source: mainline/uspace/Makefile.common@ 75baf6e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 75baf6e was 0773396, checked in by Martin Decky <martin@…>, 12 years ago

merge mainline changes

  • Property mode set to 100644
File size: 10.8 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# POSIX_COMPAT set to 'y' to use POSIX compatibility layer
47# NEEDS_MATH set to 'y' to add implementation of mathematical functions
48#
49# Optionally, for a binary:
50# STATIC_NEEDED set to 'y' for init binaries, will build statically
51# linked version
52# STATIC_ONLY set to 'y' if binary cannot be linked dynamically
53# (e.g. uses thread-local variables)
54#
55# Optionally, for a libary:
56# SLIBRARY Name with full version, e.g. libfoo.so.0.0
57# LSONAME Soname / name with short version, e.g. libfoo.so.0
58#
59# (x) required variables
60# (/) exactly one of the variables must be defined
61#
62
63ROOT_PATH = $(USPACE_PREFIX)/..
64
65VERSION_DEF = $(ROOT_PATH)/version
66
67COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
68COMMON_HEADER = $(ROOT_PATH)/common.h
69
70CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
71CONFIG_HEADER = $(ROOT_PATH)/config.h
72
73-include $(VERSION_DEF)
74-include $(COMMON_MAKEFILE)
75-include $(CONFIG_MAKEFILE)
76
77ifneq ($(BINARY),)
78 JOB = $(BINARY).job
79 OUTPUT = $(BINARY)
80 EXTRA_OUTPUT += $(BINARY).disasm
81 EXTRA_CLEAN += $(BINARY).map
82endif
83
84ifneq ($(LIBRARY),)
85 JOB = $(LIBRARY).job
86 OUTPUT = $(LIBRARY).a
87endif
88
89ifeq ($(CONFIG_BUILD_SHARED_LIBS), y)
90 ifneq ($(SLIBRARY),)
91 LARCHIVE = $(LIBRARY).la
92 LOUTPUT = $(SLIBRARY)
93 EXTRA_OUTPUT += $(LOUTPUT).disasm $(LIBRARY).so $(LSONAME)
94 EXTRA_CLEAN += $(LOUTPUT).map $(LOUTPUT).ldisasm \
95 $(LIBC_PREFIX)/shared/arch/$(UARCH)/_lib.ld \
96 $(LIBRARY).so $(LSONAME)
97 endif
98endif
99
100DEPEND = Makefile.depend
101DEPEND_PREV = $(DEPEND).prev
102
103LIB_PREFIX = $(USPACE_PREFIX)/lib
104
105LIBC_PREFIX = $(LIB_PREFIX)/c
106LIBC_INCLUDES_FLAGS = \
107 -I$(LIBC_PREFIX)/include \
108 -I$(LIBC_PREFIX)/arch/$(UARCH)/include \
109 -I$(ROOT_PATH)/abi/include
110LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
111LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
112LIBMATH_PREFIX = $(LIB_PREFIX)/math
113
114LIBPOSIX_PREFIX = $(LIB_PREFIX)/posix
115
116LIBBLOCK_PREFIX = $(LIB_PREFIX)/block
117LIBFS_PREFIX = $(LIB_PREFIX)/fs
118LIBCLUI_PREFIX = $(LIB_PREFIX)/clui
119LIBFMTUTIL_PREFIX = $(LIB_PREFIX)/fmtutil
120
121LIBGRAPH_PREFIX = $(LIB_PREFIX)/graph
122LIBSOFTREND_PREFIX = $(LIB_PREFIX)/softrend
123LIBDRAW_PREFIX = $(LIB_PREFIX)/draw
124LIBGUI_PREFIX = $(LIB_PREFIX)/gui
125
126LIBEXT4_PREFIX = $(LIB_PREFIX)/ext4
127
128LIBUSB_PREFIX = $(LIB_PREFIX)/usb
129LIBUSBHOST_PREFIX = $(LIB_PREFIX)/usbhost
130LIBUSBDEV_PREFIX = $(LIB_PREFIX)/usbdev
131LIBUSBHID_PREFIX = $(LIB_PREFIX)/usbhid
132LIBUSBVIRT_PREFIX = $(LIB_PREFIX)/usbvirt
133
134LIBDRV_PREFIX = $(LIB_PREFIX)/drv
135LIBHOUND_PREFIX = $(LIB_PREFIX)/hound
136LIBPCM_PREFIX = $(LIB_PREFIX)/pcm
137LIBNET_PREFIX = $(LIB_PREFIX)/net
138LIBNIC_PREFIX = $(LIB_PREFIX)/nic
139LIBMINIX_PREFIX = $(LIB_PREFIX)/minix
140
141LIBSCSI_PREFIX = $(LIB_PREFIX)/scsi
142
143LIBBITHENGE_PREFIX = $(LIB_PREFIX)/bithenge
144
145LIBHTTP_PREFIX = $(LIB_PREFIX)/http
146LIBURI_PREFIX = $(LIB_PREFIX)/uri
147
148LIBMBR_PREFIX = $(LIB_PREFIX)/mbr
149LIBGPT_PREFIX = $(LIB_PREFIX)/gpt
150
151ifeq ($(STATIC_NEEDED),y)
152 STATIC_BUILD = y
153else
154 ifeq ($(STATIC_ONLY),y)
155 STATIC_BUILD = y
156 else
157 ifeq ($(CONFIG_USE_SHARED_LIBS), y)
158 STATIC_BUILD = n
159 else
160 STATIC_BUILD = y
161 endif
162 endif
163endif
164
165# Build static whenever we use libusb because that library uses
166# thread local variables
167ifneq ($(findstring usb, $(LIBS)),)
168 STATIC_BUILD = y
169endif
170
171ifeq ($(STATIC_BUILD),y)
172 BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
173 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
174else
175 BASE_LIBS = $(LIBC_PREFIX)/libc.so0 $(LIBSOFTINT_PREFIX)/libsofti.so0
176 LFLAGS = -Bdynamic
177 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
178endif
179
180ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
181 OPTIMIZATION = s
182else
183 OPTIMIZATION = 3
184endif
185
186.PHONY: all clean
187
188all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(LOUTPUT) $(EXTRA_OUTPUT)
189 -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
190
191clean:
192 rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(LARCHIVE) $(LOUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
193 find . -name '*.o' -follow -exec rm \{\} \;
194 find . -name '*.lo' -follow -exec rm \{\} \;
195
196GCC_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
197 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
198 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
199 -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
200 -std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings \
201 -pipe -ggdb -D__$(ENDIANESS)__
202
203ICC_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
204 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
205 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
206 -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
207 -Werror-implicit-function-declaration -Wwrite-strings \
208 -pipe -g -D__$(ENDIANESS)__
209
210# clang does not support following options but I am not sure whether
211# something won't break because of that:
212# -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) -finput-charset=UTF-8
213CLANG_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
214 -ffreestanding -fno-builtin -nostdlib -nostdinc \
215 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
216 -Werror-implicit-function-declaration -Wwrite-strings \
217 -integrated-as \
218 -pipe -g -target $(CLANG_TARGET) -D__$(ENDIANESS)__
219
220LIB_CFLAGS = $(CFLAGS) -fPIC -D__IN_SHARED_LIBC__
221LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME) --whole-archive
222
223ifeq ($(CONFIG_DEBUG),y)
224 GCC_CFLAGS += -Werror
225 ICC_CFLAGS += -Werror
226endif
227
228ifeq ($(CONFIG_LINE_DEBUG),y)
229 GCC_CFLAGS += -g
230 ICC_CFLAGS += -g
231 CLANG_CFLAGS += -g
232endif
233
234# Prepare for POSIX before including platform specific stuff
235ifeq ($(POSIX_COMPAT),y)
236 CFLAGS = -I$(LIBPOSIX_PREFIX)/include/posix -I$(LIBPOSIX_PREFIX)/include/
237 BASE_LIBS = $(LIBPOSIX_PREFIX)/libposixaslibc.a $(LIBPOSIX_PREFIX)/libc4posix.a $(LIBSOFTINT_PREFIX)/libsoftint.a
238endif
239
240# Do we need math?
241ifeq ($(NEEDS_MATH),y)
242 BASE_LIBS += $(LIBMATH_PREFIX)/libmath.a
243endif
244
245## Setup platform configuration
246#
247
248-include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
249
250## Compilation options
251#
252
253JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py
254
255ifeq ($(COMPILER),gcc_cross)
256 CFLAGS += $(GCC_CFLAGS) $(EXTRA_CFLAGS)
257 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
258endif
259
260ifeq ($(COMPILER),gcc_helenos)
261 CFLAGS += $(GCC_CFLAGS) $(EXTRA_CFLAGS)
262 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
263endif
264
265ifeq ($(COMPILER),gcc_native)
266 CFLAGS += $(GCC_CFLAGS) $(EXTRA_CFLAGS)
267 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
268endif
269
270ifeq ($(COMPILER),icc)
271 CFLAGS += $(ICC_CFLAGS) $(EXTRA_CFLAGS)
272 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
273endif
274
275ifeq ($(COMPILER),clang)
276 CFLAGS += $(CLANG_CFLAGS) $(EXTRA_CFLAGS)
277 GCC_CFLAGS += $(EXTRA_CFLAGS)
278 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
279endif
280
281-include $(DEPEND)
282
283OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
284LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
285
286ifneq ($(BINARY),)
287%.disasm: $(BINARY)
288ifeq ($(CONFIG_LINE_DEBUG),y)
289 $(OBJDUMP) -d -S $< > $@
290else
291 $(OBJDUMP) -d $< > $@
292endif
293
294$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS)
295 $(LD) -n $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS)
296ifeq ($(CONFIG_STRIP_BINARIES),y)
297 $(STRIP) $(BINARY)
298endif
299endif
300
301ifneq ($(SLIBRARY),)
302%.disasm: $(LOUTPUT)
303ifeq ($(CONFIG_LINE_DEBUG),y)
304 $(OBJDUMP) -d -S $< > $@
305else
306 $(OBJDUMP) -d $< > $@
307endif
308
309$(LOUTPUT): $(LARCHIVE) $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld
310 $(LD) -T $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld $(LIB_LFLAGS) $(LARCHIVE) -o $@ -Map $(LOUTPUT).map
311
312$(LIBRARY).so:
313 ln -s $(SLIBRARY) $@
314
315$(LSONAME):
316 ln -s $(SLIBRARY) $@
317endif
318
319ifneq ($(LIBRARY),)
320%.a: $(OBJECTS)
321 $(AR) rc $@ $(OBJECTS)
322endif
323
324ifneq ($(SLIBRARY),)
325%.la: $(LOBJECTS)
326 $(AR) rc $@ $(LOBJECTS)
327endif
328
329%.o: %.S $(DEPEND)
330 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c $< -o $@
331ifeq ($(PRECHECK),y)
332 $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
333endif
334
335%.o: %.s $(DEPEND)
336 $(AS) $(AFLAGS) -o $@ $<
337ifeq ($(PRECHECK),y)
338 $(JOBFILE) $(JOB) $< $@ as asm
339endif
340
341%.o: %.c $(DEPEND)
342 $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
343ifeq ($(PRECHECK),y)
344 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
345endif
346
347%.lo: %.S $(DEPEND)
348 $(CC) $(DEFS) $(LIB_CFLAGS) -D__ASM__ -c $< -o $@
349ifeq ($(PRECHECK),y)
350 $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
351endif
352
353%.lo: %.s $(DEPEND)
354 $(AS) $(AFLAGS) -o $@ $<
355ifeq ($(PRECHECK),y)
356 $(JOBFILE) $(JOB) $< $@ as asm
357endif
358
359%.lo: %.c $(DEPEND)
360 $(CC) $(DEFS) $(LIB_CFLAGS) -c $< -o $@
361ifeq ($(PRECHECK),y)
362 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
363endif
364
365$(DEPEND): $(PRE_DEPEND)
366 makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(SOURCES) > $@ 2> /dev/null
367 -[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
368
369##
370# This explicit dependecy of the output binary on the object files seems to be
371# necessary to prevent parallel build failures (GNU make bug #26893 ???).
372$(OUTPUT): $(OBJECTS)
373
374$(LARCHIVE): $(LOBJECTS)
Note: See TracBrowser for help on using the repository browser.