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 | COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
|
---|
63 | COMMON_HEADER = $(ROOT_PATH)/common.h
|
---|
64 |
|
---|
65 | CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
|
---|
66 | CONFIG_HEADER = $(ROOT_PATH)/config.h
|
---|
67 |
|
---|
68 | -include $(COMMON_MAKEFILE)
|
---|
69 | -include $(CONFIG_MAKEFILE)
|
---|
70 |
|
---|
71 | OUTPUTS = $(EXTRA_OUTPUT)
|
---|
72 |
|
---|
73 | ifneq ($(BINARY),)
|
---|
74 | JOB = $(BINARY).job
|
---|
75 | TEST_BINARY = test-$(BINARY)
|
---|
76 | OUTPUTS += $(BINARY) $(BINARY).disasm
|
---|
77 | EXTRA_CLEAN += $(BINARY).map
|
---|
78 | endif
|
---|
79 |
|
---|
80 | ifneq ($(LIBRARY),)
|
---|
81 | JOB = $(LIBRARY).job
|
---|
82 | TEST_BINARY = test-$(LIBRARY)
|
---|
83 | OUTPUTS += $(LIBRARY).a
|
---|
84 | endif
|
---|
85 |
|
---|
86 | ifeq ($(CONFIG_BUILD_SHARED_LIBS),y)
|
---|
87 | ifneq ($(SOVERSION),)
|
---|
88 | SLIBRARY = $(LIBRARY).so.$(SOVERSION)
|
---|
89 | LSONAME = $(LIBRARY).so.$(basename $(SOVERSION))
|
---|
90 | OUTPUTS += $(SLIBRARY) $(SLIBRARY).disasm $(LSONAME)
|
---|
91 | EXTRA_CLEAN += $(LIBRARY).la $(SLIBRARY).map
|
---|
92 | endif
|
---|
93 | endif
|
---|
94 |
|
---|
95 | LIB_PREFIX = $(USPACE_PREFIX)/lib
|
---|
96 |
|
---|
97 | LIBC_PREFIX = $(LIB_PREFIX)/c
|
---|
98 | LIBC_INCLUDES_FLAGS = \
|
---|
99 | -I$(LIBC_PREFIX)/include \
|
---|
100 | -I$(LIBC_PREFIX)/arch/$(UARCH)/include \
|
---|
101 | -I$(ROOT_PATH)/abi/include
|
---|
102 | LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
|
---|
103 | LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
|
---|
104 |
|
---|
105 | LIBMATH_PREFIX = $(LIB_PREFIX)/math
|
---|
106 | LIBMATH_INCLUDES_FLAGS = \
|
---|
107 | -I$(LIBMATH_PREFIX)/include \
|
---|
108 | -I$(LIBMATH_PREFIX)/arch/$(UARCH)/include
|
---|
109 |
|
---|
110 | LIBPOSIX_PREFIX = $(LIB_PREFIX)/posix
|
---|
111 | LIBDLTEST_PREFIX = $(LIB_PREFIX)/dltest
|
---|
112 |
|
---|
113 | AFLAGS =
|
---|
114 | LFLAGS = --fatal-warnings --warn-common
|
---|
115 |
|
---|
116 | # FIXME: This condition is a workaround for issues #692 and #693.
|
---|
117 | ifneq ($(KARCH),ia64)
|
---|
118 | ifneq ($(KARCH),mips32)
|
---|
119 | AFLAGS += --fatal-warnings
|
---|
120 | endif
|
---|
121 | endif
|
---|
122 |
|
---|
123 | ifeq ($(STATIC_NEEDED),y)
|
---|
124 | STATIC_BUILD = y
|
---|
125 | else
|
---|
126 | ifeq ($(STATIC_ONLY),y)
|
---|
127 | STATIC_BUILD = y
|
---|
128 | else
|
---|
129 | ifeq ($(CONFIG_USE_SHARED_LIBS),y)
|
---|
130 | STATIC_BUILD = n
|
---|
131 | else
|
---|
132 | STATIC_BUILD = y
|
---|
133 | endif
|
---|
134 | endif
|
---|
135 | endif
|
---|
136 |
|
---|
137 | ifeq ($(STATIC_BUILD),y)
|
---|
138 | BASE_LIBS = $(LIBC_PREFIX)/libc.a
|
---|
139 | else
|
---|
140 | BASE_LIBS = $(LIBC_PREFIX)/libc.so.0
|
---|
141 | LINK_DYNAMIC = y
|
---|
142 | endif
|
---|
143 |
|
---|
144 | BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a $(LIBSOFTINT_PREFIX)/libsoftint.a
|
---|
145 |
|
---|
146 | ifeq ($(LINK_DYNAMIC),y)
|
---|
147 | LFLAGS += -Bdynamic
|
---|
148 | LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
|
---|
149 | else
|
---|
150 | LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
|
---|
151 | endif
|
---|
152 |
|
---|
153 | LIB_LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld
|
---|
154 |
|
---|
155 | INCLUDES_FLAGS = $(LIBC_INCLUDES_FLAGS)
|
---|
156 |
|
---|
157 | ifneq ($(LIBRARY),)
|
---|
158 | INCLUDES_FLAGS += -Iinclude -I.
|
---|
159 | endif
|
---|
160 |
|
---|
161 | INCLUDES_FLAGS += $(foreach lib,$(LIBS), -I$(LIB_PREFIX)/$(lib) -I$(LIB_PREFIX)/$(lib)/include)
|
---|
162 |
|
---|
163 | # TODO: get rid of this special case
|
---|
164 | ifneq ($(filter math, $(LIBS)),)
|
---|
165 | INCLUDES_FLAGS += $(LIBMATH_INCLUDES_FLAGS)
|
---|
166 | endif
|
---|
167 |
|
---|
168 | # PCUT-based unit tests
|
---|
169 | ifneq ($(TEST_SOURCES),)
|
---|
170 | TEST_OUTPUTS = $(TEST_BINARY) $(TEST_BINARY).disasm
|
---|
171 | TEST_CFLAGS = -I$(LIB_PREFIX)/pcut/include -D__helenos__
|
---|
172 | TEST_BINARY_LIBS = $(LIB_PREFIX)/pcut/libpcut.a
|
---|
173 | EXTRA_CLEAN += $(TEST_OUTPUTS) $(TEST_BINARY).map
|
---|
174 | ifneq ($(LIBRARY),)
|
---|
175 | TEST_BINARY_LIBS += $(LIBRARY).a
|
---|
176 | endif
|
---|
177 | TEST_BINARY_LIBS += $(TEST_LIBS)
|
---|
178 | endif
|
---|
179 |
|
---|
180 | COMMON_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
|
---|
181 | -ffreestanding -fno-builtin -nostdlib -nostdinc -fexec-charset=UTF-8 \
|
---|
182 | -finput-charset=UTF-8 -D__$(ENDIANESS)__ -fno-common \
|
---|
183 | -fdebug-prefix-map=$(realpath $(ROOT_PATH))=.
|
---|
184 |
|
---|
185 | GCC_CFLAGS = -ffunction-sections -Wall -Wextra -Wno-clobbered \
|
---|
186 | -Wno-unused-parameter -Wmissing-prototypes -std=gnu99 \
|
---|
187 | -Werror-implicit-function-declaration \
|
---|
188 | -Wwrite-strings -pipe
|
---|
189 |
|
---|
190 | # -Wno-missing-prototypes is there because it warns about main().
|
---|
191 | # This should be fixed elsewhere.
|
---|
192 | CLANG_CFLAGS = -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-typedef-redefinition \
|
---|
193 | -Wno-missing-prototypes -Wno-unused-command-line-argument \
|
---|
194 | -std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings \
|
---|
195 | -pipe -fno-stack-protector -fno-PIC
|
---|
196 |
|
---|
197 | ifeq ($(CONFIG_DEBUG),y)
|
---|
198 | COMMON_CFLAGS += -Werror
|
---|
199 | endif
|
---|
200 |
|
---|
201 | ifeq ($(CONFIG_LINE_DEBUG),y)
|
---|
202 | GCC_CFLAGS += -ggdb
|
---|
203 | CLANG_CFLAGS += -g
|
---|
204 | endif
|
---|
205 |
|
---|
206 | ## Setup platform configuration
|
---|
207 | #
|
---|
208 |
|
---|
209 | -include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
|
---|
210 |
|
---|
211 | ## Compilation options
|
---|
212 | #
|
---|
213 |
|
---|
214 | ifeq ($(PRECHECK),y)
|
---|
215 | JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py
|
---|
216 | # XXX: Do not change the order of arguments.
|
---|
217 | CC_JOB = $(JOBFILE) $(JOB) $(CC) $< -o $@
|
---|
218 | else
|
---|
219 | CC_JOB = $(CC) $< -o $@
|
---|
220 | endif
|
---|
221 |
|
---|
222 | ifeq ($(COMPILER),clang)
|
---|
223 | CFLAGS += $(COMMON_CFLAGS) $(CLANG_CFLAGS)
|
---|
224 | else
|
---|
225 | CFLAGS += $(COMMON_CFLAGS) $(GCC_CFLAGS)
|
---|
226 | endif
|
---|
227 |
|
---|
228 | ifeq ($(CONFIG_STRIP_BINARIES),y)
|
---|
229 | LFLAGS += --strip-all
|
---|
230 | endif
|
---|
231 |
|
---|
232 | LIB_CFLAGS = $(CFLAGS) -fPIC
|
---|
233 | LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME)
|
---|
234 |
|
---|
235 | AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
|
---|
236 | LD_CFLAGS := $(addprefix -Xlinker ,$(LFLAGS))
|
---|
237 |
|
---|
238 | OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
|
---|
239 | LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
|
---|
240 | TEST_OBJECTS := $(addsuffix .test.o,$(basename $(TEST_SOURCES)))
|
---|
241 | DEPENDS := $(addsuffix .d,$(basename $(SOURCES))) $(addsuffix .test.d,$(basename $(TEST_SOURCES)))
|
---|
242 |
|
---|
243 | LIBTAGS := $(foreach lib,$(LIBS), $(USPACE_PREFIX)/lib/$(lib)/tag)
|
---|
244 | LIBARGS := $(addprefix -L$(USPACE_PREFIX)/lib/, $(LIBS)) $(addprefix -l, $(LIBS))
|
---|
245 |
|
---|
246 | .PHONY: all all-test clean fasterclean depend
|
---|
247 |
|
---|
248 | all: tag $(OUTPUTS)
|
---|
249 |
|
---|
250 | all-test: $(TEST_OUTPUTS)
|
---|
251 |
|
---|
252 | clean:
|
---|
253 | rm -f $(JOB) $(OUTPUTS) $(EXTRA_CLEAN) tag deps.mk
|
---|
254 | find . -name '*.o' -follow -exec rm \{\} \;
|
---|
255 | find . -name '*.lo' -follow -exec rm \{\} \;
|
---|
256 | find . -name '*.d' -follow -exec rm \{\} \;
|
---|
257 |
|
---|
258 | fasterclean:
|
---|
259 | rm -f $(JOB) $(OUTPUTS) $(EXTRA_CLEAN) tag deps.mk
|
---|
260 |
|
---|
261 | depend: $(PRE_DEPEND)
|
---|
262 |
|
---|
263 | # "Tag" files are used to force relink of binaries when dependencies get rebuilt,
|
---|
264 | # regardless of whether the dependency was linked statically or dynamically,
|
---|
265 | # or which version of a dynamic library was used. Prerequisites for this file
|
---|
266 | # are defined further down.
|
---|
267 | tag:
|
---|
268 | touch tag
|
---|
269 |
|
---|
270 | # Generate inter-module make dependencies.
|
---|
271 | # This is needed to ensure correct build order of libraries and code depending on them.
|
---|
272 | deps.mk: Makefile
|
---|
273 | echo > $@.new
|
---|
274 | for lib in $(LIBS); do \
|
---|
275 | echo "$(SELF_TARGET): lib/$$lib.build" >> $@.new; \
|
---|
276 | done
|
---|
277 | mv -f $@.new $@
|
---|
278 |
|
---|
279 | %.disasm: %
|
---|
280 | ifeq ($(CONFIG_LINE_DEBUG),y)
|
---|
281 | $(OBJDUMP) -d -S $< > $@
|
---|
282 | else
|
---|
283 | $(OBJDUMP) -d $< > $@
|
---|
284 | endif
|
---|
285 |
|
---|
286 | ifneq ($(BINARY),)
|
---|
287 | $(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBTAGS) $(BASE_LIBS)
|
---|
288 | $(LD) $(LFLAGS) -T $(LINKER_SCRIPT) -Map $@.map -o $@ $(OBJECTS) $(LIBARGS) $(BASE_LIBS)
|
---|
289 | endif
|
---|
290 |
|
---|
291 | ifneq ($(TEST_BINARY),)
|
---|
292 | $(TEST_BINARY): $(LINKER_SCRIPT) $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBTAGS) $(BASE_LIBS)
|
---|
293 | $(LD) $(LFLAGS) -T $(LINKER_SCRIPT) -Map $@.map -o $@ $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBARGS) $(BASE_LIBS)
|
---|
294 | endif
|
---|
295 |
|
---|
296 | ifneq ($(LIBRARY),)
|
---|
297 | tag: $(LIBRARY).a
|
---|
298 |
|
---|
299 | $(LIBRARY).a: $(OBJECTS)
|
---|
300 | $(AR) rc $@ $(OBJECTS)
|
---|
301 | endif
|
---|
302 |
|
---|
303 | ifneq ($(SLIBRARY),)
|
---|
304 | tag: $(SLIBRARY)
|
---|
305 |
|
---|
306 | $(LIBRARY).la: $(LOBJECTS)
|
---|
307 | $(AR) rc $@ $(LOBJECTS)
|
---|
308 |
|
---|
309 | $(SLIBRARY): $(LIB_LINKER_SCRIPT) $(LIBRARY).la
|
---|
310 | $(LD) $(LIB_LFLAGS) -T $(LIB_LINKER_SCRIPT) -Map $@.map -o $@ --whole-archive $(LIBRARY).la --no-whole-archive
|
---|
311 |
|
---|
312 | $(LSONAME):
|
---|
313 | ln -s $(SLIBRARY) $@
|
---|
314 | endif
|
---|
315 |
|
---|
316 | %.o: %.S | depend
|
---|
317 | $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
|
---|
318 |
|
---|
319 | %.o: %.s | depend
|
---|
320 | $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
|
---|
321 |
|
---|
322 | %.o: %.c | depend
|
---|
323 | $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS)
|
---|
324 |
|
---|
325 | %.test.o: %.c | depend
|
---|
326 | $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(TEST_CFLAGS)
|
---|
327 |
|
---|
328 | %.lo: %.S | depend
|
---|
329 | $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
|
---|
330 |
|
---|
331 | %.lo: %.s | depend
|
---|
332 | $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
|
---|
333 |
|
---|
334 | %.lo: %.c | depend
|
---|
335 | $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS)
|
---|
336 |
|
---|
337 | -include $(DEPENDS)
|
---|
338 |
|
---|