source: mainline/uspace/Makefile.common@ ed88c8e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ed88c8e was a05ec66, checked in by GitHub <noreply@…>, 7 years ago

Don't use custom ldscripts in uspace. (#38)

Even with the *-linux-gnu targets, there is practically nothing Linux-specific
in the linker itself. We get a few GNU program headers this way, but those
can be safely ignored.

  • Property mode set to 100644
File size: 9.6 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 = \
101 -I$(LIBC_PREFIX)/include \
102 -I$(LIBC_PREFIX)/arch/$(UARCH)/include \
103 -I$(ROOT_PATH)/abi/include
[849ed54]104LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
105LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
[d9be488]106
[8620b2f]107LIBMATH_PREFIX = $(LIB_PREFIX)/math
[d9be488]108LIBMATH_INCLUDES_FLAGS = \
109 -I$(LIBMATH_PREFIX)/include \
110 -I$(LIBMATH_PREFIX)/arch/$(UARCH)/include
[849ed54]111
[2d2b8e6]112LIBPOSIX_PREFIX = $(LIB_PREFIX)/posix
[9182e86f]113LIBDLTEST_PREFIX = $(LIB_PREFIX)/dltest
[7c014d1]114
[a05ec66]115STARTUP_OBJECT = $(LIBC_PREFIX)/arch/$(UARCH)/src/entry.o
116
[fe171357]117AFLAGS = --fatal-warnings
[009c485]118LDFLAGS = -Wl,--fatal-warnings,--warn-common
[ae7bbfd0]119
[5b72635]120ifeq ($(STATIC_NEEDED),y)
121 STATIC_BUILD = y
[1d465bf]122else
[54146a0]123 ifeq ($(STATIC_ONLY),y)
[5b72635]124 STATIC_BUILD = y
[54146a0]125 else
[d9be488]126 ifeq ($(CONFIG_USE_SHARED_LIBS),y)
[54146a0]127 STATIC_BUILD = n
128 else
129 STATIC_BUILD = y
130 endif
[5b72635]131 endif
132endif
133
[8bcd727]134ifeq ($(STATIC_BUILD),y)
[7b884e55]135 BASE_LIBS = $(LIBC_PREFIX)/libc.a
[5b72635]136else
[7b884e55]137 BASE_LIBS = $(LIBC_PREFIX)/libc.so.0
[7c4b26c]138 LINK_DYNAMIC = y
[d9be488]139endif
140
[7b884e55]141BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a $(LIBSOFTINT_PREFIX)/libsoftint.a
[d2e7a51]142
[a05ec66]143ifneq ($(LINK_DYNAMIC),y)
[009c485]144 LDFLAGS += -static
[7c4b26c]145endif
146
[9d8b12da]147INCLUDES_FLAGS = $(LIBC_INCLUDES_FLAGS)
[1b1164e8]148
[cecba66e]149ifneq ($(LIBRARY),)
150 INCLUDES_FLAGS += -Iinclude -I.
151endif
152
153INCLUDES_FLAGS += $(foreach lib,$(LIBS), -I$(LIB_PREFIX)/$(lib) -I$(LIB_PREFIX)/$(lib)/include)
154
[9d8b12da]155# TODO: get rid of this special case
156ifneq ($(filter math, $(LIBS)),)
157 INCLUDES_FLAGS += $(LIBMATH_INCLUDES_FLAGS)
158endif
159
[01579ad]160# PCUT-based unit tests
161ifneq ($(TEST_SOURCES),)
[c631734]162 TEST_OUTPUTS = $(TEST_BINARY) $(TEST_BINARY).disasm
[01579ad]163 TEST_CFLAGS = -I$(LIB_PREFIX)/pcut/include -D__helenos__
[c631734]164 TEST_BINARY_LIBS = $(LIB_PREFIX)/pcut/libpcut.a
165 EXTRA_CLEAN += $(TEST_OUTPUTS) $(TEST_BINARY).map
[01579ad]166ifneq ($(LIBRARY),)
[c631734]167 TEST_BINARY_LIBS += $(LIBRARY).a
[01579ad]168endif
[c631734]169 TEST_BINARY_LIBS += $(TEST_LIBS)
[01579ad]170endif
171
[2660ee3]172# Flags that are not necessary, and can be overriden, but are used by default.
173DEFAULT_CFLAGS = \
174 -O$(OPTIMIZATION) \
175 -ffunction-sections \
176 -pipe \
177 -Wall \
178 -Wextra \
179 -Wno-unused-parameter \
180 -Wmissing-prototypes \
181 -Wwrite-strings \
182 -Werror-implicit-function-declaration
[143932e3]183
[e805e2f]184ifeq ($(CONFIG_DEBUG),y)
[2660ee3]185 DEFAULT_CFLAGS += -Werror
186endif
187
188ifeq ($(COMPILER),clang)
189 DEFAULT_CFLAGS += \
190 -Wno-missing-field-initializers \
191 -Wno-typedef-redefinition \
192 -Wno-unused-command-line-argument
193else
194 DEFAULT_CFLAGS += \
195 -Wno-clobbered
[e805e2f]196endif
197
[1e00216]198ifeq ($(CONFIG_LINE_DEBUG),y)
[2660ee3]199 DEFAULT_CFLAGS += -ggdb
[1e00216]200endif
201
[2660ee3]202# Flags that should always be used, even for third-party software.
[ea42e44]203COMMON_CPPFLAGS = \
[2660ee3]204 -nostdinc \
205 -D__$(ENDIANESS)__
206
[ea42e44]207COMMON_CFLAGS = \
208 -ffreestanding \
209 -nostdlib
210
[2660ee3]211# Flags that are always used for HelenOS code, but not for third-party.
212HELENOS_CFLAGS = \
213 -std=gnu99 \
214 $(INCLUDES_FLAGS) \
215 -imacros $(CONFIG_HEADER) \
216 -D_HELENOS_SOURCE \
217 -fexec-charset=UTF-8 \
218 -finput-charset=UTF-8 \
219 -fno-common \
220 -fdebug-prefix-map=$(realpath $(ROOT_PATH))=.
221
222# TODO: Use a different name.
223# CFLAGS variable is traditionally used for overridable flags.
[ea42e44]224CFLAGS = $(COMMON_CPPFLAGS) $(COMMON_CFLAGS) $(HELENOS_CFLAGS) $(DEFAULT_CFLAGS)
[2660ee3]225
[1b1164e8]226## Setup platform configuration
227#
228
229-include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
230
231## Compilation options
232#
233
[7f881cd8]234ifeq ($(PRECHECK),y)
235 JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py
236 # XXX: Do not change the order of arguments.
237 CC_JOB = $(JOBFILE) $(JOB) $(CC) $< -o $@
238else
239 CC_JOB = $(CC) $< -o $@
240endif
[1b1164e8]241
[315130c]242ifeq ($(CONFIG_STRIP_BINARIES),y)
[009c485]243 LDFLAGS += -s
[315130c]244endif
245
[a0a273e]246LIB_CFLAGS = $(CFLAGS) -fPIC
[009c485]247LIB_LDFLAGS = $(LDFLAGS) -shared -Wl,-soname,$(LSONAME)
[a0a273e]248
249AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
250
[1b1164e8]251OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
[143932e3]252LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
[01579ad]253TEST_OBJECTS := $(addsuffix .test.o,$(basename $(TEST_SOURCES)))
[4761f54]254DEPENDS := $(addsuffix .d,$(basename $(SOURCES))) $(addsuffix .test.d,$(basename $(TEST_SOURCES)))
255
[cecba66e]256LIBTAGS := $(foreach lib,$(LIBS), $(USPACE_PREFIX)/lib/$(lib)/tag)
257LIBARGS := $(addprefix -L$(USPACE_PREFIX)/lib/, $(LIBS)) $(addprefix -l, $(LIBS))
258
[7654f3e]259.PHONY: all all-test clean fasterclean depend
[c631734]260
[cecba66e]261all: tag $(OUTPUTS)
[c631734]262
263all-test: $(TEST_OUTPUTS)
264
[2660ee3]265clean: fasterclean
[7654f3e]266 find . -name '*.o' -follow -exec rm \{\} \;
267 find . -name '*.lo' -follow -exec rm \{\} \;
268 find . -name '*.d' -follow -exec rm \{\} \;
269
270fasterclean:
[2660ee3]271 rm -rf $(JOB) $(OUTPUTS) $(EXTRA_CLEAN) tag deps.mk
[c631734]272
273depend: $(PRE_DEPEND)
274
[cecba66e]275# "Tag" files are used to force relink of binaries when dependencies get rebuilt,
276# regardless of whether the dependency was linked statically or dynamically,
277# or which version of a dynamic library was used. Prerequisites for this file
278# are defined further down.
279tag:
280 touch tag
281
[4f674d7]282# Generate inter-module make dependencies.
283# This is needed to ensure correct build order of libraries and code depending on them.
284deps.mk: Makefile
285 echo > $@.new
286 for lib in $(LIBS); do \
287 echo "$(SELF_TARGET): lib/$$lib.build" >> $@.new; \
288 done
289 mv -f $@.new $@
290
[52a7f238]291%.disasm: %
[9ded977]292ifeq ($(CONFIG_LINE_DEBUG),y)
293 $(OBJDUMP) -d -S $< > $@
294else
[1b1164e8]295 $(OBJDUMP) -d $< > $@
[9ded977]296endif
[1b1164e8]297
[52a7f238]298ifneq ($(BINARY),)
[a05ec66]299$(BINARY): $(OBJECTS) $(LIBTAGS) $(BASE_LIBS)
300 $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -Wl,-Map,$@.map -o $@ $(STARTUP_OBJECT) $(OBJECTS) $(LIBARGS) $(BASE_LIBS)
[1b1164e8]301endif
302
[c631734]303ifneq ($(TEST_BINARY),)
[a05ec66]304$(TEST_BINARY): $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBTAGS) $(BASE_LIBS)
305 $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -Wl,-Map,$@.map -o $@ $(STARTUP_OBJECT) $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBARGS) $(BASE_LIBS)
[1d465bf]306endif
[143932e3]307
[1b1164e8]308ifneq ($(LIBRARY),)
[cecba66e]309tag: $(LIBRARY).a
310
[eff9f8c]311$(LIBRARY).a: $(OBJECTS)
[1b1164e8]312 $(AR) rc $@ $(OBJECTS)
313endif
314
[c631734]315ifneq ($(SLIBRARY),)
[cecba66e]316tag: $(SLIBRARY)
317
[c631734]318$(LIBRARY).la: $(LOBJECTS)
[143932e3]319 $(AR) rc $@ $(LOBJECTS)
320
[a05ec66]321$(SLIBRARY): $(LIBRARY).la
322 $(CC) $(CFLAGS) $(LIB_LDFLAGS) $(EXTRA_LDFLAGS) -Wl,-Map,$@.map -o $@ -Wl,--whole-archive $(LIBRARY).la -Wl,--no-whole-archive
[c631734]323
324$(LSONAME):
325 ln -s $(SLIBRARY) $@
[01579ad]326endif
327
[4761f54]328%.o: %.S | depend
[53ad43c]329 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
[1b1164e8]330
[4761f54]331%.o: %.s | depend
[53ad43c]332 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
[1b1164e8]333
[4761f54]334%.o: %.c | depend
[c631734]335 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS)
[1b1164e8]336
[4761f54]337%.test.o: %.c | depend
[c631734]338 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(TEST_CFLAGS)
[01579ad]339
[4761f54]340%.lo: %.S | depend
[53ad43c]341 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
[ec3e2ed]342
[4761f54]343%.lo: %.s | depend
[53ad43c]344 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
[ec3e2ed]345
[4761f54]346%.lo: %.c | depend
[c631734]347 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS)
[664af708]348
[731d8f9]349-include $(DEPENDS)
350
Note: See TracBrowser for help on using the repository browser.