source: mainline/kernel/Makefile@ 938f227

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

add indentation

  • Property mode set to 100644
File size: 11.9 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## Configuration
30#
31
32ROOT_PATH = ..
33
34VERSION_DEF = $(ROOT_PATH)/version
35
36COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
37COMMON_HEADER = $(ROOT_PATH)/common.h
38COMMON_HEADER_ARCH = arch/$(KARCH)/include/common.h
39
40CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
41CONFIG_HEADER = $(ROOT_PATH)/config.h
42
43-include $(VERSION_DEF)
44-include $(COMMON_MAKEFILE)
45-include $(CONFIG_MAKEFILE)
46
47## Common names
48#
49
50DEPEND = Makefile.depend
51DEPEND_PREV = $(DEPEND).prev
52RAW = kernel.raw
53BIN = kernel.bin
54MAP = kernel.map
55JOB = kernel.job
56MAP_PREV = $(MAP).prev
57DISASM = kernel.disasm
58DUMP = kernel.dump
59REAL_MAP = generic/src/debug/real_map
60
61ARCH_INCLUDE = generic/include/arch
62GENARCH_INCLUDE = generic/include/genarch
63
64GENMAP = tools/genmap.py
65JOBFILE = $(ROOT_PATH)/tools/jobfile.py
66
67LINK = arch/$(KARCH)/_link.ld
68EMPTY_MAP = generic/src/debug/empty_map.o
69SIZEOK_MAP = generic/src/debug/sizeok_map.o
70
71.PHONY: all clean
72
73all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(BIN) $(DISASM)
74 -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
75
76clean:
77 rm -f $(DEPEND) $(DEPEND_PREV) $(RAW) $(BIN) $(MAP) $(JOB) $(MAP_PREV) $(DISASM) $(DUMP) $(REAL_MAP).* $(ARCH_INCLUDE) $(GENARCH_INCLUDE) arch/*/_link.ld arch/*/include/common.h
78 find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.o' -follow -exec rm \{\} \;
79
80## Common compiler flags
81#
82
83INCLUDES = generic/include
84
85ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
86 OPTIMIZATION = s
87else
88 OPTIMIZATION = 3
89endif
90
91DEFS = -DKERNEL -DRELEASE=$(RELEASE) "-DNAME=$(NAME)" -D__$(BITS)_BITS__ -D__$(ENDIANESS)__
92
93GCC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
94 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
95 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
96 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
97 -Werror-implicit-function-declaration -Wwrite-strings \
98 -pipe
99
100ICC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
101 -ffreestanding -fno-builtin -nostdlib -nostdinc -Wall -Wmissing-prototypes \
102 -Werror-implicit-function-declaration -wd170
103
104SUNCC_CFLAGS = -I$(INCLUDES) -xO$(OPTIMIZATION) \
105 -xnolib -xc99=all -features=extensions \
106 -erroff=E_ZERO_SIZED_STRUCT_UNION
107
108CLANG_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
109 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
110 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
111 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
112 -Werror-implicit-function-declaration -Wwrite-strings \
113 -pipe -arch $(CLANG_ARCH)
114
115ifeq ($(CONFIG_DEBUG),y)
116 GCC_CFLAGS += -Werror
117 ICC_CFLAGS += -Werror
118endif
119
120-include arch/$(KARCH)/Makefile.inc
121-include genarch/Makefile.inc
122-include $(DEPEND)
123
124## The at-sign
125#
126# The $(ATSIGN) variable holds the ASCII character representing the at-sign
127# ('@') used in various $(AS) constructs (e.g. @progbits). On architectures that
128# don't use '@' for starting a comment, $(ATSIGN) is merely '@'. However, on
129# those that do use it for starting a comment (e.g. arm32), $(ATSIGN) must be
130# defined as the percentile-sign ('%') in the architecture-dependent
131# Makefile.inc.
132#
133
134ATSIGN ?= @
135
136## Cross-platform assembly to start a symtab.data section
137#
138
139SYMTAB_SECTION = ".section symtab.data, \"a\", $(ATSIGN)progbits;"
140
141## Compilation options
142#
143
144ifeq ($(COMPILER),gcc_native)
145 CFLAGS = $(GCC_CFLAGS)
146 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
147endif
148
149ifeq ($(COMPILER),gcc_cross)
150 CFLAGS = $(GCC_CFLAGS)
151 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
152endif
153
154ifeq ($(COMPILER),icc)
155 CFLAGS = $(ICC_CFLAGS)
156 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
157endif
158
159ifeq ($(COMPILER),suncc)
160 CFLAGS = $(SUNCC_CFLAGS)
161 DEFS += $(CONFIG_DEFS)
162 DEPEND_DEFS = $(DEFS)
163endif
164
165ifeq ($(COMPILER),clang)
166 CFLAGS = $(CLANG_CFLAGS)
167 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
168endif
169
170## Generic kernel sources
171#
172
173GENERIC_SOURCES = \
174 generic/src/adt/avl.c \
175 generic/src/adt/bitmap.c \
176 generic/src/adt/btree.c \
177 generic/src/adt/hash_table.c \
178 generic/src/adt/list.c \
179 generic/src/console/chardev.c \
180 generic/src/console/console.c \
181 generic/src/cpu/cpu.c \
182 generic/src/ddi/ddi.c \
183 generic/src/ddi/irq.c \
184 generic/src/ddi/device.c \
185 generic/src/debug/symtab.c \
186 generic/src/debug/stacktrace.c \
187 generic/src/interrupt/interrupt.c \
188 generic/src/main/main.c \
189 generic/src/main/kinit.c \
190 generic/src/main/uinit.c \
191 generic/src/main/version.c \
192 generic/src/main/shutdown.c \
193 generic/src/proc/program.c \
194 generic/src/proc/scheduler.c \
195 generic/src/proc/thread.c \
196 generic/src/proc/task.c \
197 generic/src/proc/the.c \
198 generic/src/proc/tasklet.c \
199 generic/src/syscall/syscall.c \
200 generic/src/syscall/copy.c \
201 generic/src/mm/buddy.c \
202 generic/src/mm/frame.c \
203 generic/src/mm/page.c \
204 generic/src/mm/tlb.c \
205 generic/src/mm/as.c \
206 generic/src/mm/backend_anon.c \
207 generic/src/mm/backend_elf.c \
208 generic/src/mm/backend_phys.c \
209 generic/src/mm/slab.c \
210 generic/src/lib/func.c \
211 generic/src/lib/memstr.c \
212 generic/src/lib/sort.c \
213 generic/src/lib/str.c \
214 generic/src/lib/elf.c \
215 generic/src/lib/rd.c \
216 generic/src/printf/printf_core.c \
217 generic/src/printf/printf.c \
218 generic/src/printf/snprintf.c \
219 generic/src/printf/vprintf.c \
220 generic/src/printf/vsnprintf.c \
221 generic/src/time/clock.c \
222 generic/src/time/timeout.c \
223 generic/src/time/delay.c \
224 generic/src/preempt/preemption.c \
225 generic/src/synch/spinlock.c \
226 generic/src/synch/condvar.c \
227 generic/src/synch/rwlock.c \
228 generic/src/synch/mutex.c \
229 generic/src/synch/semaphore.c \
230 generic/src/synch/smc.c \
231 generic/src/synch/waitq.c \
232 generic/src/synch/futex.c \
233 generic/src/smp/ipi.c \
234 generic/src/smp/smp.c \
235 generic/src/ipc/ipc.c \
236 generic/src/ipc/sysipc.c \
237 generic/src/ipc/ipcrsc.c \
238 generic/src/ipc/irq.c \
239 generic/src/ipc/event.c \
240 generic/src/security/cap.c \
241 generic/src/sysinfo/sysinfo.c \
242 generic/src/sysinfo/stats.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
293 ifeq ($(KARCH),mips32)
294 GENERIC_SOURCES += test/debug/mips1.c
295 else
296 GENERIC_SOURCES += test/debug/mips1_skip.c
297 endif
298
299 ifeq ($(KARCH),ia64)
300 GENERIC_SOURCES += test/mm/purge1.c
301 else
302 GENERIC_SOURCES += test/mm/purge1_skip.c
303 endif
304
305 ifeq ($(CONFIG_FPU),y)
306 ifeq ($(KARCH),ia32)
307 TEST_FPU1 = y
308 TEST_SSE1 = y
309 GENERIC_SOURCES += test/fpu/fpu1_x86.c
310 endif
311
312 ifeq ($(KARCH),amd64)
313 TEST_FPU1 = y
314 TEST_SSE1 = y
315 GENERIC_SOURCES += test/fpu/fpu1_x86.c
316 endif
317
318 ifeq ($(KARCH),ia64)
319 TEST_FPU1 = y
320 GENERIC_SOURCES += test/fpu/fpu1_ia64.c
321 endif
322
323 ifeq ($(KARCH),mips32)
324 TEST_MIPS2 = y
325 endif
326 endif
327
328 ifneq ($(TEST_FPU1),y)
329 GENERIC_SOURCES += test/fpu/fpu1_skip.c
330 endif
331
332 ifeq ($(TEST_SSE1),y)
333 GENERIC_SOURCES += test/fpu/sse1.c
334 else
335 GENERIC_SOURCES += test/fpu/sse1_skip.c
336 endif
337
338 ifeq ($(TEST_MIPS2),y)
339 GENERIC_SOURCES += test/fpu/mips2.c
340 else
341 GENERIC_SOURCES += test/fpu/mips2_skip.c
342 endif
343
344endif
345
346GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
347ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
348GENARCH_OBJECTS := $(addsuffix .o,$(basename $(GENARCH_SOURCES)))
349
350ifeq ($(CONFIG_SYMTAB),y)
351 SYMTAB_OBJECTS := generic/src/debug/real_map.o
352else
353 SYMTAB_OBJECTS :=
354endif
355
356$(BIN): $(RAW)
357 $(OBJCOPY) -O $(BFD) $< $@
358
359$(DISASM): $(RAW)
360 $(OBJDUMP) -d $< > $@
361
362$(RAW): $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(SYMTAB_OBJECTS)
363 $(LD) -N $(LFLAGS) -T $(LINK) -M -Map $(MAP) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
364ifeq ($(CONFIG_STRIP_BINARIES),y)
365 $(STRIP) $(RAW)
366endif
367
368$(LINK): $(LINK).in $(DEPEND)
369 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $< | grep -v "^\#" > $@
370
371%.o: %.S $(DEPEND)
372 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c $< -o $@
373ifeq ($(PRECHECK),y)
374 $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(GCC_CFLAGS) -D__ASM__
375endif
376
377%.o: %.s $(DEPEND)
378 $(AS) $(AFLAGS) -o $@ $<
379ifeq ($(PRECHECK),y)
380 $(JOBFILE) $(JOB) $< $@ as asm $(DEFS) $(CFLAGS) $(EXTRA_FLAGS)
381endif
382
383#
384# The FPU tests are the only objects for which we allow the compiler to generate
385# FPU instructions.
386#
387
388test/fpu/%.o: test/fpu/%.c $(DEPEND)
389 $(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) -c $< -o $@
390ifeq ($(PRECHECK),y)
391 $(JOBFILE) $(JOB) $< $@ cc test $(DEFS) $(CFLAGS) $(EXTRA_FLAGS)
392endif
393
394#
395# Ordinary objects.
396#
397
398%.o: %.c $(DEPEND)
399 $(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS) -c $< -o $@
400ifeq ($(PRECHECK),y)
401 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS)
402endif
403
404$(REAL_MAP).o: $(REAL_MAP).bin
405 echo $(SYMTAB_SECTION)" .incbin \"$<\"" | $(AS) $(AFLAGS) -o $@
406
407$(REAL_MAP).bin: $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS)
408 echo $(SYMTAB_SECTION) | $(AS) $(AFLAGS) -o $(EMPTY_MAP)
409 $(LD) -N $(LFLAGS) -T $(LINK) -M -Map $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
410 $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > $(DUMP)
411 $(GENMAP) $(MAP_PREV) $(DUMP) $@
412
413 # Do it once again, this time to get correct even the symbols
414 # on architectures that have bss after symtab
415
416 echo $(SYMTAB_SECTION)" .incbin \"$@\"" | $(AS) $(AFLAGS) -o $(SIZEOK_MAP)
417 $(LD) -N $(LFLAGS) -T $(LINK) -M -Map $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
418 $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > $(DUMP)
419 $(GENMAP) $(MAP_PREV) $(DUMP) $@
420
421$(DEPEND): $(ARCH_INCLUDE) $(GENARCH_INCLUDE) $(COMMON_HEADER_ARCH)
422 makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) > $@ 2> /dev/null
423 -[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
424
425$(ARCH_INCLUDE): arch/$(KARCH)/include/
426 ln -sfn ../../$< $@
427
428$(GENARCH_INCLUDE): genarch/include/
429 ln -sfn ../../$< $@
430
431$(COMMON_HEADER_ARCH): $(COMMON_HEADER)
432 ln -sfn ../../../$< $@
Note: See TracBrowser for help on using the repository browser.