source: mainline/uspace/Makefile.common@ 8620b2f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8620b2f 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
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
148ifeq ($(STATIC_NEEDED),y)
149 STATIC_BUILD = y
150else
151 ifeq ($(STATIC_ONLY),y)
152 STATIC_BUILD = y
153 else
154 ifeq ($(CONFIG_USE_SHARED_LIBS), y)
155 STATIC_BUILD = n
156 else
157 STATIC_BUILD = y
158 endif
159 endif
160endif
161
162# Build static whenever we use libusb because that library uses
163# thread local variables
164ifneq ($(findstring usb, $(LIBS)),)
165 STATIC_BUILD = y
166endif
167
168ifeq ($(STATIC_BUILD),y)
169 BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
170 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
171else
172 BASE_LIBS = $(LIBC_PREFIX)/libc.so0 $(LIBSOFTINT_PREFIX)/libsofti.so0
173 LFLAGS = -Bdynamic
174 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
175endif
176
177ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
178 OPTIMIZATION = s
179else
180 OPTIMIZATION = 3
181endif
182
183.PHONY: all clean
184
185all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(LOUTPUT) $(EXTRA_OUTPUT)
186 -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
187
188clean:
189 rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(LARCHIVE) $(LOUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
190 find . -name '*.o' -follow -exec rm \{\} \;
191 find . -name '*.lo' -follow -exec rm \{\} \;
192
193GCC_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
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 \
197 -std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings \
198 -pipe -ggdb -D__$(ENDIANESS)__
199
200ICC_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
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 \
205 -pipe -g -D__$(ENDIANESS)__
206
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
210CLANG_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
211 -ffreestanding -fno-builtin -nostdlib -nostdinc \
212 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
213 -Werror-implicit-function-declaration -Wwrite-strings \
214 -integrated-as \
215 -pipe -g -target $(CLANG_TARGET) -D__$(ENDIANESS)__
216
217LIB_CFLAGS = $(CFLAGS) -fPIC -D__IN_SHARED_LIBC__
218LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME) --whole-archive
219
220ifeq ($(CONFIG_DEBUG),y)
221 GCC_CFLAGS += -Werror
222 ICC_CFLAGS += -Werror
223endif
224
225ifeq ($(CONFIG_LINE_DEBUG),y)
226 GCC_CFLAGS += -g
227 ICC_CFLAGS += -g
228 CLANG_CFLAGS += -g
229endif
230
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
237# Do we need math?
238ifeq ($(NEEDS_MATH),y)
239 BASE_LIBS += $(LIBMATH_PREFIX)/libmath.a
240endif
241
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)
253 CFLAGS += $(GCC_CFLAGS) $(EXTRA_CFLAGS)
254 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
255endif
256
257ifeq ($(COMPILER),gcc_helenos)
258 CFLAGS += $(GCC_CFLAGS) $(EXTRA_CFLAGS)
259 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
260endif
261
262ifeq ($(COMPILER),gcc_native)
263 CFLAGS += $(GCC_CFLAGS) $(EXTRA_CFLAGS)
264 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
265endif
266
267ifeq ($(COMPILER),icc)
268 CFLAGS += $(ICC_CFLAGS) $(EXTRA_CFLAGS)
269 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
270endif
271
272ifeq ($(COMPILER),clang)
273 CFLAGS += $(CLANG_CFLAGS) $(EXTRA_CFLAGS)
274 GCC_CFLAGS += $(EXTRA_CFLAGS)
275 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
276endif
277
278-include $(DEPEND)
279
280OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
281LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
282
283ifneq ($(BINARY),)
284%.disasm: $(BINARY)
285ifeq ($(CONFIG_LINE_DEBUG),y)
286 $(OBJDUMP) -d -S $< > $@
287else
288 $(OBJDUMP) -d $< > $@
289endif
290
291$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS)
292 $(LD) -n $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS)
293ifeq ($(CONFIG_STRIP_BINARIES),y)
294 $(STRIP) $(BINARY)
295endif
296endif
297
298ifneq ($(SLIBRARY),)
299%.disasm: $(LOUTPUT)
300ifeq ($(CONFIG_LINE_DEBUG),y)
301 $(OBJDUMP) -d -S $< > $@
302else
303 $(OBJDUMP) -d $< > $@
304endif
305
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
308
309$(LIBRARY).so:
310 ln -s $(SLIBRARY) $@
311
312$(LSONAME):
313 ln -s $(SLIBRARY) $@
314endif
315
316ifneq ($(LIBRARY),)
317%.a: $(OBJECTS)
318 $(AR) rc $@ $(OBJECTS)
319endif
320
321ifneq ($(SLIBRARY),)
322%.la: $(LOBJECTS)
323 $(AR) rc $@ $(LOBJECTS)
324endif
325
326%.o: %.S $(DEPEND)
327 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c $< -o $@
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
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
349
350%.lo: %.s $(DEPEND)
351 $(AS) $(AFLAGS) -o $@ $<
352ifeq ($(PRECHECK),y)
353 $(JOBFILE) $(JOB) $< $@ as asm
354endif
355
356%.lo: %.c $(DEPEND)
357 $(CC) $(DEFS) $(LIB_CFLAGS) -c $< -o $@
358ifeq ($(PRECHECK),y)
359 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
360endif
361
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) $@
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
371$(LARCHIVE): $(LOBJECTS)
Note: See TracBrowser for help on using the repository browser.