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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7e69e0e was 7e69e0e, checked in by Jiri Svoboda <jiri@…>, 11 years ago

Introducing trackmod and modplay.

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