source: mainline/uspace/Makefile.common@ fb41d44

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

Fix accidentally commited debugging code.

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