source: mainline/uspace/Makefile.common@ ec3e2ed0

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

Build shared C library. Add config options for building and using all libraries
as shared instead of just C library (not working yet). Move libtest under
lib/test.

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