source: mainline/uspace/Makefile.common@ 9b8be79

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9b8be79 was 7570a95f, checked in by Jiří Zárevúcky <jiri.zarevucky@…>, 7 years ago

Pass system include dirs via -isystem, for correct ordering

We need those directories to be considered after any -I specified by
the user, otherwise ordering is a problem.

By default, GCC doesn't produce warnings for system headers.
We want those warnings anyway, so we enable them specifically.

  • Property mode set to 100644
File size: 11.2 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# PRE_DEPEND targets required for dependency check
38#
39# BINARY (/) binary output name (like appname)
40# LIBRARY (/) library output name (like libname)
41#
42# EXTRA_OUTPUT additional output targets
43# EXTRA_CLEAN additional cleanup targets
44#
45# Optionally, for a binary:
46# STATIC_NEEDED set to 'y' for init binaries, will build statically
47# linked version
48# STATIC_ONLY set to 'y' if binary cannot be linked dynamically
49# (e.g. uses thread-local variables)
50#
51# Optionally, for a library:
52# SOVERSION shared library version (major.minor),
53# if missing, no shared library is built
54#
55# (x) required variables
56# (/) exactly one of the variables must be defined
57#
58
59ROOT_PATH = $(USPACE_PREFIX)/..
60
61VERSION_DEF = $(ROOT_PATH)/version
62
63COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
64COMMON_HEADER = $(ROOT_PATH)/common.h
65
66CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
67CONFIG_HEADER = $(ROOT_PATH)/config.h
68
69-include $(VERSION_DEF)
70-include $(COMMON_MAKEFILE)
71-include $(CONFIG_MAKEFILE)
72
73OUTPUTS = $(EXTRA_OUTPUT)
74
75ifneq ($(BINARY),)
76 JOB = $(BINARY).job
77 TEST_BINARY = test-$(BINARY)
78 OUTPUTS += $(BINARY) $(BINARY).disasm
79 EXTRA_CLEAN += $(BINARY).map
80endif
81
82ifneq ($(LIBRARY),)
83 JOB = $(LIBRARY).job
84 TEST_BINARY = test-$(LIBRARY)
85 OUTPUTS += $(LIBRARY).a
86endif
87
88ifeq ($(CONFIG_BUILD_SHARED_LIBS),y)
89 ifneq ($(SOVERSION),)
90 SLIBRARY = $(LIBRARY).so.$(SOVERSION)
91 LSONAME = $(LIBRARY).so.$(basename $(SOVERSION))
92 OUTPUTS += $(SLIBRARY) $(SLIBRARY).disasm $(LSONAME)
93 EXTRA_CLEAN += $(LIBRARY).la $(SLIBRARY).map
94 endif
95endif
96
97LIB_PREFIX = $(USPACE_PREFIX)/lib
98
99LIBC_PREFIX = $(LIB_PREFIX)/c
100LIBC_INCLUDES_FLAGS = \
101 -isystem $(LIBC_PREFIX)/include \
102 -isystem $(LIBC_PREFIX)/arch/$(UARCH)/include \
103 -isystem $(ROOT_PATH)/abi/include
104
105LIBCPP_PREFIX = $(LIB_PREFIX)/cpp
106LIBCPP_INCLUDES_FLAGS = -isystem $(LIBCPP_PREFIX)/include
107
108LIBDLTEST_PREFIX = $(LIB_PREFIX)/dltest
109
110START_FILES = $(LIBC_PREFIX)/crt0.o $(LIBC_PREFIX)/crt1.o
111
112AFLAGS = --fatal-warnings
113LDFLAGS = -Wl,--fatal-warnings,--warn-common
114
115ifeq ($(STATIC_NEEDED),y)
116 STATIC_BUILD = y
117else
118 ifeq ($(STATIC_ONLY),y)
119 STATIC_BUILD = y
120 else
121 ifeq ($(CONFIG_USE_SHARED_LIBS),y)
122 STATIC_BUILD = n
123 else
124 STATIC_BUILD = y
125 endif
126 endif
127endif
128
129ifneq ($(STATIC_BUILD),y)
130 LINK_DYNAMIC = y
131endif
132
133BASE_LIBS =
134
135ifneq ($(LIBRARY),libc)
136 ifeq ($(STATIC_BUILD),y)
137 BASE_LIBS += $(LIBC_PREFIX)/libc.a
138 else
139 BASE_LIBS += $(LIBC_PREFIX)/libc.so.0
140 endif
141endif
142
143BASE_LIBS += -lgcc
144
145ifneq ($(LINK_DYNAMIC),y)
146 LDFLAGS += -static
147endif
148
149INCLUDES_FLAGS = $(LIBC_INCLUDES_FLAGS)
150
151ifneq ($(LIBRARY),)
152 INCLUDES_FLAGS += -Iinclude -I.
153endif
154
155INCLUDES_FLAGS += $(foreach lib,$(LIBS), -I$(LIB_PREFIX)/$(lib) -I$(LIB_PREFIX)/$(lib)/include)
156
157# TODO: get rid of this special case
158ifneq ($(filter math, $(LIBS)),)
159 INCLUDES_FLAGS += $(LIBMATH_INCLUDES_FLAGS)
160endif
161
162# PCUT-based unit tests
163ifneq ($(TEST_SOURCES),)
164 TEST_OUTPUTS = $(TEST_BINARY) $(TEST_BINARY).disasm
165 TEST_CFLAGS = -I$(LIB_PREFIX)/pcut/include -D__helenos__ $(EXTRA_TEST_CFLAGS)
166 TEST_BINARY_LIBS = $(LIB_PREFIX)/pcut/libpcut.a
167 EXTRA_CLEAN += $(TEST_OUTPUTS) $(TEST_BINARY).map
168ifneq ($(LIBRARY),)
169 TEST_BINARY_LIBS += $(LIBRARY).a
170endif
171 TEST_BINARY_LIBS += $(TEST_LIBS)
172endif
173
174# Flags that are not necessary, and can be overriden, but are used by default.
175DEFAULT_CFLAGS = \
176 -O$(OPTIMIZATION) \
177 -ffunction-sections \
178 -fno-builtin-strftime \
179 -pipe \
180 -Wall \
181 -Wextra \
182 -Wno-unused-parameter \
183 -Wno-nonnull-compare \
184 -Wmissing-prototypes \
185 -Wwrite-strings \
186 -Werror-implicit-function-declaration \
187 -Wsystem-headers \
188 -Wunknown-pragmas
189
190# XXX: -fno-builtin-strftime is for a seemingly spurious format warning.
191
192ifeq ($(CONFIG_DEBUG),y)
193 DEFAULT_CFLAGS += -Werror
194endif
195
196ifeq ($(CONFIG_UBSAN),y)
197 DEFAULT_CFLAGS += -fsanitize=undefined
198endif
199
200ifeq ($(COMPILER),clang)
201 DEFAULT_CFLAGS += \
202 -Wno-missing-field-initializers \
203 -Wno-typedef-redefinition \
204 -Wno-unused-command-line-argument
205else
206 DEFAULT_CFLAGS += \
207 -Wno-clobbered
208endif
209
210ifeq ($(CONFIG_LINE_DEBUG),y)
211 DEFAULT_CFLAGS += -ggdb
212endif
213
214# Flags that should always be used, even for third-party software.
215COMMON_CPPFLAGS = \
216 -D__$(ENDIANESS)__
217
218COMMON_CFLAGS = \
219 -nostdlib
220
221# Flags that are always used for HelenOS code, but not for third-party.
222HELENOS_CFLAGS = \
223 -std=gnu99 \
224 $(INCLUDES_FLAGS) \
225 -imacros $(CONFIG_HEADER) \
226 -D_HELENOS_SOURCE \
227 -fexec-charset=UTF-8 \
228 -finput-charset=UTF-8 \
229 -fno-common \
230 -fdebug-prefix-map=$(realpath $(ROOT_PATH))=.
231
232# TODO: Use a different name.
233# CFLAGS variable is traditionally used for overridable flags.
234CFLAGS = $(COMMON_CPPFLAGS) $(COMMON_CFLAGS) $(HELENOS_CFLAGS) $(DEFAULT_CFLAGS)
235
236# Flags for the compilation of C++ code.
237CXX_BASE_LIBS = $(LIBCPP_PREFIX)/libcpp.a $(BASE_LIBS)
238DEFAULT_CXXFLAGS = \
239 -O$(OPTIMIZATION) \
240 -ffunction-sections \
241 -pipe \
242 -Wall \
243 -Wextra \
244 -Wno-unused-parameter \
245 -Wwrite-strings \
246 -Werror-implicit-function-declaration
247
248ifeq ($(CONFIG_DEBUG),y)
249 DEFAULT_CXXFLAGS += -Werror
250endif
251
252COMMON_CXXFLAGS = $(COMMON_CFLAGS) -fno-exceptions
253HELENOS_CXXFLAGS = \
254 -std=c++17 -frtti \
255 $(LIBCPP_INCLUDES_FLAGS) $(INCLUDES_FLAGS) \
256 -imacros $(CONFIG_HEADER) \
257 -D_HELENOS_SOURCE \
258 -fexec-charset=UTF-8 \
259 -finput-charset=UTF-8 \
260 -fno-common \
261 -fdebug-prefix-map=$(realpath $(ROOT_PATH))=.
262
263CXXFLAGS = $(COMMON_CPPFLAGS) $(COMMON_CXXFLAGS) $(HELENOS_CXXFLAGS) $(DEFAULT_CXXFLAGS)
264
265## Setup platform configuration
266#
267
268-include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
269
270## Compilation options
271#
272
273ifeq ($(PRECHECK),y)
274 JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py
275 # XXX: Do not change the order of arguments.
276 CC_JOB = $(JOBFILE) $(JOB) $(CC) $< -o $@
277 CXX_JOB = $(JOBFILE) $(JOB) $(CXX) $< -o $@
278else
279 CC_JOB = $(CC) $< -o $@
280 CXX_JOB = $(CXX) $< -o $@
281endif
282
283ifeq ($(CONFIG_STRIP_BINARIES),y)
284 LDFLAGS += -s
285endif
286
287LIB_CFLAGS = $(CFLAGS) -fPIC
288LIB_LDFLAGS = $(LDFLAGS) -shared -Wl,-soname,$(LSONAME) -Wl,--no-undefined,--no-allow-shlib-undefined
289
290AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
291
292OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
293LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
294TEST_OBJECTS := $(addsuffix .test.o,$(basename $(TEST_SOURCES)))
295DEPENDS := $(addsuffix .d,$(basename $(SOURCES))) $(addsuffix .test.d,$(basename $(TEST_SOURCES)))
296
297LIBTAGS := $(foreach lib,$(LIBS), $(USPACE_PREFIX)/lib/$(lib)/tag)
298LIBARGS := $(addprefix -L$(USPACE_PREFIX)/lib/, $(LIBS)) $(addprefix -l, $(LIBS))
299
300.PHONY: all all-test clean fasterclean depend
301
302all: tag $(OUTPUTS)
303
304all-test: $(TEST_OUTPUTS)
305
306clean: fasterclean
307 find . -name '*.o' -follow -exec rm \{\} \;
308 find . -name '*.lo' -follow -exec rm \{\} \;
309 find . -name '*.d' -follow -exec rm \{\} \;
310
311fasterclean:
312 rm -rf $(JOB) $(OUTPUTS) $(EXTRA_CLEAN) tag deps.mk
313
314depend: $(PRE_DEPEND)
315
316# "Tag" files are used to force relink of binaries when dependencies get rebuilt,
317# regardless of whether the dependency was linked statically or dynamically,
318# or which version of a dynamic library was used. Prerequisites for this file
319# are defined further down.
320tag:
321 touch tag
322
323# Generate inter-module make dependencies.
324# This is needed to ensure correct build order of libraries and code depending on them.
325deps.mk: Makefile
326 echo > $@.new
327 for lib in $(LIBS); do \
328 echo "$(SELF_TARGET): lib/$$lib.build" >> $@.new; \
329 done
330 mv -f $@.new $@
331
332%.disasm: %
333ifeq ($(CONFIG_LINE_DEBUG),y)
334 $(OBJDUMP) -d -S $< > $@
335else
336 $(OBJDUMP) -d $< > $@
337endif
338
339ifneq ($(BINARY),)
340
341ifneq ($(filter %.cpp %.cc %.cxx, $(SOURCES)),)
342$(BINARY): $(OBJECTS) $(LIBTAGS)
343 $(CXX) $(CXXFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -Wl,-Map,$@.map -o $@ $(START_FILES) $(OBJECTS) $(LIBARGS) $(CXX_BASE_LIBS)
344else
345$(BINARY): $(OBJECTS) $(LIBTAGS)
346 $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -Wl,-Map,$@.map -o $@ $(START_FILES) $(OBJECTS) $(LIBARGS) $(BASE_LIBS)
347endif
348
349endif
350
351ifneq ($(TEST_BINARY),)
352$(TEST_BINARY): $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBTAGS)
353 $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -Wl,-Map,$@.map -o $@ $(START_FILES) $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBARGS) $(BASE_LIBS)
354endif
355
356ifneq ($(LIBRARY),)
357tag: $(LIBRARY).a
358
359$(LIBRARY).a: $(OBJECTS)
360 $(AR) rc $@ $(OBJECTS)
361endif
362
363ifneq ($(SLIBRARY),)
364tag: $(SLIBRARY)
365
366$(LIBRARY).la: $(LOBJECTS)
367 $(AR) rc $@ $(LOBJECTS)
368
369$(SLIBRARY): $(LIBRARY).la
370 $(CC) $(CFLAGS) $(LIB_LDFLAGS) $(EXTRA_LDFLAGS) -Wl,-Map,$@.map -o $@ -Wl,--whole-archive $(LIBRARY).la -Wl,--no-whole-archive $(LIBARGS) $(BASE_LIBS)
371
372$(LSONAME):
373 ln -s $(SLIBRARY) $@
374endif
375
376%.o: %.S | depend
377 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
378
379%.o: %.s | depend
380 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
381
382%.o: %.c | depend
383 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS)
384
385%.o: %.cpp | depend
386 $(CXX_JOB) -c -MD -MP $(DEFS) $(CXXFLAGS) $(EXTRA_CXXFLAGS)
387
388%.o: %.cxx | depend
389 $(CXX_JOB) -c -MD -MP $(DEFS) $(CXXFLAGS) $(EXTRA_CXXFLAGS)
390
391%.o: %.cc | depend
392 $(CXX_JOB) -c -MD -MP $(DEFS) $(CXXFLAGS) $(EXTRA_CXXFLAGS)
393
394%.test.o: %.c | depend
395 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(TEST_CFLAGS)
396
397%.lo: %.S | depend
398 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
399
400%.lo: %.s | depend
401 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
402
403%.lo: %.c | depend
404 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS)
405
406%.lo: %.cpp | depend
407 $(CXX_JOB) -c -MD -MP $(DEFS) $(CXXFLAGS) $(EXTRA_CXXFLAGS)
408
409%.lo: %.cxx | depend
410 $(CXX_JOB) -c -MD -MP $(DEFS) $(CXXFLAGS) $(EXTRA_CXXFLAGS)
411
412%.lo: %.cc | depend
413 $(CXX_JOB) -c -MD -MP $(DEFS) $(CXXFLAGS) $(EXTRA_CXXFLAGS)
414
415-include $(DEPENDS)
416
Note: See TracBrowser for help on using the repository browser.