source: mainline/uspace/Makefile.common@ 66262a1b

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

Don't use custom ldscripts in uspace.

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
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 -I$(LIBC_PREFIX)/include \
102 -I$(LIBC_PREFIX)/arch/$(UARCH)/include \
103 -I$(ROOT_PATH)/abi/include
104LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
105LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
106
107LIBMATH_PREFIX = $(LIB_PREFIX)/math
108LIBMATH_INCLUDES_FLAGS = \
109 -I$(LIBMATH_PREFIX)/include \
110 -I$(LIBMATH_PREFIX)/arch/$(UARCH)/include
111
112LIBPOSIX_PREFIX = $(LIB_PREFIX)/posix
113LIBDLTEST_PREFIX = $(LIB_PREFIX)/dltest
114
115STARTUP_OBJECT = $(LIBC_PREFIX)/arch/$(UARCH)/src/entry.o
116
117AFLAGS = --fatal-warnings
118LDFLAGS = -Wl,--fatal-warnings,--warn-common
119
120ifeq ($(STATIC_NEEDED),y)
121 STATIC_BUILD = y
122else
123 ifeq ($(STATIC_ONLY),y)
124 STATIC_BUILD = y
125 else
126 ifeq ($(CONFIG_USE_SHARED_LIBS),y)
127 STATIC_BUILD = n
128 else
129 STATIC_BUILD = y
130 endif
131 endif
132endif
133
134ifeq ($(STATIC_BUILD),y)
135 BASE_LIBS = $(LIBC_PREFIX)/libc.a
136else
137 BASE_LIBS = $(LIBC_PREFIX)/libc.so.0
138 LINK_DYNAMIC = y
139endif
140
141BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a $(LIBSOFTINT_PREFIX)/libsoftint.a
142
143ifneq ($(LINK_DYNAMIC),y)
144 LDFLAGS += -static
145endif
146
147INCLUDES_FLAGS = $(LIBC_INCLUDES_FLAGS)
148
149ifneq ($(LIBRARY),)
150 INCLUDES_FLAGS += -Iinclude -I.
151endif
152
153INCLUDES_FLAGS += $(foreach lib,$(LIBS), -I$(LIB_PREFIX)/$(lib) -I$(LIB_PREFIX)/$(lib)/include)
154
155# TODO: get rid of this special case
156ifneq ($(filter math, $(LIBS)),)
157 INCLUDES_FLAGS += $(LIBMATH_INCLUDES_FLAGS)
158endif
159
160# PCUT-based unit tests
161ifneq ($(TEST_SOURCES),)
162 TEST_OUTPUTS = $(TEST_BINARY) $(TEST_BINARY).disasm
163 TEST_CFLAGS = -I$(LIB_PREFIX)/pcut/include -D__helenos__
164 TEST_BINARY_LIBS = $(LIB_PREFIX)/pcut/libpcut.a
165 EXTRA_CLEAN += $(TEST_OUTPUTS) $(TEST_BINARY).map
166ifneq ($(LIBRARY),)
167 TEST_BINARY_LIBS += $(LIBRARY).a
168endif
169 TEST_BINARY_LIBS += $(TEST_LIBS)
170endif
171
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
183
184ifeq ($(CONFIG_DEBUG),y)
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
196endif
197
198ifeq ($(CONFIG_LINE_DEBUG),y)
199 DEFAULT_CFLAGS += -ggdb
200endif
201
202# Flags that should always be used, even for third-party software.
203COMMON_CPPFLAGS = \
204 -nostdinc \
205 -D__$(ENDIANESS)__
206
207COMMON_CFLAGS = \
208 -ffreestanding \
209 -nostdlib
210
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.
224CFLAGS = $(COMMON_CPPFLAGS) $(COMMON_CFLAGS) $(HELENOS_CFLAGS) $(DEFAULT_CFLAGS)
225
226## Setup platform configuration
227#
228
229-include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
230
231## Compilation options
232#
233
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
241
242ifeq ($(CONFIG_STRIP_BINARIES),y)
243 LDFLAGS += -s
244endif
245
246LIB_CFLAGS = $(CFLAGS) -fPIC
247LIB_LDFLAGS = $(LDFLAGS) -shared -Wl,-soname,$(LSONAME)
248
249AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
250
251OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
252LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
253TEST_OBJECTS := $(addsuffix .test.o,$(basename $(TEST_SOURCES)))
254DEPENDS := $(addsuffix .d,$(basename $(SOURCES))) $(addsuffix .test.d,$(basename $(TEST_SOURCES)))
255
256LIBTAGS := $(foreach lib,$(LIBS), $(USPACE_PREFIX)/lib/$(lib)/tag)
257LIBARGS := $(addprefix -L$(USPACE_PREFIX)/lib/, $(LIBS)) $(addprefix -l, $(LIBS))
258
259.PHONY: all all-test clean fasterclean depend
260
261all: tag $(OUTPUTS)
262
263all-test: $(TEST_OUTPUTS)
264
265clean: fasterclean
266 find . -name '*.o' -follow -exec rm \{\} \;
267 find . -name '*.lo' -follow -exec rm \{\} \;
268 find . -name '*.d' -follow -exec rm \{\} \;
269
270fasterclean:
271 rm -rf $(JOB) $(OUTPUTS) $(EXTRA_CLEAN) tag deps.mk
272
273depend: $(PRE_DEPEND)
274
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
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
291%.disasm: %
292ifeq ($(CONFIG_LINE_DEBUG),y)
293 $(OBJDUMP) -d -S $< > $@
294else
295 $(OBJDUMP) -d $< > $@
296endif
297
298ifneq ($(BINARY),)
299$(BINARY): $(OBJECTS) $(LIBTAGS) $(BASE_LIBS)
300 $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -Wl,-Map,$@.map -o $@ $(STARTUP_OBJECT) $(OBJECTS) $(LIBARGS) $(BASE_LIBS)
301endif
302
303ifneq ($(TEST_BINARY),)
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)
306endif
307
308ifneq ($(LIBRARY),)
309tag: $(LIBRARY).a
310
311$(LIBRARY).a: $(OBJECTS)
312 $(AR) rc $@ $(OBJECTS)
313endif
314
315ifneq ($(SLIBRARY),)
316tag: $(SLIBRARY)
317
318$(LIBRARY).la: $(LOBJECTS)
319 $(AR) rc $@ $(LOBJECTS)
320
321$(SLIBRARY): $(LIBRARY).la
322 $(CC) $(CFLAGS) $(LIB_LDFLAGS) $(EXTRA_LDFLAGS) -Wl,-Map,$@.map -o $@ -Wl,--whole-archive $(LIBRARY).la -Wl,--no-whole-archive
323
324$(LSONAME):
325 ln -s $(SLIBRARY) $@
326endif
327
328%.o: %.S | depend
329 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
330
331%.o: %.s | depend
332 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
333
334%.o: %.c | depend
335 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS)
336
337%.test.o: %.c | depend
338 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(TEST_CFLAGS)
339
340%.lo: %.S | depend
341 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
342
343%.lo: %.s | depend
344 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS)
345
346%.lo: %.c | depend
347 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS)
348
349-include $(DEPENDS)
350
Note: See TracBrowser for help on using the repository browser.