source: mainline/uspace/Makefile.common@ 5b72635

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

Use dynamic linking for all apps and servers except those that are used
as init binaries. Turn on and off with CONFIG_USE_SHARED_LIBS.

  • Property mode set to 100644
File size: 8.4 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# EXTRA_OUTPUT additional output targets
43# EXTRA_CLEAN additional cleanup targets
44#
45# STATIC_NEEDED set to 'y' for init binaries, will build statically
46# linked version
47#
48# (x) required variables
49# (/) exactly one of the variables must be defined
50#
51
52ROOT_PATH = $(USPACE_PREFIX)/..
53
54VERSION_DEF = $(ROOT_PATH)/version
55
56COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
57COMMON_HEADER = $(ROOT_PATH)/common.h
58
59CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
60CONFIG_HEADER = $(ROOT_PATH)/config.h
61
62-include $(VERSION_DEF)
63-include $(COMMON_MAKEFILE)
64-include $(CONFIG_MAKEFILE)
65
66ifneq ($(BINARY),)
67 JOB = $(BINARY).job
68 OUTPUT = $(BINARY)
69 EXTRA_OUTPUT += $(BINARY).disasm
70 EXTRA_CLEAN += $(BINARY).map
71endif
72
73ifneq ($(LIBRARY),)
74 JOB = $(LIBRARY).job
75 OUTPUT = $(LIBRARY).a
76endif
77
78ifeq ($(CONFIG_BUILD_SHARED_LIBS), y)
79 ifneq ($(SLIBRARY),)
80 LARCHIVE = $(LIBRARY).la
81 LOUTPUT = $(SLIBRARY)
82 EXTRA_OUTPUT += $(LOUTPUT).disasm
83 EXTRA_CLEAN += $(LOUTPUT).map $(LOUTPUT).ldisasm \
84 $(LIBC_PREFIX)/shared/arch/$(UARCH)/_lib.ld
85 endif
86endif
87
88DEPEND = Makefile.depend
89DEPEND_PREV = $(DEPEND).prev
90
91LIB_PREFIX = $(USPACE_PREFIX)/lib
92
93LIBC_PREFIX = $(LIB_PREFIX)/c
94LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
95LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
96
97LIBBLOCK_PREFIX = $(LIB_PREFIX)/block
98LIBFS_PREFIX = $(LIB_PREFIX)/fs
99LIBCLUI_PREFIX = $(LIB_PREFIX)/clui
100
101LIBDRV_PREFIX = $(LIB_PREFIX)/drv
102LIBPACKET_PREFIX = $(LIB_PREFIX)/packet
103LIBNET_PREFIX = $(LIB_PREFIX)/net
104
105ifeq ($(STATIC_NEEDED),y)
106 STATIC_BUILD = y
107else
108 ifeq ($(CONFIG_USE_SHARED_LIBS), y)
109 STATIC_BUILD = n
110 else
111 STATIC_BUILD = y
112 endif
113endif
114
115ifeq ($(STATIC_BUILD), y)
116BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
117LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
118else
119BASE_LIBS = $(LIBC_PREFIX)/libc.so.0 $(LIBSOFTINT_PREFIX)/libsoftint.a
120LFLAGS = -Bdynamic
121LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
122endif
123
124ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
125 OPTIMIZATION = s
126else
127 OPTIMIZATION = 3
128endif
129
130.PHONY: all clean
131
132all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(LOUTPUT) $(EXTRA_OUTPUT)
133 -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
134
135clean:
136 rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(LARCHIVE) $(LOUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
137 find . -name '*.o' -follow -exec rm \{\} \;
138 find . -name '*.lo' -follow -exec rm \{\} \;
139
140GCC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
141 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
142 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
143 -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
144 -Werror-implicit-function-declaration -Wwrite-strings \
145 -pipe -g -D__$(ENDIANESS)__
146
147ICC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
148 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
149 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
150 -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
151 -Werror-implicit-function-declaration -Wwrite-strings \
152 -pipe -g -D__$(ENDIANESS)__
153
154CLANG_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
155 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
156 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
157 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
158 -Werror-implicit-function-declaration -Wwrite-strings \
159 -pipe -g -arch $(CLANG_ARCH) -D__$(ENDIANESS)__
160
161LIB_CFLAGS = $(CFLAGS) -fPIC -D__IN_SHARED_LIBC__
162LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME) --whole-archive
163
164ifeq ($(CONFIG_DEBUG),y)
165 GCC_CFLAGS += -Werror
166 ICC_CFLAGS += -Werror
167endif
168
169ifeq ($(CONFIG_LINE_DEBUG),y)
170 GCC_CFLAGS += -g
171 ICC_CFLAGS += -g
172 SUNCC_CFLAGS += -g
173 CLANG_CFLAGS += -g
174endif
175
176## Setup platform configuration
177#
178
179-include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
180
181## Compilation options
182#
183
184JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py
185
186ifeq ($(COMPILER),gcc_cross)
187 CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS)
188 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
189endif
190
191ifeq ($(COMPILER),gcc_native)
192 CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS)
193 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
194endif
195
196ifeq ($(COMPILER),icc)
197 CFLAGS = $(ICC_CFLAGS) $(EXTRA_CFLAGS)
198 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
199endif
200
201ifeq ($(COMPILER),clang)
202 CFLAGS = $(CLANG_CFLAGS) $(EXTRA_CFLAGS)
203 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
204endif
205
206-include $(DEPEND)
207
208OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
209LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
210
211ifneq ($(BINARY),)
212%.disasm: $(BINARY)
213ifeq ($(CONFIG_LINE_DEBUG),y)
214 $(OBJDUMP) -d -S $< > $@
215else
216 $(OBJDUMP) -d $< > $@
217endif
218
219$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS)
220 $(LD) -n $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS)
221ifeq ($(CONFIG_STRIP_BINARIES),y)
222 $(STRIP) $(BINARY)
223endif
224endif
225
226ifneq ($(SLIBRARY),)
227%.disasm: $(LOUTPUT)
228ifeq ($(CONFIG_LINE_DEBUG),y)
229 $(OBJDUMP) -d -S $< > $@
230else
231 $(OBJDUMP) -d $< > $@
232endif
233
234$(LOUTPUT): $(LARCHIVE) $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld
235 $(LD) -T $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld $(LIB_LFLAGS) $(LARCHIVE) -o $@ -Map $(LOUTPUT).map
236endif
237
238ifneq ($(LIBRARY),)
239%.a: $(OBJECTS)
240 $(AR) rc $@ $(OBJECTS)
241endif
242
243ifneq ($(SLIBRARY),)
244%.la: $(LOBJECTS)
245 $(AR) rc $@ $(LOBJECTS)
246endif
247
248%.o: %.S $(DEPEND)
249 $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
250ifeq ($(PRECHECK),y)
251 $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
252endif
253
254%.o: %.s $(DEPEND)
255 $(AS) $(AFLAGS) -o $@ $<
256ifeq ($(PRECHECK),y)
257 $(JOBFILE) $(JOB) $< $@ as asm
258endif
259
260%.o: %.c $(DEPEND)
261 $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
262ifeq ($(PRECHECK),y)
263 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
264endif
265
266%.lo: %.S $(DEPEND)
267 $(CC) $(DEFS) $(LIB_CFLAGS) -D__ASM__ -c $< -o $@
268ifeq ($(PRECHECK),y)
269 $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
270endif
271
272%.lo: %.s $(DEPEND)
273 $(AS) $(AFLAGS) -o $@ $<
274ifeq ($(PRECHECK),y)
275 $(JOBFILE) $(JOB) $< $@ as asm
276endif
277
278%.lo: %.c $(DEPEND)
279 $(CC) $(DEFS) $(LIB_CFLAGS) -c $< -o $@
280ifeq ($(PRECHECK),y)
281 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
282endif
283
284$(DEPEND): $(PRE_DEPEND)
285 makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(SOURCES) > $@ 2> /dev/null
286 -[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
287
288##
289# This explicit dependecy of the output binary on the object files seems to be
290# necessary to prevent parallel build failures (GNU make bug #26893 ???).
291$(OUTPUT): $(OBJECTS)
292
293$(LARCHIVE): $(LOBJECTS)
Note: See TracBrowser for help on using the repository browser.