source: mainline/uspace/Makefile.common@ 7b884e55

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7b884e55 was 7b884e55, checked in by jzr <zarevucky.jiri@…>, 8 years ago

Also temporarily disallow shared libsoftint.

libsoftint conceptually belongs before libc, but the linker scripts are
generated as part of libc build. The linker scripts will be moved
elsewhere in the future, but for now just link statically.

  • Property mode set to 100644
File size: 9.3 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# LINKER_SCRIPT linker script
38# PRE_DEPEND targets required for dependency check
39#
40# BINARY (/) binary output name (like appname)
41# LIBRARY (/) library output name (like libname)
42#
43# EXTRA_OUTPUT additional output targets
44# EXTRA_CLEAN additional cleanup targets
45#
46# Optionally, for a binary:
47# STATIC_NEEDED set to 'y' for init binaries, will build statically
48# linked version
49# STATIC_ONLY set to 'y' if binary cannot be linked dynamically
50# (e.g. uses thread-local variables)
51#
52# Optionally, for a library:
53# SOVERSION shared library version (major.minor),
54# if missing, no shared library is built
55#
56# (x) required variables
57# (/) exactly one of the variables must be defined
58#
59
60ROOT_PATH = $(USPACE_PREFIX)/..
61
62COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
63COMMON_HEADER = $(ROOT_PATH)/common.h
64
65CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
66CONFIG_HEADER = $(ROOT_PATH)/config.h
67
68-include $(COMMON_MAKEFILE)
69-include $(CONFIG_MAKEFILE)
70
71OUTPUTS = $(EXTRA_OUTPUT)
72
73ifneq ($(BINARY),)
74 JOB = $(BINARY).job
75 TEST_BINARY = test-$(BINARY)
76 OUTPUTS += $(BINARY) $(BINARY).disasm
77 EXTRA_CLEAN += $(BINARY).map
78endif
79
80ifneq ($(LIBRARY),)
81 JOB = $(LIBRARY).job
82 TEST_BINARY = test-$(LIBRARY)
83 OUTPUTS += $(LIBRARY).a
84endif
85
86ifeq ($(CONFIG_BUILD_SHARED_LIBS),y)
87 ifneq ($(SOVERSION),)
88 SLIBRARY = $(LIBRARY).so.$(SOVERSION)
89 LSONAME = $(LIBRARY).so.$(basename $(SOVERSION))
90 OUTPUTS += $(SLIBRARY) $(SLIBRARY).disasm $(LSONAME)
91 EXTRA_CLEAN += $(LIBRARY).la $(SLIBRARY).map
92 endif
93endif
94
95LIB_PREFIX = $(USPACE_PREFIX)/lib
96
97LIBC_PREFIX = $(LIB_PREFIX)/c
98LIBC_INCLUDES_FLAGS = \
99 -I$(LIBC_PREFIX)/include \
100 -I$(LIBC_PREFIX)/arch/$(UARCH)/include \
101 -I$(ROOT_PATH)/abi/include
102LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
103LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
104
105LIBMATH_PREFIX = $(LIB_PREFIX)/math
106LIBMATH_INCLUDES_FLAGS = \
107 -I$(LIBMATH_PREFIX)/include \
108 -I$(LIBMATH_PREFIX)/arch/$(UARCH)/include
109
110LIBPOSIX_PREFIX = $(LIB_PREFIX)/posix
111LIBDLTEST_PREFIX = $(LIB_PREFIX)/dltest
112
113AFLAGS =
114LFLAGS = --fatal-warnings --warn-common
115
116# FIXME: This condition is a workaround for issues #692 and #693.
117ifneq ($(KARCH),ia64)
118ifneq ($(KARCH),mips32)
119 AFLAGS += --fatal-warnings
120endif
121endif
122
123ifeq ($(STATIC_NEEDED),y)
124 STATIC_BUILD = y
125else
126 ifeq ($(STATIC_ONLY),y)
127 STATIC_BUILD = y
128 else
129 ifeq ($(CONFIG_USE_SHARED_LIBS),y)
130 STATIC_BUILD = n
131 else
132 STATIC_BUILD = y
133 endif
134 endif
135endif
136
137ifeq ($(STATIC_BUILD),y)
138 BASE_LIBS = $(LIBC_PREFIX)/libc.a
139else
140 BASE_LIBS = $(LIBC_PREFIX)/libc.so.0
141 LINK_DYNAMIC = y
142endif
143
144BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a $(LIBSOFTINT_PREFIX)/libsoftint.a
145
146ifeq ($(LINK_DYNAMIC),y)
147 LFLAGS += -Bdynamic
148 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
149else
150 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
151endif
152
153LIB_LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld
154
155INCLUDES_FLAGS = $(LIBC_INCLUDES_FLAGS)
156
157ifneq ($(LIBRARY),)
158 INCLUDES_FLAGS += -Iinclude -I.
159endif
160
161INCLUDES_FLAGS += $(foreach lib,$(LIBS), -I$(LIB_PREFIX)/$(lib) -I$(LIB_PREFIX)/$(lib)/include)
162
163# TODO: get rid of this special case
164ifneq ($(filter math, $(LIBS)),)
165 INCLUDES_FLAGS += $(LIBMATH_INCLUDES_FLAGS)
166endif
167
168# PCUT-based unit tests
169ifneq ($(TEST_SOURCES),)
170 TEST_OUTPUTS = $(TEST_BINARY) $(TEST_BINARY).disasm
171 TEST_CFLAGS = -I$(LIB_PREFIX)/pcut/include -D__helenos__
172 TEST_BINARY_LIBS = $(LIB_PREFIX)/pcut/libpcut.a
173 EXTRA_CLEAN += $(TEST_OUTPUTS) $(TEST_BINARY).map
174ifneq ($(LIBRARY),)
175 TEST_BINARY_LIBS += $(LIBRARY).a
176endif
177 TEST_BINARY_LIBS += $(TEST_LIBS)
178endif
179
180COMMON_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
181 -ffreestanding -fno-builtin -nostdlib -nostdinc -fexec-charset=UTF-8 \
182 -finput-charset=UTF-8 -D__$(ENDIANESS)__ -fno-common \
183 -fdebug-prefix-map=$(realpath $(ROOT_PATH))=.
184
185GCC_CFLAGS = -ffunction-sections -Wall -Wextra -Wno-clobbered \
186 -Wno-unused-parameter -Wmissing-prototypes -std=gnu99 \
187 -Werror-implicit-function-declaration \
188 -Wwrite-strings -pipe
189
190# -Wno-missing-prototypes is there because it warns about main().
191# This should be fixed elsewhere.
192CLANG_CFLAGS = -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-typedef-redefinition \
193 -Wno-missing-prototypes -Wno-unused-command-line-argument \
194 -std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings \
195 -pipe -fno-stack-protector -fno-PIC
196
197ifeq ($(CONFIG_DEBUG),y)
198 COMMON_CFLAGS += -Werror
199endif
200
201ifeq ($(CONFIG_LINE_DEBUG),y)
202 GCC_CFLAGS += -ggdb
203 CLANG_CFLAGS += -g
204endif
205
206## Setup platform configuration
207#
208
209-include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
210
211## Compilation options
212#
213
214ifeq ($(PRECHECK),y)
215 JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py
216 # XXX: Do not change the order of arguments.
217 CC_JOB = $(JOBFILE) $(JOB) $(CC) $< -o $@
218else
219 CC_JOB = $(CC) $< -o $@
220endif
221
222ifeq ($(COMPILER),clang)
223 CFLAGS += $(COMMON_CFLAGS) $(CLANG_CFLAGS)
224else
225 CFLAGS += $(COMMON_CFLAGS) $(GCC_CFLAGS)
226endif
227
228ifeq ($(CONFIG_STRIP_BINARIES),y)
229 LFLAGS += --strip-all
230endif
231
232LIB_CFLAGS = $(CFLAGS) -fPIC
233LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME)
234
235AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
236LD_CFLAGS := $(addprefix -Xlinker ,$(LFLAGS))
237
238OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
239LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
240TEST_OBJECTS := $(addsuffix .test.o,$(basename $(TEST_SOURCES)))
241DEPENDS := $(addsuffix .d,$(basename $(SOURCES))) $(addsuffix .test.d,$(basename $(TEST_SOURCES)))
242
243LIBTAGS := $(foreach lib,$(LIBS), $(USPACE_PREFIX)/lib/$(lib)/tag)
244LIBARGS := $(addprefix -L$(USPACE_PREFIX)/lib/, $(LIBS)) $(addprefix -l, $(LIBS))
245
246-include $(DEPENDS)
247
248.PHONY: all all-test clean depend
249
250all: tag $(OUTPUTS)
251
252all-test: $(TEST_OUTPUTS)
253
254clean:
255 rm -f $(JOB) $(OUTPUTS) $(EXTRA_CLEAN)
256
257depend: $(PRE_DEPEND)
258
259# "Tag" files are used to force relink of binaries when dependencies get rebuilt,
260# regardless of whether the dependency was linked statically or dynamically,
261# or which version of a dynamic library was used. Prerequisites for this file
262# are defined further down.
263tag:
264 touch tag
265
266%.disasm: %
267ifeq ($(CONFIG_LINE_DEBUG),y)
268 $(OBJDUMP) -d -S $< > $@
269else
270 $(OBJDUMP) -d $< > $@
271endif
272
273ifneq ($(BINARY),)
274$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBTAGS) $(BASE_LIBS)
275 $(LD) $(LFLAGS) -T $(LINKER_SCRIPT) -Map $@.map -o $@ $(OBJECTS) $(LIBARGS) $(BASE_LIBS)
276endif
277
278ifneq ($(TEST_BINARY),)
279$(TEST_BINARY): $(LINKER_SCRIPT) $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBTAGS) $(BASE_LIBS)
280 $(LD) $(LFLAGS) -T $(LINKER_SCRIPT) -Map $@.map -o $@ $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBARGS) $(BASE_LIBS)
281endif
282
283ifneq ($(LIBRARY),)
284tag: $(LIBRARY).a
285
286$(LIBRARY).a: $(OBJECTS)
287 $(AR) rc $@ $(OBJECTS)
288endif
289
290ifneq ($(SLIBRARY),)
291tag: $(SLIBRARY)
292
293$(LIBRARY).la: $(LOBJECTS)
294 $(AR) rc $@ $(LOBJECTS)
295
296$(SLIBRARY): $(LIB_LINKER_SCRIPT) $(LIBRARY).la
297 $(LD) $(LIB_LFLAGS) -T $(LIB_LINKER_SCRIPT) -Map $@.map -o $@ --whole-archive $(LIBRARY).la --no-whole-archive
298
299$(LSONAME):
300 ln -s $(SLIBRARY) $@
301endif
302
303%.o: %.S | depend
304 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
305
306%.o: %.s | depend
307 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
308
309%.o: %.c | depend
310 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS)
311
312%.test.o: %.c | depend
313 $(CC_JOB) -c -MD -MP $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(TEST_CFLAGS)
314
315%.lo: %.S | depend
316 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
317
318%.lo: %.s | depend
319 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__
320
321%.lo: %.c | depend
322 $(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS)
323
Note: See TracBrowser for help on using the repository browser.