source: mainline/uspace/Makefile.common@ 95d5dca

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

merge mainline changes

  • Property mode set to 100644
File size: 10.8 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# 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)
[364778b2]42#
[1b1164e8]43# EXTRA_OUTPUT additional output targets
44# EXTRA_CLEAN additional cleanup targets
45#
[2d2b8e6]46# POSIX_COMPAT set to 'y' to use POSIX compatibility layer
[8620b2f]47# NEEDS_MATH set to 'y' to add implementation of mathematical functions
[2d2b8e6]48#
[364778b2]49# Optionally, for a binary:
[5b72635]50# STATIC_NEEDED set to 'y' for init binaries, will build statically
51# linked version
[54146a0]52# STATIC_ONLY set to 'y' if binary cannot be linked dynamically
53# (e.g. uses thread-local variables)
[5b72635]54#
[364778b2]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#
[1b1164e8]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
[7fb3f1c]89ifeq ($(CONFIG_BUILD_SHARED_LIBS), y)
90 ifneq ($(SLIBRARY),)
91 LARCHIVE = $(LIBRARY).la
92 LOUTPUT = $(SLIBRARY)
[ec883cf]93 EXTRA_OUTPUT += $(LOUTPUT).disasm $(LIBRARY).so $(LSONAME)
[7fb3f1c]94 EXTRA_CLEAN += $(LOUTPUT).map $(LOUTPUT).ldisasm \
[ec883cf]95 $(LIBC_PREFIX)/shared/arch/$(UARCH)/_lib.ld \
96 $(LIBRARY).so $(LSONAME)
[7fb3f1c]97 endif
[143932e3]98endif
99
[1b1164e8]100DEPEND = Makefile.depend
101DEPEND_PREV = $(DEPEND).prev
102
[36a75a2]103LIB_PREFIX = $(USPACE_PREFIX)/lib
[849ed54]104
105LIBC_PREFIX = $(LIB_PREFIX)/c
[6c5fc8e]106LIBC_INCLUDES_FLAGS = \
107 -I$(LIBC_PREFIX)/include \
108 -I$(LIBC_PREFIX)/arch/$(UARCH)/include \
109 -I$(ROOT_PATH)/abi/include
[849ed54]110LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
111LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
[8620b2f]112LIBMATH_PREFIX = $(LIB_PREFIX)/math
[849ed54]113
[2d2b8e6]114LIBPOSIX_PREFIX = $(LIB_PREFIX)/posix
115
[849ed54]116LIBBLOCK_PREFIX = $(LIB_PREFIX)/block
117LIBFS_PREFIX = $(LIB_PREFIX)/fs
[ee7e82a9]118LIBCLUI_PREFIX = $(LIB_PREFIX)/clui
[22cf42d9]119LIBFMTUTIL_PREFIX = $(LIB_PREFIX)/fmtutil
[849ed54]120
[6d5e378]121LIBGRAPH_PREFIX = $(LIB_PREFIX)/graph
122LIBSOFTREND_PREFIX = $(LIB_PREFIX)/softrend
123LIBDRAW_PREFIX = $(LIB_PREFIX)/draw
124LIBGUI_PREFIX = $(LIB_PREFIX)/gui
125
[6c501f8]126LIBEXT4_PREFIX = $(LIB_PREFIX)/ext4
[3bd76491]127
[c0e1be7]128LIBUSB_PREFIX = $(LIB_PREFIX)/usb
[3e4f2e0]129LIBUSBHOST_PREFIX = $(LIB_PREFIX)/usbhost
130LIBUSBDEV_PREFIX = $(LIB_PREFIX)/usbdev
131LIBUSBHID_PREFIX = $(LIB_PREFIX)/usbhid
[b8100da]132LIBUSBVIRT_PREFIX = $(LIB_PREFIX)/usbvirt
[8d6c1f1]133
[c47e1a8]134LIBDRV_PREFIX = $(LIB_PREFIX)/drv
[afa7c17]135LIBHOUND_PREFIX = $(LIB_PREFIX)/hound
[ea6c838]136LIBPCM_PREFIX = $(LIB_PREFIX)/pcm
[849ed54]137LIBNET_PREFIX = $(LIB_PREFIX)/net
[00d7e1b]138LIBNIC_PREFIX = $(LIB_PREFIX)/nic
[86d0b4b3]139LIBMINIX_PREFIX = $(LIB_PREFIX)/minix
[7c014d1]140
[0feaae4]141LIBSCSI_PREFIX = $(LIB_PREFIX)/scsi
142
[681a985]143LIBBITHENGE_PREFIX = $(LIB_PREFIX)/bithenge
144
[d7b7f5e]145LIBHTTP_PREFIX = $(LIB_PREFIX)/http
146LIBURI_PREFIX = $(LIB_PREFIX)/uri
147
[d3a92c87]148LIBMBR_PREFIX = $(LIB_PREFIX)/mbr
[99758c9]149LIBGPT_PREFIX = $(LIB_PREFIX)/gpt
[d3a92c87]150
[5b72635]151ifeq ($(STATIC_NEEDED),y)
152 STATIC_BUILD = y
[1d465bf]153else
[54146a0]154 ifeq ($(STATIC_ONLY),y)
[5b72635]155 STATIC_BUILD = y
[54146a0]156 else
157 ifeq ($(CONFIG_USE_SHARED_LIBS), y)
158 STATIC_BUILD = n
159 else
160 STATIC_BUILD = y
161 endif
[5b72635]162 endif
163endif
164
[a60afd0]165# Build static whenever we use libusb because that library uses
166# thread local variables
167ifneq ($(findstring usb, $(LIBS)),)
168 STATIC_BUILD = y
169endif
[1b1164e8]170
[8bcd727]171ifeq ($(STATIC_BUILD),y)
172 BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
173 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
[5b72635]174else
[8bcd727]175 BASE_LIBS = $(LIBC_PREFIX)/libc.so0 $(LIBSOFTINT_PREFIX)/libsofti.so0
176 LFLAGS = -Bdynamic
177 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
[1d465bf]178endif
[1b1164e8]179
[3c664d6]180ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
181 OPTIMIZATION = s
182else
183 OPTIMIZATION = 3
184endif
185
[1b1164e8]186.PHONY: all clean
187
[143932e3]188all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(LOUTPUT) $(EXTRA_OUTPUT)
[1b1164e8]189 -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
190
191clean:
[143932e3]192 rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(LARCHIVE) $(LOUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
[1b1164e8]193 find . -name '*.o' -follow -exec rm \{\} \;
[143932e3]194 find . -name '*.lo' -follow -exec rm \{\} \;
[1b1164e8]195
[aebcd42]196GCC_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
[1b1164e8]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 \
[e8c5c11]200 -std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings \
[17d214e]201 -pipe -ggdb -D__$(ENDIANESS)__
[1b1164e8]202
[aebcd42]203ICC_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
[1b1164e8]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 \
[e805e2f]208 -pipe -g -D__$(ENDIANESS)__
[1b1164e8]209
[1570759b]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
[aebcd42]213CLANG_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
[1570759b]214 -ffreestanding -fno-builtin -nostdlib -nostdinc \
[1b1164e8]215 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
216 -Werror-implicit-function-declaration -Wwrite-strings \
[b92a0ee]217 -integrated-as \
[1570759b]218 -pipe -g -target $(CLANG_TARGET) -D__$(ENDIANESS)__
[1b1164e8]219
[143932e3]220LIB_CFLAGS = $(CFLAGS) -fPIC -D__IN_SHARED_LIBC__
221LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME) --whole-archive
222
[e805e2f]223ifeq ($(CONFIG_DEBUG),y)
224 GCC_CFLAGS += -Werror
225 ICC_CFLAGS += -Werror
226endif
227
[1e00216]228ifeq ($(CONFIG_LINE_DEBUG),y)
229 GCC_CFLAGS += -g
230 ICC_CFLAGS += -g
231 CLANG_CFLAGS += -g
232endif
233
[ba4799a]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
[8620b2f]240# Do we need math?
241ifeq ($(NEEDS_MATH),y)
242 BASE_LIBS += $(LIBMATH_PREFIX)/libmath.a
243endif
244
[1b1164e8]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)
[2d2b8e6]256 CFLAGS += $(GCC_CFLAGS) $(EXTRA_CFLAGS)
[1b1164e8]257 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
258endif
259
[8f2eca0]260ifeq ($(COMPILER),gcc_helenos)
261 CFLAGS += $(GCC_CFLAGS) $(EXTRA_CFLAGS)
262 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
263endif
264
[1b1164e8]265ifeq ($(COMPILER),gcc_native)
[2d2b8e6]266 CFLAGS += $(GCC_CFLAGS) $(EXTRA_CFLAGS)
[1b1164e8]267 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
268endif
269
270ifeq ($(COMPILER),icc)
[2d2b8e6]271 CFLAGS += $(ICC_CFLAGS) $(EXTRA_CFLAGS)
[1b1164e8]272 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
273endif
274
275ifeq ($(COMPILER),clang)
[2d2b8e6]276 CFLAGS += $(CLANG_CFLAGS) $(EXTRA_CFLAGS)
[1570759b]277 GCC_CFLAGS += $(EXTRA_CFLAGS)
[1b1164e8]278 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
279endif
280
281-include $(DEPEND)
282
283OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
[143932e3]284LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
[1b1164e8]285
286ifneq ($(BINARY),)
287%.disasm: $(BINARY)
[9ded977]288ifeq ($(CONFIG_LINE_DEBUG),y)
289 $(OBJDUMP) -d -S $< > $@
290else
[1b1164e8]291 $(OBJDUMP) -d $< > $@
[9ded977]292endif
[1b1164e8]293
294$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS)
[afdcc60e]295 $(LD) -n $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS)
[1cb092d]296ifeq ($(CONFIG_STRIP_BINARIES),y)
297 $(STRIP) $(BINARY)
298endif
[1b1164e8]299endif
300
[1d465bf]301ifneq ($(SLIBRARY),)
302%.disasm: $(LOUTPUT)
303ifeq ($(CONFIG_LINE_DEBUG),y)
304 $(OBJDUMP) -d -S $< > $@
305else
306 $(OBJDUMP) -d $< > $@
307endif
308
[729f774f]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
[ec883cf]311
312$(LIBRARY).so:
313 ln -s $(SLIBRARY) $@
314
315$(LSONAME):
316 ln -s $(SLIBRARY) $@
[1d465bf]317endif
[143932e3]318
[1b1164e8]319ifneq ($(LIBRARY),)
[67edca6]320%.a: $(OBJECTS)
[1b1164e8]321 $(AR) rc $@ $(OBJECTS)
322endif
323
[143932e3]324ifneq ($(SLIBRARY),)
[67edca6]325%.la: $(LOBJECTS)
[143932e3]326 $(AR) rc $@ $(LOBJECTS)
327endif
328
[1b1164e8]329%.o: %.S $(DEPEND)
[1570759b]330 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c $< -o $@
[1b1164e8]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
[0e9b512]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
[ec3e2ed]352
[0e9b512]353%.lo: %.s $(DEPEND)
354 $(AS) $(AFLAGS) -o $@ $<
355ifeq ($(PRECHECK),y)
356 $(JOBFILE) $(JOB) $< $@ as asm
357endif
[ec3e2ed]358
[143932e3]359%.lo: %.c $(DEPEND)
360 $(CC) $(DEFS) $(LIB_CFLAGS) -c $< -o $@
361ifeq ($(PRECHECK),y)
362 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
363endif
364
[1b1164e8]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) $@
[664af708]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
[143932e3]374$(LARCHIVE): $(LOBJECTS)
Note: See TracBrowser for help on using the repository browser.