source: mainline/uspace/Makefile.common@ 9317f45

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9317f45 was 5fb070d, checked in by Dzejrou <dzejrou@…>, 7 years ago

cpp: changed the current standard to C++17, this should be added to config later

  • Property mode set to 100644
File size: 10.5 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
[fc0b2a8]37# LINKER_SCRIPT linker script
[1b1164e8]38# PRE_DEPEND targets required for dependency check
39#
40# BINARY (/) binary output name (like appname)
41# LIBRARY (/) library output name (like libname)
[364778b2]42#
[1b1164e8]43# EXTRA_OUTPUT additional output targets
44# EXTRA_CLEAN additional cleanup targets
45#
[364778b2]46# Optionally, for a binary:
[5b72635]47# STATIC_NEEDED set to 'y' for init binaries, will build statically
48# linked version
[54146a0]49# STATIC_ONLY set to 'y' if binary cannot be linked dynamically
50# (e.g. uses thread-local variables)
[5b72635]51#
[c631734]52# Optionally, for a library:
53# SOVERSION shared library version (major.minor),
54# if missing, no shared library is built
[364778b2]55#
[1b1164e8]56# (x) required variables
57# (/) exactly one of the variables must be defined
58#
59
60ROOT_PATH = $(USPACE_PREFIX)/..
61
[e6ae77a]62VERSION_DEF = $(ROOT_PATH)/version
63
[1b1164e8]64COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
65COMMON_HEADER = $(ROOT_PATH)/common.h
66
67CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
68CONFIG_HEADER = $(ROOT_PATH)/config.h
69
[e6ae77a]70-include $(VERSION_DEF)
[1b1164e8]71-include $(COMMON_MAKEFILE)
72-include $(CONFIG_MAKEFILE)
73
[c631734]74OUTPUTS = $(EXTRA_OUTPUT)
75
[1b1164e8]76ifneq ($(BINARY),)
77 JOB = $(BINARY).job
[01579ad]78 TEST_BINARY = test-$(BINARY)
[c631734]79 OUTPUTS += $(BINARY) $(BINARY).disasm
[1b1164e8]80 EXTRA_CLEAN += $(BINARY).map
81endif
82
83ifneq ($(LIBRARY),)
84 JOB = $(LIBRARY).job
[01579ad]85 TEST_BINARY = test-$(LIBRARY)
[c631734]86 OUTPUTS += $(LIBRARY).a
[1b1164e8]87endif
88
[d9be488]89ifeq ($(CONFIG_BUILD_SHARED_LIBS),y)
[c631734]90 ifneq ($(SOVERSION),)
91 SLIBRARY = $(LIBRARY).so.$(SOVERSION)
92 LSONAME = $(LIBRARY).so.$(basename $(SOVERSION))
93 OUTPUTS += $(SLIBRARY) $(SLIBRARY).disasm $(LSONAME)
94 EXTRA_CLEAN += $(LIBRARY).la $(SLIBRARY).map
[7fb3f1c]95 endif
[143932e3]96endif
97
[36a75a2]98LIB_PREFIX = $(USPACE_PREFIX)/lib
[849ed54]99
100LIBC_PREFIX = $(LIB_PREFIX)/c
[6c5fc8e]101LIBC_INCLUDES_FLAGS = \
102 -I$(LIBC_PREFIX)/include \
103 -I$(LIBC_PREFIX)/arch/$(UARCH)/include \
104 -I$(ROOT_PATH)/abi/include
[058c240]105
106LIBCPP_PREFIX = $(LIB_PREFIX)/cpp
107LIBCPP_INCLUDES_FLAGS = -I$(LIBCPP_PREFIX)/include
108
[849ed54]109LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
110LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
[d9be488]111
[8620b2f]112LIBMATH_PREFIX = $(LIB_PREFIX)/math
[d9be488]113LIBMATH_INCLUDES_FLAGS = \
114 -I$(LIBMATH_PREFIX)/include \
115 -I$(LIBMATH_PREFIX)/arch/$(UARCH)/include
[849ed54]116
[2d2b8e6]117LIBPOSIX_PREFIX = $(LIB_PREFIX)/posix
[9182e86f]118LIBDLTEST_PREFIX = $(LIB_PREFIX)/dltest
[7c014d1]119
[fe171357]120AFLAGS = --fatal-warnings
[009c485]121LDFLAGS = -Wl,--fatal-warnings,--warn-common
[ae7bbfd0]122
[5b72635]123ifeq ($(STATIC_NEEDED),y)
124 STATIC_BUILD = y
[1d465bf]125else
[54146a0]126 ifeq ($(STATIC_ONLY),y)
[5b72635]127 STATIC_BUILD = y
[54146a0]128 else
[d9be488]129 ifeq ($(CONFIG_USE_SHARED_LIBS),y)
[54146a0]130 STATIC_BUILD = n
131 else
132 STATIC_BUILD = y
133 endif
[5b72635]134 endif
135endif
136
[8bcd727]137ifeq ($(STATIC_BUILD),y)
[7b884e55]138 BASE_LIBS = $(LIBC_PREFIX)/libc.a
[5b72635]139else
[7b884e55]140 BASE_LIBS = $(LIBC_PREFIX)/libc.so.0
[7c4b26c]141 LINK_DYNAMIC = y
[d9be488]142endif
143
[7b884e55]144BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a $(LIBSOFTINT_PREFIX)/libsoftint.a
[d2e7a51]145
[fc0b2a8]146ifeq ($(LINK_DYNAMIC),y)
147 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
148else
[009c485]149 LDFLAGS += -static
[fc0b2a8]150 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
[7c4b26c]151endif
152
[fc0b2a8]153LIB_LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld
154
[9d8b12da]155INCLUDES_FLAGS = $(LIBC_INCLUDES_FLAGS)
[1b1164e8]156
[cecba66e]157ifneq ($(LIBRARY),)
158 INCLUDES_FLAGS += -Iinclude -I.
159endif
160
161INCLUDES_FLAGS += $(foreach lib,$(LIBS), -I$(LIB_PREFIX)/$(lib) -I$(LIB_PREFIX)/$(lib)/include)
162
[9d8b12da]163# TODO: get rid of this special case
164ifneq ($(filter math, $(LIBS)),)
165 INCLUDES_FLAGS += $(LIBMATH_INCLUDES_FLAGS)
166endif
167
[01579ad]168# PCUT-based unit tests
169ifneq ($(TEST_SOURCES),)
[c631734]170 TEST_OUTPUTS = $(TEST_BINARY) $(TEST_BINARY).disasm
[4e6a610]171 TEST_CFLAGS = -I$(LIB_PREFIX)/pcut/include -D__helenos__ $(EXTRA_TEST_CFLAGS)
[c631734]172 TEST_BINARY_LIBS = $(LIB_PREFIX)/pcut/libpcut.a
173 EXTRA_CLEAN += $(TEST_OUTPUTS) $(TEST_BINARY).map
[01579ad]174ifneq ($(LIBRARY),)
[c631734]175 TEST_BINARY_LIBS += $(LIBRARY).a
[01579ad]176endif
[c631734]177 TEST_BINARY_LIBS += $(TEST_LIBS)
[01579ad]178endif
179
[2660ee3]180# Flags that are not necessary, and can be overriden, but are used by default.
181DEFAULT_CFLAGS = \
182 -O$(OPTIMIZATION) \
183 -ffunction-sections \
184 -pipe \
185 -Wall \
186 -Wextra \
187 -Wno-unused-parameter \
188 -Wmissing-prototypes \
189 -Wwrite-strings \
190 -Werror-implicit-function-declaration
[143932e3]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 += \
202 -Wno-missing-field-initializers \
203 -Wno-typedef-redefinition \
204 -Wno-unused-command-line-argument
205else
206 DEFAULT_CFLAGS += \
207 -Wno-clobbered
[e805e2f]208endif
209
[1e00216]210ifeq ($(CONFIG_LINE_DEBUG),y)
[2660ee3]211 DEFAULT_CFLAGS += -ggdb
[1e00216]212endif
213
[2660ee3]214# Flags that should always be used, even for third-party software.
[ea42e44]215COMMON_CPPFLAGS = \
[2660ee3]216 -nostdinc \
217 -D__$(ENDIANESS)__
218
[ea42e44]219COMMON_CFLAGS = \
220 -ffreestanding \
221 -nostdlib
222
[2660ee3]223# Flags that are always used for HelenOS code, but not for third-party.
224HELENOS_CFLAGS = \
225 -std=gnu99 \
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.
239CPPFLAGS = $(LIBCPP_INCLUDES_FLAGS) $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
240 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
241 -finput-charset=UTF-8 -ffreestanding -fno-builtin -ffunction-sections \
242 -nostdlib -nostdinc -Wall -Wextra -Wno-clobbered -Wno-unused-parameter \
[5fb070d]243 -std=c++17 -Werror-implicit-function-declaration \
[058c240]244 -Wwrite-strings -pipe -ggdb -D__$(ENDIANESS)__
245
[1b1164e8]246## Setup platform configuration
247#
248
249-include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
250
251## Compilation options
252#
253
[7f881cd8]254ifeq ($(PRECHECK),y)
255 JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py
256 # XXX: Do not change the order of arguments.
257 CC_JOB = $(JOBFILE) $(JOB) $(CC) $< -o $@
258else
259 CC_JOB = $(CC) $< -o $@
260endif
[1b1164e8]261
[315130c]262ifeq ($(CONFIG_STRIP_BINARIES),y)
[009c485]263 LDFLAGS += -s
[315130c]264endif
265
[a0a273e]266LIB_CFLAGS = $(CFLAGS) -fPIC
[009c485]267LIB_LDFLAGS = $(LDFLAGS) -shared -Wl,-soname,$(LSONAME)
[a0a273e]268
269AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
270
[1b1164e8]271OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
[143932e3]272LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
[01579ad]273TEST_OBJECTS := $(addsuffix .test.o,$(basename $(TEST_SOURCES)))
[4761f54]274DEPENDS := $(addsuffix .d,$(basename $(SOURCES))) $(addsuffix .test.d,$(basename $(TEST_SOURCES)))
275
[cecba66e]276LIBTAGS := $(foreach lib,$(LIBS), $(USPACE_PREFIX)/lib/$(lib)/tag)
277LIBARGS := $(addprefix -L$(USPACE_PREFIX)/lib/, $(LIBS)) $(addprefix -l, $(LIBS))
278
[7654f3e]279.PHONY: all all-test clean fasterclean depend
[c631734]280
[cecba66e]281all: tag $(OUTPUTS)
[c631734]282
283all-test: $(TEST_OUTPUTS)
284
[2660ee3]285clean: fasterclean
[7654f3e]286 find . -name '*.o' -follow -exec rm \{\} \;
287 find . -name '*.lo' -follow -exec rm \{\} \;
288 find . -name '*.d' -follow -exec rm \{\} \;
289
290fasterclean:
[2660ee3]291 rm -rf $(JOB) $(OUTPUTS) $(EXTRA_CLEAN) tag deps.mk
[c631734]292
293depend: $(PRE_DEPEND)
294
[cecba66e]295# "Tag" files are used to force relink of binaries when dependencies get rebuilt,
296# regardless of whether the dependency was linked statically or dynamically,
297# or which version of a dynamic library was used. Prerequisites for this file
298# are defined further down.
299tag:
300 touch tag
301
[4f674d7]302# Generate inter-module make dependencies.
303# This is needed to ensure correct build order of libraries and code depending on them.
304deps.mk: Makefile
305 echo > $@.new
306 for lib in $(LIBS); do \
307 echo "$(SELF_TARGET): lib/$$lib.build" >> $@.new; \
308 done
309 mv -f $@.new $@
310
[52a7f238]311%.disasm: %
[9ded977]312ifeq ($(CONFIG_LINE_DEBUG),y)
313 $(OBJDUMP) -d -S $< > $@
314else
[1b1164e8]315 $(OBJDUMP) -d $< > $@
[9ded977]316endif
[1b1164e8]317
[52a7f238]318ifneq ($(BINARY),)
[fc0b2a8]319$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBTAGS) $(BASE_LIBS)
320 $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -T $(LINKER_SCRIPT) -Wl,-Map,$@.map -o $@ $(OBJECTS) $(LIBARGS) $(BASE_LIBS)
[1b1164e8]321endif
322
[c631734]323ifneq ($(TEST_BINARY),)
[fc0b2a8]324$(TEST_BINARY): $(LINKER_SCRIPT) $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBTAGS) $(BASE_LIBS)
325 $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -T $(LINKER_SCRIPT) -Wl,-Map,$@.map -o $@ $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBARGS) $(BASE_LIBS)
[1d465bf]326endif
[143932e3]327
[1b1164e8]328ifneq ($(LIBRARY),)
[cecba66e]329tag: $(LIBRARY).a
330
[eff9f8c]331$(LIBRARY).a: $(OBJECTS)
[1b1164e8]332 $(AR) rc $@ $(OBJECTS)
333endif
334
[c631734]335ifneq ($(SLIBRARY),)
[cecba66e]336tag: $(SLIBRARY)
337
[c631734]338$(LIBRARY).la: $(LOBJECTS)
[143932e3]339 $(AR) rc $@ $(LOBJECTS)
340
[fc0b2a8]341$(SLIBRARY): $(LIB_LINKER_SCRIPT) $(LIBRARY).la
342 $(CC) $(CFLAGS) $(LIB_LDFLAGS) $(EXTRA_LDFLAGS) -T $(LIB_LINKER_SCRIPT) -Wl,-Map,$@.map -o $@ -Wl,--whole-archive $(LIBRARY).la -Wl,--no-whole-archive
[c631734]343
344$(LSONAME):
345 ln -s $(SLIBRARY) $@
[01579ad]346endif
347
[4761f54]348%.o: %.S | depend
[53ad43c]349 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
[1b1164e8]350
[4761f54]351%.o: %.s | depend
[53ad43c]352 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
[1b1164e8]353
[4761f54]354%.o: %.c | depend
[c631734]355 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS)
[1b1164e8]356
[058c240]357%.o: %.cpp | depend
358 $(CPP) $(CPPFLAGS) $(EXTRA_CPPFLAGS) -c $< -o $@
359
[4761f54]360%.test.o: %.c | depend
[c631734]361 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(TEST_CFLAGS)
[01579ad]362
[4761f54]363%.lo: %.S | depend
[53ad43c]364 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
[ec3e2ed]365
[4761f54]366%.lo: %.s | depend
[53ad43c]367 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
[ec3e2ed]368
[4761f54]369%.lo: %.c | depend
[c631734]370 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS)
[664af708]371
[731d8f9]372-include $(DEPENDS)
373
Note: See TracBrowser for help on using the repository browser.