source: mainline/uspace/Makefile.common@ 3fb14b0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3fb14b0 was 6480827, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Alignment workaround is just for amd64

Oops, this was never meant for the generic makefile and it was
breaking sparc64.

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