source: mainline/kernel/Makefile.build@ ba50a34

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ba50a34 was 218e50c, checked in by Martin Decky <martin@…>, 16 years ago

style changes

  • Property mode set to 100644
File size: 11.4 KB
Line 
1#
2# Copyright (c) 2005 Martin Decky
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# - Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# - Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# - The name of the author may not be used to endorse or promote products
15# derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28
29
30## Include configuration
31#
32
33include Makefile.common
34include ../version
35include ../Makefile.config
36include ../config.defs
37
38LINK = arch/$(KARCH)/_link.ld
39EMPTY_MAP = generic/src/debug/empty_map.o
40SIZEOK_MAP = generic/src/debug/sizeok_map.o
41
42INCLUDES = generic/include
43OPTIMIZATION = 3
44
45ifndef CROSS_PREFIX
46 CROSS_PREFIX = /usr/local
47endif
48
49## Common compiler flags
50#
51
52DEFS = -DKERNEL -DRELEASE=$(RELEASE) "-DNAME=$(NAME)" -D__$(BITS)_BITS__ -D__$(ENDIANESS)__
53
54GCC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros ../config.h \
55 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
56 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
57 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Werror \
58 -pipe
59
60ICC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros ../config.h \
61 -ffreestanding -fno-builtin -nostdlib -nostdinc -Wall -Wmissing-prototypes \
62 -Werror -wd170
63
64SUNCC_CFLAGS = -I$(INCLUDES) -xO$(OPTIMIZATION) \
65 -xnolib -xc99=all -features=extensions \
66 -erroff=E_ZERO_SIZED_STRUCT_UNION
67
68CLANG_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros ../config.h \
69 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
70 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
71 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -pipe \
72 -arch $(CLANG_ARCH)
73
74LFLAGS = -M
75AFLAGS =
76
77-include arch/$(KARCH)/Makefile.inc
78-include genarch/Makefile.inc
79
80## The at-sign
81#
82# The $(ATSIGN) variable holds the ASCII character representing the at-sign
83# ('@') used in various $(AS) constructs (e.g. @progbits). On architectures that
84# don't use '@' for starting a comment, $(ATSIGN) is merely '@'. However, on
85# those that do use it for starting a comment (e.g. arm32), $(ATSIGN) must be
86# defined as the percentile-sign ('%') in the architecture-dependent
87# Makefile.inc.
88#
89ATSIGN ?= @
90
91## Cross-platform assembly to start a symtab.data section
92#
93SYMTAB_SECTION = ".section symtab.data, \"a\", $(ATSIGN)progbits;"
94
95## Simple detection for the type of the host system
96#
97HOST = $(shell uname)
98
99## On Solaris, some utilities have slightly different names
100#
101ifeq ($(HOST),SunOS)
102 BINUTILS_PREFIX = "g"
103else
104 BINUTILS_PREFIX = ""
105endif
106
107## Toolchain configuration
108#
109
110ifeq ($(COMPILER),gcc_native)
111 CC = gcc
112 GCC = gcc
113 AS = $(BINUTILS_PREFIX)as
114 LD = $(BINUTILS_PREFIX)ld
115 OBJCOPY = $(BINUTILS_PREFIX)objcopy
116 OBJDUMP = $(BINUTILS_PREFIX)objdump
117 LIBDIR = /usr/lib
118 CFLAGS = $(GCC_CFLAGS)
119 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
120endif
121
122ifeq ($(COMPILER),gcc_cross)
123 CC = $(TOOLCHAIN_DIR)/bin/$(TARGET)-gcc
124 GCC = $(CC)
125 AS = $(TOOLCHAIN_DIR)/bin/$(TARGET)-as
126 LD = $(TOOLCHAIN_DIR)/bin/$(TARGET)-ld
127 OBJCOPY = $(TOOLCHAIN_DIR)/bin/$(TARGET)-objcopy
128 OBJDUMP = $(TOOLCHAIN_DIR)/bin/$(TARGET)-objdump
129 LIBDIR = $(TOOLCHAIN_DIR)/lib
130 CFLAGS = $(GCC_CFLAGS)
131 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
132endif
133
134ifeq ($(COMPILER),icc)
135 CC = icc
136 GCC = gcc
137 AS = as
138 LD = ld
139 OBJCOPY = objcopy
140 OBJDUMP = objdump
141 LIBDIR = /usr/lib
142 CFLAGS = $(ICC_CFLAGS)
143 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
144endif
145
146ifeq ($(COMPILER),suncc)
147 CC = suncc
148 GCC = gcc
149 AS = $(BINUTILS_PREFIX)as
150 LD = $(BINUTILS_PREFIX)ld
151 OBJCOPY = $(BINUTILS_PREFIX)objcopy
152 OBJDUMP = $(BINUTILS_PREFIX)objdump
153 LIBDIR = /usr/lib
154 CFLAGS = $(SUNCC_CFLAGS)
155 DEFS += $(CONFIG_DEFS)
156 DEPEND_DEFS = $(DEFS)
157endif
158
159ifeq ($(COMPILER),clang)
160 CC = clang
161 GCC = gcc
162 AS = $(BINUTILS_PREFIX)as
163 LD = $(BINUTILS_PREFIX)ld
164 OBJCOPY = $(BINUTILS_PREFIX)objcopy
165 OBJDUMP = $(BINUTILS_PREFIX)objdump
166 LIBDIR = /usr/lib
167 CFLAGS = $(CLANG_CFLAGS)
168 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
169endif
170
171
172## Generic kernel sources
173#
174
175GENERIC_SOURCES = \
176 generic/src/adt/avl.c \
177 generic/src/adt/bitmap.c \
178 generic/src/adt/btree.c \
179 generic/src/adt/hash_table.c \
180 generic/src/adt/list.c \
181 generic/src/console/chardev.c \
182 generic/src/console/console.c \
183 generic/src/cpu/cpu.c \
184 generic/src/ddi/ddi.c \
185 generic/src/ddi/irq.c \
186 generic/src/ddi/device.c \
187 generic/src/debug/symtab.c \
188 generic/src/interrupt/interrupt.c \
189 generic/src/main/main.c \
190 generic/src/main/kinit.c \
191 generic/src/main/uinit.c \
192 generic/src/main/version.c \
193 generic/src/main/shutdown.c \
194 generic/src/proc/program.c \
195 generic/src/proc/scheduler.c \
196 generic/src/proc/thread.c \
197 generic/src/proc/task.c \
198 generic/src/proc/the.c \
199 generic/src/proc/tasklet.c \
200 generic/src/syscall/syscall.c \
201 generic/src/syscall/copy.c \
202 generic/src/mm/buddy.c \
203 generic/src/mm/frame.c \
204 generic/src/mm/page.c \
205 generic/src/mm/tlb.c \
206 generic/src/mm/as.c \
207 generic/src/mm/backend_anon.c \
208 generic/src/mm/backend_elf.c \
209 generic/src/mm/backend_phys.c \
210 generic/src/mm/slab.c \
211 generic/src/lib/func.c \
212 generic/src/lib/memstr.c \
213 generic/src/lib/sort.c \
214 generic/src/lib/string.c \
215 generic/src/lib/elf.c \
216 generic/src/lib/rd.c \
217 generic/src/printf/printf_core.c \
218 generic/src/printf/printf.c \
219 generic/src/printf/snprintf.c \
220 generic/src/printf/vprintf.c \
221 generic/src/printf/vsnprintf.c \
222 generic/src/time/clock.c \
223 generic/src/time/timeout.c \
224 generic/src/time/delay.c \
225 generic/src/preempt/preemption.c \
226 generic/src/synch/spinlock.c \
227 generic/src/synch/condvar.c \
228 generic/src/synch/rwlock.c \
229 generic/src/synch/mutex.c \
230 generic/src/synch/semaphore.c \
231 generic/src/synch/smc.c \
232 generic/src/synch/waitq.c \
233 generic/src/synch/futex.c \
234 generic/src/smp/ipi.c \
235 generic/src/smp/smp.c \
236 generic/src/ipc/ipc.c \
237 generic/src/ipc/sysipc.c \
238 generic/src/ipc/ipcrsc.c \
239 generic/src/ipc/irq.c \
240 generic/src/ipc/event.c \
241 generic/src/security/cap.c \
242 generic/src/sysinfo/sysinfo.c
243
244## Kernel console support
245#
246
247ifeq ($(CONFIG_KCONSOLE),y)
248GENERIC_SOURCES += \
249 generic/src/console/kconsole.c \
250 generic/src/console/cmd.c
251endif
252
253## Udebug interface sources
254#
255
256ifeq ($(CONFIG_UDEBUG),y)
257GENERIC_SOURCES += \
258 generic/src/ipc/kbox.c \
259 generic/src/udebug/udebug.c \
260 generic/src/udebug/udebug_ops.c \
261 generic/src/udebug/udebug_ipc.c
262endif
263
264## Test sources
265#
266
267ifeq ($(CONFIG_TEST),y)
268 CFLAGS += -Itest/
269 GENERIC_SOURCES += \
270 test/test.c \
271 test/atomic/atomic1.c \
272 test/btree/btree1.c \
273 test/avltree/avltree1.c \
274 test/fault/fault1.c \
275 test/mm/falloc1.c \
276 test/mm/falloc2.c \
277 test/mm/mapping1.c \
278 test/mm/slab1.c \
279 test/mm/slab2.c \
280 test/synch/rwlock1.c \
281 test/synch/rwlock2.c \
282 test/synch/rwlock3.c \
283 test/synch/rwlock4.c \
284 test/synch/rwlock5.c \
285 test/synch/semaphore1.c \
286 test/synch/semaphore2.c \
287 test/print/print1.c \
288 test/print/print2.c \
289 test/print/print3.c \
290 test/print/print4.c \
291 test/thread/thread1.c \
292 test/sysinfo/sysinfo1.c
293
294 ifeq ($(KARCH),mips32)
295 GENERIC_SOURCES += test/debug/mips1.c
296 else
297 GENERIC_SOURCES += test/debug/mips1_skip.c
298 endif
299
300 ifeq ($(KARCH),ia64)
301 GENERIC_SOURCES += test/mm/purge1.c
302 else
303 GENERIC_SOURCES += test/mm/purge1_skip.c
304 endif
305
306 ifeq ($(CONFIG_FPU),y)
307 ifeq ($(KARCH),ia32)
308 TEST_FPU1 = y
309 TEST_SSE1 = y
310 GENERIC_SOURCES += test/fpu/fpu1_x86.c
311 endif
312
313 ifeq ($(KARCH),amd64)
314 TEST_FPU1 = y
315 TEST_SSE1 = y
316 GENERIC_SOURCES += test/fpu/fpu1_x86.c
317 endif
318
319 ifeq ($(KARCH),ia64)
320 TEST_FPU1 = y
321 GENERIC_SOURCES += test/fpu/fpu1_ia64.c
322 endif
323
324 ifeq ($(KARCH),mips32)
325 TEST_MIPS2 = y
326 endif
327 endif
328
329 ifneq ($(TEST_FPU1),y)
330 GENERIC_SOURCES += test/fpu/fpu1_skip.c
331 endif
332
333 ifeq ($(TEST_SSE1),y)
334 GENERIC_SOURCES += test/fpu/sse1.c
335 else
336 GENERIC_SOURCES += test/fpu/sse1_skip.c
337 endif
338
339 ifeq ($(TEST_MIPS2),y)
340 GENERIC_SOURCES += test/fpu/mips2.c
341 else
342 GENERIC_SOURCES += test/fpu/mips2_skip.c
343 endif
344
345endif
346
347GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
348ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
349GENARCH_OBJECTS := $(addsuffix .o,$(basename $(GENARCH_SOURCES)))
350
351ifeq ($(CONFIG_SYMTAB),y)
352 SYMTAB_OBJECTS := generic/src/debug/real_map.o
353else
354 SYMTAB_OBJECTS :=
355endif
356
357.PHONY: all
358
359all: $(BIN) $(DISASM)
360
361-include $(DEPEND)
362
363$(BIN): $(RAW)
364 $(OBJCOPY) -O $(BFD) $< $@
365
366$(DISASM): $(RAW)
367 $(OBJDUMP) -d $< > $@
368
369$(RAW): $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(SYMTAB_OBJECTS)
370 $(LD) -T $(LINK) $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS) -o $@ -Map $(MAP)
371
372$(LINK): $(LINK).in $(DEPEND)
373 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $< | grep -v "^\#" > $@
374
375%.o: %.S $(DEPEND)
376 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c $< -o $@
377
378%.o: %.s $(DEPEND)
379 $(AS) $(AFLAGS) $< -o $@
380
381#
382# The FPU tests are the only objects for which we allow the compiler to generate
383# FPU instructions.
384#
385test/fpu/%.o: test/fpu/%.c $(DEPEND)
386 $(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) -c $< -o $@
387ifeq ($(EXTRA_TOOL),stanse)
388 ../tools/jobfile.py $(JOB) $< $@ $(DEFS) $(CFLAGS) $(EXTRA_FLAGS)
389endif
390
391#
392# Ordinary objects.
393#
394%.o: %.c $(DEPEND)
395 $(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS) -c $< -o $@
396ifeq ($(EXTRA_TOOL),stanse)
397 ../tools/jobfile.py $(JOB) $< $@ $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS)
398endif
399
400$(REAL_MAP).o: $(REAL_MAP).bin
401 echo $(SYMTAB_SECTION)" .incbin \"$<\"" | $(AS) $(AFLAGS) -o $@
402
403$(REAL_MAP).bin: $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS)
404 echo $(SYMTAB_SECTION) | $(AS) $(AFLAGS) -o $(EMPTY_MAP)
405 $(LD) -T $(LINK) $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP) -o $@ -Map $(MAP_PREV)
406 $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > $(DUMP)
407 tools/genmap.py $(MAP_PREV) $(DUMP) $@
408
409 # Do it once again, this time to get correct even the symbols
410 # on architectures that have bss after symtab
411
412 echo $(SYMTAB_SECTION)" .incbin \"$@\"" | $(AS) $(AFLAGS) -o $(SIZEOK_MAP)
413 $(LD) -T $(LINK) $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP) -o $@ -Map $(MAP_PREV)
414 $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > $(DUMP)
415 tools/genmap.py $(MAP_PREV) $(DUMP) $@
416
417$(DEPEND): $(ARCH_INCLUDE) $(GENARCH_INCLUDE)
418 makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) > $@ 2> /dev/null
419 -[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
420
421$(ARCH_INCLUDE): arch/$(KARCH)/include/
422 ln -sfn ../../$< $@
423
424$(GENARCH_INCLUDE): genarch/include/
425 ln -sfn ../../$< $@
Note: See TracBrowser for help on using the repository browser.