source: mainline/uspace/Makefile.common@ 60029df

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

XXX to NOTE

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