Bump IPC_MAX_ASYNC_CALLS
[helenos.git] / uspace / Makefile.common
blobcb9177fdf7629b4f899a99954d8d435ad1cd7c86
2 # Copyright (c) 2005 Martin Decky
3 # Copyright (c) 2007 Jakub Jermar
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
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.
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.
30 # Individual makefiles set:
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
40 #   BINARY         (/) binary output name (like appname)
41 #   LIBRARY        (/) library output name (like libname)
43 #   EXTRA_OUTPUT       additional output targets
44 #   EXTRA_CLEAN        additional cleanup targets
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)
52 # Optionally, for a library:
53 #   SOVERSION            shared library version (major.minor),
54 #                        if missing, no shared library is built
56 # (x) required variables
57 # (/) exactly one of the variables must be defined
60 ROOT_PATH = $(USPACE_PREFIX)/..
62 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
63 COMMON_HEADER = $(ROOT_PATH)/common.h
65 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
66 CONFIG_HEADER = $(ROOT_PATH)/config.h
68 -include $(COMMON_MAKEFILE)
69 -include $(CONFIG_MAKEFILE)
71 OUTPUTS = $(EXTRA_OUTPUT)
73 ifneq ($(BINARY),)
74         JOB = $(BINARY).job
75         TEST_BINARY = test-$(BINARY)
76         OUTPUTS += $(BINARY) $(BINARY).disasm
77         EXTRA_CLEAN += $(BINARY).map
78 endif
80 ifneq ($(LIBRARY),)
81         JOB = $(LIBRARY).job
82         TEST_BINARY = test-$(LIBRARY)
83         OUTPUTS += $(LIBRARY).a
84 endif
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
95 LIB_PREFIX = $(USPACE_PREFIX)/lib
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
105 LIBMATH_PREFIX = $(LIB_PREFIX)/math
106 LIBMATH_INCLUDES_FLAGS = \
107         -I$(LIBMATH_PREFIX)/include \
108         -I$(LIBMATH_PREFIX)/arch/$(UARCH)/include
110 LIBPOSIX_PREFIX = $(LIB_PREFIX)/posix
111 LIBDLTEST_PREFIX = $(LIB_PREFIX)/dltest
113 AFLAGS =
114 LFLAGS = --fatal-warnings --warn-common
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
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
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
144 BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a $(LIBSOFTINT_PREFIX)/libsoftint.a
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
153 LIB_LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld
155 INCLUDES_FLAGS = $(LIBC_INCLUDES_FLAGS)
157 ifneq ($(LIBRARY),)
158         INCLUDES_FLAGS += -Iinclude -I.
159 endif
161 INCLUDES_FLAGS += $(foreach lib,$(LIBS), -I$(LIB_PREFIX)/$(lib) -I$(LIB_PREFIX)/$(lib)/include)
163 # TODO: get rid of this special case
164 ifneq ($(filter math, $(LIBS)),)
165         INCLUDES_FLAGS += $(LIBMATH_INCLUDES_FLAGS)
166 endif
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
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))=.
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
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
197 ifeq ($(CONFIG_DEBUG),y)
198         COMMON_CFLAGS += -Werror
199 endif
201 ifeq ($(CONFIG_LINE_DEBUG),y)
202         GCC_CFLAGS += -ggdb
203         CLANG_CFLAGS += -g
204 endif
206 ## Setup platform configuration
209 -include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
211 ## Compilation options
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
222 ifeq ($(COMPILER),clang)
223         CFLAGS += $(COMMON_CFLAGS) $(CLANG_CFLAGS)
224 else
225         CFLAGS += $(COMMON_CFLAGS) $(GCC_CFLAGS)
226 endif
228 ifeq ($(CONFIG_STRIP_BINARIES),y)
229         LFLAGS += --strip-all
230 endif
232 LIB_CFLAGS = $(CFLAGS) -fPIC
233 LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME)
235 AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
236 LD_CFLAGS := $(addprefix -Xlinker ,$(LFLAGS))
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)))
243 LIBTAGS := $(foreach lib,$(LIBS), $(USPACE_PREFIX)/lib/$(lib)/tag)
244 LIBARGS := $(addprefix -L$(USPACE_PREFIX)/lib/, $(LIBS)) $(addprefix -l, $(LIBS))
246 -include $(DEPENDS)
248 .PHONY: all all-test clean depend
250 all: tag $(OUTPUTS)
252 all-test: $(TEST_OUTPUTS)
254 clean:
255         rm -f $(JOB) $(OUTPUTS) $(EXTRA_CLEAN)
257 depend: $(PRE_DEPEND)
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
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 $@
275 %.disasm: %
276 ifeq ($(CONFIG_LINE_DEBUG),y)
277         $(OBJDUMP) -d -S $< > $@
278 else
279         $(OBJDUMP) -d $< > $@
280 endif
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
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
292 ifneq ($(LIBRARY),)
293 tag: $(LIBRARY).a
295 $(LIBRARY).a: $(OBJECTS)
296         $(AR) rc $@ $(OBJECTS)
297 endif
299 ifneq ($(SLIBRARY),)
300 tag: $(SLIBRARY)
302 $(LIBRARY).la: $(LOBJECTS)
303         $(AR) rc $@ $(LOBJECTS)
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
308 $(LSONAME):
309         ln -s $(SLIBRARY) $@
310 endif
312 %.o: %.S | depend
313         $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
315 %.o: %.s | depend
316         $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
318 %.o: %.c | depend
319         $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS)
321 %.test.o: %.c | depend
322         $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(TEST_CFLAGS)
324 %.lo: %.S | depend
325         $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
327 %.lo: %.s | depend
328         $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
330 %.lo: %.c | depend
331         $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS)