source: mainline/uspace/Makefile.common@ dc20e31

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since dc20e31 was 8620b2f, checked in by Vojtech Horky <vojtechhorky@…>, 12 years ago

Move math functions into a separate library

Their implementation is still non-existent but at least
replacement is possible as the application (such as Python)
could be linked with a functional 3rd party library.

  • Property mode set to 100644
File size: 10.7 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
[5b72635]148ifeq ($(STATIC_NEEDED),y)
149 STATIC_BUILD = y
[1d465bf]150else
[54146a0]151 ifeq ($(STATIC_ONLY),y)
[5b72635]152 STATIC_BUILD = y
[54146a0]153 else
154 ifeq ($(CONFIG_USE_SHARED_LIBS), y)
155 STATIC_BUILD = n
156 else
157 STATIC_BUILD = y
158 endif
[5b72635]159 endif
160endif
161
[a60afd0]162# Build static whenever we use libusb because that library uses
163# thread local variables
164ifneq ($(findstring usb, $(LIBS)),)
165 STATIC_BUILD = y
166endif
[1b1164e8]167
[8bcd727]168ifeq ($(STATIC_BUILD),y)
169 BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
170 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
[5b72635]171else
[8bcd727]172 BASE_LIBS = $(LIBC_PREFIX)/libc.so0 $(LIBSOFTINT_PREFIX)/libsofti.so0
173 LFLAGS = -Bdynamic
174 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
[1d465bf]175endif
[1b1164e8]176
[3c664d6]177ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
178 OPTIMIZATION = s
179else
180 OPTIMIZATION = 3
181endif
182
[1b1164e8]183.PHONY: all clean
184
[143932e3]185all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(LOUTPUT) $(EXTRA_OUTPUT)
[1b1164e8]186 -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
187
188clean:
[143932e3]189 rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(LARCHIVE) $(LOUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
[1b1164e8]190 find . -name '*.o' -follow -exec rm \{\} \;
[143932e3]191 find . -name '*.lo' -follow -exec rm \{\} \;
[1b1164e8]192
[aebcd42]193GCC_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
[1b1164e8]194 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
195 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
196 -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
[e8c5c11]197 -std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings \
[17d214e]198 -pipe -ggdb -D__$(ENDIANESS)__
[1b1164e8]199
[aebcd42]200ICC_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
[1b1164e8]201 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
202 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
203 -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
204 -Werror-implicit-function-declaration -Wwrite-strings \
[e805e2f]205 -pipe -g -D__$(ENDIANESS)__
[1b1164e8]206
[1570759b]207# clang does not support following options but I am not sure whether
208# something won't break because of that:
209# -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) -finput-charset=UTF-8
[aebcd42]210CLANG_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
[1570759b]211 -ffreestanding -fno-builtin -nostdlib -nostdinc \
[1b1164e8]212 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
213 -Werror-implicit-function-declaration -Wwrite-strings \
[b92a0ee]214 -integrated-as \
[1570759b]215 -pipe -g -target $(CLANG_TARGET) -D__$(ENDIANESS)__
[1b1164e8]216
[143932e3]217LIB_CFLAGS = $(CFLAGS) -fPIC -D__IN_SHARED_LIBC__
218LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME) --whole-archive
219
[e805e2f]220ifeq ($(CONFIG_DEBUG),y)
221 GCC_CFLAGS += -Werror
222 ICC_CFLAGS += -Werror
223endif
224
[1e00216]225ifeq ($(CONFIG_LINE_DEBUG),y)
226 GCC_CFLAGS += -g
227 ICC_CFLAGS += -g
228 CLANG_CFLAGS += -g
229endif
230
[ba4799a]231# Prepare for POSIX before including platform specific stuff
232ifeq ($(POSIX_COMPAT),y)
233 CFLAGS = -I$(LIBPOSIX_PREFIX)/include/posix -I$(LIBPOSIX_PREFIX)/include/
234 BASE_LIBS = $(LIBPOSIX_PREFIX)/libposixaslibc.a $(LIBPOSIX_PREFIX)/libc4posix.a $(LIBSOFTINT_PREFIX)/libsoftint.a
235endif
236
[8620b2f]237# Do we need math?
238ifeq ($(NEEDS_MATH),y)
239 BASE_LIBS += $(LIBMATH_PREFIX)/libmath.a
240endif
241
[1b1164e8]242## Setup platform configuration
243#
244
245-include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
246
247## Compilation options
248#
249
250JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py
251
252ifeq ($(COMPILER),gcc_cross)
[2d2b8e6]253 CFLAGS += $(GCC_CFLAGS) $(EXTRA_CFLAGS)
[1b1164e8]254 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
255endif
256
[8f2eca0]257ifeq ($(COMPILER),gcc_helenos)
258 CFLAGS += $(GCC_CFLAGS) $(EXTRA_CFLAGS)
259 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
260endif
261
[1b1164e8]262ifeq ($(COMPILER),gcc_native)
[2d2b8e6]263 CFLAGS += $(GCC_CFLAGS) $(EXTRA_CFLAGS)
[1b1164e8]264 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
265endif
266
267ifeq ($(COMPILER),icc)
[2d2b8e6]268 CFLAGS += $(ICC_CFLAGS) $(EXTRA_CFLAGS)
[1b1164e8]269 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
270endif
271
272ifeq ($(COMPILER),clang)
[2d2b8e6]273 CFLAGS += $(CLANG_CFLAGS) $(EXTRA_CFLAGS)
[1570759b]274 GCC_CFLAGS += $(EXTRA_CFLAGS)
[1b1164e8]275 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
276endif
277
278-include $(DEPEND)
279
280OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
[143932e3]281LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
[1b1164e8]282
283ifneq ($(BINARY),)
284%.disasm: $(BINARY)
[9ded977]285ifeq ($(CONFIG_LINE_DEBUG),y)
286 $(OBJDUMP) -d -S $< > $@
287else
[1b1164e8]288 $(OBJDUMP) -d $< > $@
[9ded977]289endif
[1b1164e8]290
291$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS)
[afdcc60e]292 $(LD) -n $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS)
[1cb092d]293ifeq ($(CONFIG_STRIP_BINARIES),y)
294 $(STRIP) $(BINARY)
295endif
[1b1164e8]296endif
297
[1d465bf]298ifneq ($(SLIBRARY),)
299%.disasm: $(LOUTPUT)
300ifeq ($(CONFIG_LINE_DEBUG),y)
301 $(OBJDUMP) -d -S $< > $@
302else
303 $(OBJDUMP) -d $< > $@
304endif
305
[729f774f]306$(LOUTPUT): $(LARCHIVE) $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld
307 $(LD) -T $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld $(LIB_LFLAGS) $(LARCHIVE) -o $@ -Map $(LOUTPUT).map
[ec883cf]308
309$(LIBRARY).so:
310 ln -s $(SLIBRARY) $@
311
312$(LSONAME):
313 ln -s $(SLIBRARY) $@
[1d465bf]314endif
[143932e3]315
[1b1164e8]316ifneq ($(LIBRARY),)
[67edca6]317%.a: $(OBJECTS)
[1b1164e8]318 $(AR) rc $@ $(OBJECTS)
319endif
320
[143932e3]321ifneq ($(SLIBRARY),)
[67edca6]322%.la: $(LOBJECTS)
[143932e3]323 $(AR) rc $@ $(LOBJECTS)
324endif
325
[1b1164e8]326%.o: %.S $(DEPEND)
[1570759b]327 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c $< -o $@
[1b1164e8]328ifeq ($(PRECHECK),y)
329 $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
330endif
331
332%.o: %.s $(DEPEND)
333 $(AS) $(AFLAGS) -o $@ $<
334ifeq ($(PRECHECK),y)
335 $(JOBFILE) $(JOB) $< $@ as asm
336endif
337
338%.o: %.c $(DEPEND)
339 $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
340ifeq ($(PRECHECK),y)
341 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
342endif
343
[0e9b512]344%.lo: %.S $(DEPEND)
345 $(CC) $(DEFS) $(LIB_CFLAGS) -D__ASM__ -c $< -o $@
346ifeq ($(PRECHECK),y)
347 $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
348endif
[ec3e2ed]349
[0e9b512]350%.lo: %.s $(DEPEND)
351 $(AS) $(AFLAGS) -o $@ $<
352ifeq ($(PRECHECK),y)
353 $(JOBFILE) $(JOB) $< $@ as asm
354endif
[ec3e2ed]355
[143932e3]356%.lo: %.c $(DEPEND)
357 $(CC) $(DEFS) $(LIB_CFLAGS) -c $< -o $@
358ifeq ($(PRECHECK),y)
359 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
360endif
361
[1b1164e8]362$(DEPEND): $(PRE_DEPEND)
363 makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(SOURCES) > $@ 2> /dev/null
364 -[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
[664af708]365
366##
367# This explicit dependecy of the output binary on the object files seems to be
368# necessary to prevent parallel build failures (GNU make bug #26893 ???).
369$(OUTPUT): $(OBJECTS)
370
[143932e3]371$(LARCHIVE): $(LOBJECTS)
Note: See TracBrowser for help on using the repository browser.