1 | #
|
---|
2 | # Copyright (c) 2005 Martin Decky
|
---|
3 | # Copyright (c) 2007 Jakub Jermar
|
---|
4 | # All rights reserved.
|
---|
5 | #
|
---|
6 | # Redistribution and use in source and binary forms, with or without
|
---|
7 | # modification, are permitted provided that the following conditions
|
---|
8 | # are met:
|
---|
9 | #
|
---|
10 | # - Redistributions of source code must retain the above copyright
|
---|
11 | # notice, this list of conditions and the following disclaimer.
|
---|
12 | # - Redistributions in binary form must reproduce the above copyright
|
---|
13 | # notice, this list of conditions and the following disclaimer in the
|
---|
14 | # documentation and/or other materials provided with the distribution.
|
---|
15 | # - The name of the author may not be used to endorse or promote products
|
---|
16 | # derived from this software without specific prior written permission.
|
---|
17 | #
|
---|
18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | #
|
---|
29 |
|
---|
30 | # Individual makefiles set:
|
---|
31 | #
|
---|
32 | # USPACE_PREFIX (*) relative path to uspace/ directory
|
---|
33 | # SOURCES (*) list of source files
|
---|
34 | # LIBS libraries to link with
|
---|
35 | # DEFS compiler defines
|
---|
36 | # EXTRA_CFLAGS additional flags to pass to C compiler
|
---|
37 | # LINKER_SCRIPT linker script
|
---|
38 | # PRE_DEPEND targets required for dependency check
|
---|
39 | #
|
---|
40 | # BINARY (/) binary output name (like appname)
|
---|
41 | # LIBRARY (/) library output name (like libname)
|
---|
42 | #
|
---|
43 | # EXTRA_OUTPUT additional output targets
|
---|
44 | # EXTRA_CLEAN additional cleanup targets
|
---|
45 | #
|
---|
46 | # Optionally, for a binary:
|
---|
47 | # STATIC_NEEDED set to 'y' for init binaries, will build statically
|
---|
48 | # linked version
|
---|
49 | # STATIC_ONLY set to 'y' if binary cannot be linked dynamically
|
---|
50 | # (e.g. uses thread-local variables)
|
---|
51 | #
|
---|
52 | # Optionally, for a library:
|
---|
53 | # SOVERSION shared library version (major.minor),
|
---|
54 | # if missing, no shared library is built
|
---|
55 | #
|
---|
56 | # (x) required variables
|
---|
57 | # (/) exactly one of the variables must be defined
|
---|
58 | #
|
---|
59 |
|
---|
60 | ROOT_PATH = $(USPACE_PREFIX)/..
|
---|
61 |
|
---|
62 | VERSION_DEF = $(ROOT_PATH)/version
|
---|
63 |
|
---|
64 | COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
|
---|
65 | COMMON_HEADER = $(ROOT_PATH)/common.h
|
---|
66 |
|
---|
67 | CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
|
---|
68 | CONFIG_HEADER = $(ROOT_PATH)/config.h
|
---|
69 |
|
---|
70 | -include $(VERSION_DEF)
|
---|
71 | -include $(COMMON_MAKEFILE)
|
---|
72 | -include $(CONFIG_MAKEFILE)
|
---|
73 |
|
---|
74 | OUTPUTS = $(EXTRA_OUTPUT)
|
---|
75 |
|
---|
76 | ifneq ($(BINARY),)
|
---|
77 | JOB = $(BINARY).job
|
---|
78 | TEST_BINARY = test-$(BINARY)
|
---|
79 | OUTPUTS += $(BINARY) $(BINARY).disasm
|
---|
80 | EXTRA_CLEAN += $(BINARY).map
|
---|
81 | endif
|
---|
82 |
|
---|
83 | ifneq ($(LIBRARY),)
|
---|
84 | JOB = $(LIBRARY).job
|
---|
85 | TEST_BINARY = test-$(LIBRARY)
|
---|
86 | OUTPUTS += $(LIBRARY).a
|
---|
87 | endif
|
---|
88 |
|
---|
89 | ifeq ($(CONFIG_BUILD_SHARED_LIBS),y)
|
---|
90 | ifneq ($(SOVERSION),)
|
---|
91 | SLIBRARY = $(LIBRARY).so.$(SOVERSION)
|
---|
92 | LSONAME = $(LIBRARY).so.$(basename $(SOVERSION))
|
---|
93 | OUTPUTS += $(SLIBRARY) $(SLIBRARY).disasm $(LSONAME)
|
---|
94 | EXTRA_CLEAN += $(LIBRARY).la $(SLIBRARY).map
|
---|
95 | endif
|
---|
96 | endif
|
---|
97 |
|
---|
98 | LIB_PREFIX = $(USPACE_PREFIX)/lib
|
---|
99 |
|
---|
100 | LIBC_PREFIX = $(LIB_PREFIX)/c
|
---|
101 | LIBC_INCLUDES_FLAGS = \
|
---|
102 | -I$(LIBC_PREFIX)/include \
|
---|
103 | -I$(LIBC_PREFIX)/arch/$(UARCH)/include \
|
---|
104 | -I$(ROOT_PATH)/abi/include
|
---|
105 | LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
|
---|
106 | LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
|
---|
107 |
|
---|
108 | LIBMATH_PREFIX = $(LIB_PREFIX)/math
|
---|
109 | LIBMATH_INCLUDES_FLAGS = \
|
---|
110 | -I$(LIBMATH_PREFIX)/include \
|
---|
111 | -I$(LIBMATH_PREFIX)/arch/$(UARCH)/include
|
---|
112 |
|
---|
113 | LIBPOSIX_PREFIX = $(LIB_PREFIX)/posix
|
---|
114 | LIBDLTEST_PREFIX = $(LIB_PREFIX)/dltest
|
---|
115 |
|
---|
116 | AFLAGS = --fatal-warnings
|
---|
117 | LFLAGS = --fatal-warnings --warn-common
|
---|
118 |
|
---|
119 | ifeq ($(STATIC_NEEDED),y)
|
---|
120 | STATIC_BUILD = y
|
---|
121 | else
|
---|
122 | ifeq ($(STATIC_ONLY),y)
|
---|
123 | STATIC_BUILD = y
|
---|
124 | else
|
---|
125 | ifeq ($(CONFIG_USE_SHARED_LIBS),y)
|
---|
126 | STATIC_BUILD = n
|
---|
127 | else
|
---|
128 | STATIC_BUILD = y
|
---|
129 | endif
|
---|
130 | endif
|
---|
131 | endif
|
---|
132 |
|
---|
133 | ifeq ($(STATIC_BUILD),y)
|
---|
134 | BASE_LIBS = $(LIBC_PREFIX)/libc.a
|
---|
135 | else
|
---|
136 | BASE_LIBS = $(LIBC_PREFIX)/libc.so.0
|
---|
137 | LINK_DYNAMIC = y
|
---|
138 | endif
|
---|
139 |
|
---|
140 | BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a $(LIBSOFTINT_PREFIX)/libsoftint.a
|
---|
141 |
|
---|
142 | ifeq ($(LINK_DYNAMIC),y)
|
---|
143 | LFLAGS += -Bdynamic
|
---|
144 | LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
|
---|
145 | else
|
---|
146 | LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
|
---|
147 | endif
|
---|
148 |
|
---|
149 | LIB_LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld
|
---|
150 |
|
---|
151 | INCLUDES_FLAGS = $(LIBC_INCLUDES_FLAGS)
|
---|
152 |
|
---|
153 | ifneq ($(LIBRARY),)
|
---|
154 | INCLUDES_FLAGS += -Iinclude -I.
|
---|
155 | endif
|
---|
156 |
|
---|
157 | INCLUDES_FLAGS += $(foreach lib,$(LIBS), -I$(LIB_PREFIX)/$(lib) -I$(LIB_PREFIX)/$(lib)/include)
|
---|
158 |
|
---|
159 | # TODO: get rid of this special case
|
---|
160 | ifneq ($(filter math, $(LIBS)),)
|
---|
161 | INCLUDES_FLAGS += $(LIBMATH_INCLUDES_FLAGS)
|
---|
162 | endif
|
---|
163 |
|
---|
164 | # PCUT-based unit tests
|
---|
165 | ifneq ($(TEST_SOURCES),)
|
---|
166 | TEST_OUTPUTS = $(TEST_BINARY) $(TEST_BINARY).disasm
|
---|
167 | TEST_CFLAGS = -I$(LIB_PREFIX)/pcut/include -D__helenos__
|
---|
168 | TEST_BINARY_LIBS = $(LIB_PREFIX)/pcut/libpcut.a
|
---|
169 | EXTRA_CLEAN += $(TEST_OUTPUTS) $(TEST_BINARY).map
|
---|
170 | ifneq ($(LIBRARY),)
|
---|
171 | TEST_BINARY_LIBS += $(LIBRARY).a
|
---|
172 | endif
|
---|
173 | TEST_BINARY_LIBS += $(TEST_LIBS)
|
---|
174 | endif
|
---|
175 |
|
---|
176 | COMMON_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
|
---|
177 | -ffreestanding -fno-builtin -nostdlib -nostdinc -fexec-charset=UTF-8 \
|
---|
178 | -finput-charset=UTF-8 -D__$(ENDIANESS)__ -fno-common \
|
---|
179 | -fdebug-prefix-map=$(realpath $(ROOT_PATH))=.
|
---|
180 |
|
---|
181 | GCC_CFLAGS = -ffunction-sections -Wall -Wextra -Wno-clobbered \
|
---|
182 | -Wno-unused-parameter -Wmissing-prototypes -std=gnu99 \
|
---|
183 | -Werror-implicit-function-declaration \
|
---|
184 | -Wwrite-strings -pipe
|
---|
185 |
|
---|
186 | # -Wno-missing-prototypes is there because it warns about main().
|
---|
187 | # This should be fixed elsewhere.
|
---|
188 | CLANG_CFLAGS = -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-typedef-redefinition \
|
---|
189 | -Wno-missing-prototypes -Wno-unused-command-line-argument \
|
---|
190 | -std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings \
|
---|
191 | -pipe -fno-stack-protector -fno-PIC
|
---|
192 |
|
---|
193 | ifeq ($(CONFIG_DEBUG),y)
|
---|
194 | COMMON_CFLAGS += -Werror
|
---|
195 | endif
|
---|
196 |
|
---|
197 | ifeq ($(CONFIG_LINE_DEBUG),y)
|
---|
198 | GCC_CFLAGS += -ggdb
|
---|
199 | CLANG_CFLAGS += -g
|
---|
200 | endif
|
---|
201 |
|
---|
202 | ## Setup platform configuration
|
---|
203 | #
|
---|
204 |
|
---|
205 | -include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
|
---|
206 |
|
---|
207 | ## Compilation options
|
---|
208 | #
|
---|
209 |
|
---|
210 | ifeq ($(PRECHECK),y)
|
---|
211 | JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py
|
---|
212 | # XXX: Do not change the order of arguments.
|
---|
213 | CC_JOB = $(JOBFILE) $(JOB) $(CC) $< -o $@
|
---|
214 | else
|
---|
215 | CC_JOB = $(CC) $< -o $@
|
---|
216 | endif
|
---|
217 |
|
---|
218 | ifeq ($(COMPILER),clang)
|
---|
219 | CFLAGS += $(COMMON_CFLAGS) $(CLANG_CFLAGS)
|
---|
220 | else
|
---|
221 | CFLAGS += $(COMMON_CFLAGS) $(GCC_CFLAGS)
|
---|
222 | endif
|
---|
223 |
|
---|
224 | ifeq ($(CONFIG_STRIP_BINARIES),y)
|
---|
225 | LFLAGS += --strip-all
|
---|
226 | endif
|
---|
227 |
|
---|
228 | LIB_CFLAGS = $(CFLAGS) -fPIC
|
---|
229 | LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME)
|
---|
230 |
|
---|
231 | AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
|
---|
232 | LD_CFLAGS := $(addprefix -Xlinker ,$(LFLAGS))
|
---|
233 |
|
---|
234 | OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
|
---|
235 | LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
|
---|
236 | TEST_OBJECTS := $(addsuffix .test.o,$(basename $(TEST_SOURCES)))
|
---|
237 | DEPENDS := $(addsuffix .d,$(basename $(SOURCES))) $(addsuffix .test.d,$(basename $(TEST_SOURCES)))
|
---|
238 |
|
---|
239 | LIBTAGS := $(foreach lib,$(LIBS), $(USPACE_PREFIX)/lib/$(lib)/tag)
|
---|
240 | LIBARGS := $(addprefix -L$(USPACE_PREFIX)/lib/, $(LIBS)) $(addprefix -l, $(LIBS))
|
---|
241 |
|
---|
242 | .PHONY: all all-test clean fasterclean depend
|
---|
243 |
|
---|
244 | all: tag $(OUTPUTS)
|
---|
245 |
|
---|
246 | all-test: $(TEST_OUTPUTS)
|
---|
247 |
|
---|
248 | clean:
|
---|
249 | rm -f $(JOB) $(OUTPUTS) $(EXTRA_CLEAN) tag deps.mk
|
---|
250 | find . -name '*.o' -follow -exec rm \{\} \;
|
---|
251 | find . -name '*.lo' -follow -exec rm \{\} \;
|
---|
252 | find . -name '*.d' -follow -exec rm \{\} \;
|
---|
253 |
|
---|
254 | fasterclean:
|
---|
255 | rm -f $(JOB) $(OUTPUTS) $(EXTRA_CLEAN) tag deps.mk
|
---|
256 |
|
---|
257 | depend: $(PRE_DEPEND)
|
---|
258 |
|
---|
259 | # "Tag" files are used to force relink of binaries when dependencies get rebuilt,
|
---|
260 | # regardless of whether the dependency was linked statically or dynamically,
|
---|
261 | # or which version of a dynamic library was used. Prerequisites for this file
|
---|
262 | # are defined further down.
|
---|
263 | tag:
|
---|
264 | touch tag
|
---|
265 |
|
---|
266 | # Generate inter-module make dependencies.
|
---|
267 | # This is needed to ensure correct build order of libraries and code depending on them.
|
---|
268 | deps.mk: Makefile
|
---|
269 | echo > $@.new
|
---|
270 | for lib in $(LIBS); do \
|
---|
271 | echo "$(SELF_TARGET): lib/$$lib.build" >> $@.new; \
|
---|
272 | done
|
---|
273 | mv -f $@.new $@
|
---|
274 |
|
---|
275 | %.disasm: %
|
---|
276 | ifeq ($(CONFIG_LINE_DEBUG),y)
|
---|
277 | $(OBJDUMP) -d -S $< > $@
|
---|
278 | else
|
---|
279 | $(OBJDUMP) -d $< > $@
|
---|
280 | endif
|
---|
281 |
|
---|
282 | ifneq ($(BINARY),)
|
---|
283 | $(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBTAGS) $(BASE_LIBS)
|
---|
284 | $(LD) $(LFLAGS) -T $(LINKER_SCRIPT) -Map $@.map -o $@ $(OBJECTS) $(LIBARGS) $(BASE_LIBS)
|
---|
285 | endif
|
---|
286 |
|
---|
287 | ifneq ($(TEST_BINARY),)
|
---|
288 | $(TEST_BINARY): $(LINKER_SCRIPT) $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBTAGS) $(BASE_LIBS)
|
---|
289 | $(LD) $(LFLAGS) -T $(LINKER_SCRIPT) -Map $@.map -o $@ $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBARGS) $(BASE_LIBS)
|
---|
290 | endif
|
---|
291 |
|
---|
292 | ifneq ($(LIBRARY),)
|
---|
293 | tag: $(LIBRARY).a
|
---|
294 |
|
---|
295 | $(LIBRARY).a: $(OBJECTS)
|
---|
296 | $(AR) rc $@ $(OBJECTS)
|
---|
297 | endif
|
---|
298 |
|
---|
299 | ifneq ($(SLIBRARY),)
|
---|
300 | tag: $(SLIBRARY)
|
---|
301 |
|
---|
302 | $(LIBRARY).la: $(LOBJECTS)
|
---|
303 | $(AR) rc $@ $(LOBJECTS)
|
---|
304 |
|
---|
305 | $(SLIBRARY): $(LIB_LINKER_SCRIPT) $(LIBRARY).la
|
---|
306 | $(LD) $(LIB_LFLAGS) -T $(LIB_LINKER_SCRIPT) -Map $@.map -o $@ --whole-archive $(LIBRARY).la --no-whole-archive
|
---|
307 |
|
---|
308 | $(LSONAME):
|
---|
309 | ln -s $(SLIBRARY) $@
|
---|
310 | endif
|
---|
311 |
|
---|
312 | %.o: %.S | depend
|
---|
313 | $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
|
---|
314 |
|
---|
315 | %.o: %.s | depend
|
---|
316 | $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
|
---|
317 |
|
---|
318 | %.o: %.c | depend
|
---|
319 | $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS)
|
---|
320 |
|
---|
321 | %.test.o: %.c | depend
|
---|
322 | $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(TEST_CFLAGS)
|
---|
323 |
|
---|
324 | %.lo: %.S | depend
|
---|
325 | $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
|
---|
326 |
|
---|
327 | %.lo: %.s | depend
|
---|
328 | $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
|
---|
329 |
|
---|
330 | %.lo: %.c | depend
|
---|
331 | $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS)
|
---|
332 |
|
---|
333 | -include $(DEPENDS)
|
---|
334 |
|
---|