source: mainline/uspace/Makefile.common@ 706b4de

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 706b4de was 7654f3e, checked in by jzr <zarevucky.jiri@…>, 8 years ago

Fix 'make clean' in individual uspace directories.

  • Property mode set to 100644
File size: 9.8 KB
Line 
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
60ROOT_PATH = $(USPACE_PREFIX)/..
61
62COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
63COMMON_HEADER = $(ROOT_PATH)/common.h
64
65CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
66CONFIG_HEADER = $(ROOT_PATH)/config.h
67
68-include $(COMMON_MAKEFILE)
69-include $(CONFIG_MAKEFILE)
70
71OUTPUTS = $(EXTRA_OUTPUT)
72
73ifneq ($(BINARY),)
74 JOB = $(BINARY).job
75 TEST_BINARY = test-$(BINARY)
76 OUTPUTS += $(BINARY) $(BINARY).disasm
77 EXTRA_CLEAN += $(BINARY).map
78endif
79
80ifneq ($(LIBRARY),)
81 JOB = $(LIBRARY).job
82 TEST_BINARY = test-$(LIBRARY)
83 OUTPUTS += $(LIBRARY).a
84endif
85
86ifeq ($(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
93endif
94
95LIB_PREFIX = $(USPACE_PREFIX)/lib
96
97LIBC_PREFIX = $(LIB_PREFIX)/c
98LIBC_INCLUDES_FLAGS = \
99 -I$(LIBC_PREFIX)/include \
100 -I$(LIBC_PREFIX)/arch/$(UARCH)/include \
101 -I$(ROOT_PATH)/abi/include
102LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
103LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
104
105LIBMATH_PREFIX = $(LIB_PREFIX)/math
106LIBMATH_INCLUDES_FLAGS = \
107 -I$(LIBMATH_PREFIX)/include \
108 -I$(LIBMATH_PREFIX)/arch/$(UARCH)/include
109
110LIBPOSIX_PREFIX = $(LIB_PREFIX)/posix
111LIBDLTEST_PREFIX = $(LIB_PREFIX)/dltest
112
113AFLAGS =
114LFLAGS = --fatal-warnings --warn-common
115
116# FIXME: This condition is a workaround for issues #692 and #693.
117ifneq ($(KARCH),ia64)
118ifneq ($(KARCH),mips32)
119 AFLAGS += --fatal-warnings
120endif
121endif
122
123ifeq ($(STATIC_NEEDED),y)
124 STATIC_BUILD = y
125else
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
135endif
136
137ifeq ($(STATIC_BUILD),y)
138 BASE_LIBS = $(LIBC_PREFIX)/libc.a
139else
140 BASE_LIBS = $(LIBC_PREFIX)/libc.so.0
141 LINK_DYNAMIC = y
142endif
143
144BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a $(LIBSOFTINT_PREFIX)/libsoftint.a
145
146ifeq ($(LINK_DYNAMIC),y)
147 LFLAGS += -Bdynamic
148 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
149else
150 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
151endif
152
153LIB_LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld
154
155INCLUDES_FLAGS = $(LIBC_INCLUDES_FLAGS)
156
157ifneq ($(LIBRARY),)
158 INCLUDES_FLAGS += -Iinclude -I.
159endif
160
161INCLUDES_FLAGS += $(foreach lib,$(LIBS), -I$(LIB_PREFIX)/$(lib) -I$(LIB_PREFIX)/$(lib)/include)
162
163# TODO: get rid of this special case
164ifneq ($(filter math, $(LIBS)),)
165 INCLUDES_FLAGS += $(LIBMATH_INCLUDES_FLAGS)
166endif
167
168# PCUT-based unit tests
169ifneq ($(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
174ifneq ($(LIBRARY),)
175 TEST_BINARY_LIBS += $(LIBRARY).a
176endif
177 TEST_BINARY_LIBS += $(TEST_LIBS)
178endif
179
180COMMON_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
185GCC_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.
192CLANG_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
197ifeq ($(CONFIG_DEBUG),y)
198 COMMON_CFLAGS += -Werror
199endif
200
201ifeq ($(CONFIG_LINE_DEBUG),y)
202 GCC_CFLAGS += -ggdb
203 CLANG_CFLAGS += -g
204endif
205
206## Setup platform configuration
207#
208
209-include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
210
211## Compilation options
212#
213
214ifeq ($(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 $@
218else
219 CC_JOB = $(CC) $< -o $@
220endif
221
222ifeq ($(COMPILER),clang)
223 CFLAGS += $(COMMON_CFLAGS) $(CLANG_CFLAGS)
224else
225 CFLAGS += $(COMMON_CFLAGS) $(GCC_CFLAGS)
226endif
227
228ifeq ($(CONFIG_STRIP_BINARIES),y)
229 LFLAGS += --strip-all
230endif
231
232LIB_CFLAGS = $(CFLAGS) -fPIC
233LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME)
234
235AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
236LD_CFLAGS := $(addprefix -Xlinker ,$(LFLAGS))
237
238OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
239LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
240TEST_OBJECTS := $(addsuffix .test.o,$(basename $(TEST_SOURCES)))
241DEPENDS := $(addsuffix .d,$(basename $(SOURCES))) $(addsuffix .test.d,$(basename $(TEST_SOURCES)))
242
243LIBTAGS := $(foreach lib,$(LIBS), $(USPACE_PREFIX)/lib/$(lib)/tag)
244LIBARGS := $(addprefix -L$(USPACE_PREFIX)/lib/, $(LIBS)) $(addprefix -l, $(LIBS))
245
246.PHONY: all all-test clean fasterclean depend
247
248all: tag $(OUTPUTS)
249
250all-test: $(TEST_OUTPUTS)
251
252clean:
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
258fasterclean:
259 rm -f $(JOB) $(OUTPUTS) $(EXTRA_CLEAN) tag deps.mk
260
261depend: $(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.
267tag:
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.
272deps.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: %
280ifeq ($(CONFIG_LINE_DEBUG),y)
281 $(OBJDUMP) -d -S $< > $@
282else
283 $(OBJDUMP) -d $< > $@
284endif
285
286ifneq ($(BINARY),)
287$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBTAGS) $(BASE_LIBS)
288 $(LD) $(LFLAGS) -T $(LINKER_SCRIPT) -Map $@.map -o $@ $(OBJECTS) $(LIBARGS) $(BASE_LIBS)
289endif
290
291ifneq ($(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)
294endif
295
296ifneq ($(LIBRARY),)
297tag: $(LIBRARY).a
298
299$(LIBRARY).a: $(OBJECTS)
300 $(AR) rc $@ $(OBJECTS)
301endif
302
303ifneq ($(SLIBRARY),)
304tag: $(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) $@
314endif
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
Note: See TracBrowser for help on using the repository browser.