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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5a841a4 was 86d0b4b3, checked in by Maurizio Lombardi <m.lombardi85@…>, 14 years ago

Fix minix.h file position

  • Property mode set to 100644
File size: 6.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# 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
75DEPEND = Makefile.depend
76DEPEND_PREV = $(DEPEND).prev
77
78LIB_PREFIX = $(USPACE_PREFIX)/lib
79
80LIBC_PREFIX = $(LIB_PREFIX)/c
81LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
82LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
83
84LIBBLOCK_PREFIX = $(LIB_PREFIX)/block
85LIBFS_PREFIX = $(LIB_PREFIX)/fs
86LIBCLUI_PREFIX = $(LIB_PREFIX)/clui
87
88LIBDRV_PREFIX = $(LIB_PREFIX)/drv
89LIBPACKET_PREFIX = $(LIB_PREFIX)/packet
90LIBNET_PREFIX = $(LIB_PREFIX)/net
91
92LIBMINIX_PREFIX = $(LIB_PREFIX)/minix
93
94BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
95
96LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
97
98ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
99 OPTIMIZATION = s
100else
101 OPTIMIZATION = 3
102endif
103
104.PHONY: all clean
105
106all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(EXTRA_OUTPUT)
107 -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
108
109clean:
110 rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
111 find . -name '*.o' -follow -exec rm \{\} \;
112
113GCC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
114 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
115 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
116 -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
117 -Werror-implicit-function-declaration -Wwrite-strings \
118 -pipe -g -D__$(ENDIANESS)__
119
120ICC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
121 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
122 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
123 -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
124 -Werror-implicit-function-declaration -Wwrite-strings \
125 -pipe -g -D__$(ENDIANESS)__
126
127CLANG_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
128 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
129 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
130 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
131 -Werror-implicit-function-declaration -Wwrite-strings \
132 -pipe -g -arch $(CLANG_ARCH) -D__$(ENDIANESS)__
133
134ifeq ($(CONFIG_DEBUG),y)
135 GCC_CFLAGS += -Werror
136 ICC_CFLAGS += -Werror
137endif
138
139ifeq ($(CONFIG_LINE_DEBUG),y)
140 GCC_CFLAGS += -g
141 ICC_CFLAGS += -g
142 SUNCC_CFLAGS += -g
143 CLANG_CFLAGS += -g
144endif
145
146## Setup platform configuration
147#
148
149-include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
150
151## Compilation options
152#
153
154JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py
155
156ifeq ($(COMPILER),gcc_cross)
157 CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS)
158 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
159endif
160
161ifeq ($(COMPILER),gcc_native)
162 CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS)
163 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
164endif
165
166ifeq ($(COMPILER),icc)
167 CFLAGS = $(ICC_CFLAGS) $(EXTRA_CFLAGS)
168 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
169endif
170
171ifeq ($(COMPILER),clang)
172 CFLAGS = $(CLANG_CFLAGS) $(EXTRA_CFLAGS)
173 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
174endif
175
176-include $(DEPEND)
177
178OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
179
180ifneq ($(BINARY),)
181%.disasm: $(BINARY)
182ifeq ($(CONFIG_LINE_DEBUG),y)
183 $(OBJDUMP) -d -S $< > $@
184else
185 $(OBJDUMP) -d $< > $@
186endif
187
188$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS)
189 $(LD) -N $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS)
190ifeq ($(CONFIG_STRIP_BINARIES),y)
191 $(STRIP) $(BINARY)
192endif
193endif
194
195ifneq ($(LIBRARY),)
196%.a: $(OBJECTS)
197 $(AR) rc $@ $(OBJECTS)
198endif
199
200%.o: %.S $(DEPEND)
201 $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
202ifeq ($(PRECHECK),y)
203 $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
204endif
205
206%.o: %.s $(DEPEND)
207 $(AS) $(AFLAGS) -o $@ $<
208ifeq ($(PRECHECK),y)
209 $(JOBFILE) $(JOB) $< $@ as asm
210endif
211
212%.o: %.c $(DEPEND)
213 $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
214ifeq ($(PRECHECK),y)
215 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
216endif
217
218$(DEPEND): $(PRE_DEPEND)
219 makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(SOURCES) > $@ 2> /dev/null
220 -[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
221
222##
223# This explicit dependecy of the output binary on the object files seems to be
224# necessary to prevent parallel build failures (GNU make bug #26893 ???).
225$(OUTPUT): $(OBJECTS)
226
Note: See TracBrowser for help on using the repository browser.