source: mainline/kernel/Makefile@ a829a5b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a829a5b was f0d7bd9, checked in by Vojtech Horky <vojtechhorky@…>, 13 years ago

Create function for displaying —more— prompt

  • Property mode set to 100644
File size: 12.7 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
61ABI_INCLUDE = generic/include/abi
62ARCH_INCLUDE = generic/include/arch
63GENARCH_INCLUDE = generic/include/genarch
64
65GENMAP = tools/genmap.py
66JOBFILE = $(ROOT_PATH)/tools/jobfile.py
67
68LINK = arch/$(KARCH)/_link.ld
69EMPTY_MAP = generic/src/debug/empty_map.o
70SIZEOK_MAP = generic/src/debug/sizeok_map.o
71
72.PHONY: all clean
73
74all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(BIN) $(DISASM)
75 -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
76
77clean:
78 rm -f $(DEPEND) $(DEPEND_PREV) $(RAW) $(BIN) $(MAP) $(JOB) $(MAP_PREV) $(DISASM) $(DUMP) $(REAL_MAP).* $(ABI_INCLUDE) $(ARCH_INCLUDE) $(GENARCH_INCLUDE) arch/*/_link.ld arch/*/include/common.h
79 find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.o' -follow -exec rm \{\} \;
80
81## Common compiler flags
82#
83
84INCLUDES = generic/include
85
86ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
87 OPTIMIZATION = s
88else
89 OPTIMIZATION = 3
90endif
91
92DEFS = -DKERNEL -DRELEASE=$(RELEASE) "-DCOPYRIGHT=$(COPYRIGHT)" "-DNAME=$(NAME)" -D__$(BITS)_BITS__ -D__$(ENDIANESS)__
93
94GCC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
95 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
96 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
97 -std=gnu99 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
98 -Werror-implicit-function-declaration -Wwrite-strings \
99 -pipe
100
101ICC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
102 -ffreestanding -fno-builtin -nostdlib -nostdinc -Wall -Wmissing-prototypes \
103 -Werror-implicit-function-declaration -wd170
104
105CLANG_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
106 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
107 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
108 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
109 -Werror-implicit-function-declaration -Wwrite-strings \
110 -pipe -arch $(CLANG_ARCH)
111
112ifeq ($(CONFIG_DEBUG),y)
113 GCC_CFLAGS += -Werror
114 ICC_CFLAGS += -Werror
115endif
116
117ifeq ($(CONFIG_LTO),y)
118 GCC_CFLAGS += -flto
119endif
120
121ifeq ($(CONFIG_LINE_DEBUG),y)
122 GCC_CFLAGS += -g
123 ICC_CFLAGS += -g
124 CLANG_CFLAGS += -g
125endif
126
127#
128# Mind the mutual ordering with the inclusion of the arch Makefile.inc.
129# AFLAGS and LFLAGS must be initialized before the inclusion.
130#
131AFLAGS =
132LFLAGS = -n -T $(LINK) -M
133
134#
135# Mind the mutual ordering with the initialization of AFLAGS and LFLAGS.
136# The arch Makefile.inc must be included after the initialization.
137#
138-include arch/$(KARCH)/Makefile.inc
139-include genarch/Makefile.inc
140-include $(DEPEND)
141
142## The at-sign
143#
144# The $(ATSIGN) variable holds the ASCII character representing the at-sign
145# ('@') used in various $(AS) constructs (e.g. @progbits). On architectures that
146# don't use '@' for starting a comment, $(ATSIGN) is merely '@'. However, on
147# those that do use it for starting a comment (e.g. arm32), $(ATSIGN) must be
148# defined as the percentile-sign ('%') in the architecture-dependent
149# Makefile.inc.
150#
151
152ATSIGN ?= @
153
154## Cross-platform assembly to start a symtab.data section
155#
156
157SYMTAB_SECTION = ".section symtab.data, \"a\", $(ATSIGN)progbits;"
158
159## Compilation options
160#
161
162ifeq ($(COMPILER),gcc_native)
163 CFLAGS = $(GCC_CFLAGS)
164 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
165 INSTRUMENTATION = -finstrument-functions
166endif
167
168ifeq ($(COMPILER),gcc_cross)
169 CFLAGS = $(GCC_CFLAGS)
170 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
171 INSTRUMENTATION = -finstrument-functions
172endif
173
174ifeq ($(COMPILER),icc)
175 CFLAGS = $(ICC_CFLAGS)
176 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
177 INSTRUMENTATION =
178endif
179
180ifeq ($(COMPILER),clang)
181 CFLAGS = $(CLANG_CFLAGS)
182 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
183 INSTRUMENTATION =
184endif
185
186
187## Generic kernel sources
188#
189
190GENERIC_SOURCES = \
191 generic/src/adt/avl.c \
192 generic/src/adt/bitmap.c \
193 generic/src/adt/btree.c \
194 generic/src/adt/hash_table.c \
195 generic/src/adt/list.c \
196 generic/src/console/chardev.c \
197 generic/src/console/console.c \
198 generic/src/console/prompt.c \
199 generic/src/cpu/cpu.c \
200 generic/src/ddi/ddi.c \
201 generic/src/ddi/irq.c \
202 generic/src/ddi/device.c \
203 generic/src/debug/symtab.c \
204 generic/src/debug/stacktrace.c \
205 generic/src/debug/panic.c \
206 generic/src/debug/debug.c \
207 generic/src/interrupt/interrupt.c \
208 generic/src/main/main.c \
209 generic/src/main/kinit.c \
210 generic/src/main/uinit.c \
211 generic/src/main/version.c \
212 generic/src/main/shutdown.c \
213 generic/src/proc/program.c \
214 generic/src/proc/scheduler.c \
215 generic/src/proc/thread.c \
216 generic/src/proc/task.c \
217 generic/src/proc/the.c \
218 generic/src/syscall/syscall.c \
219 generic/src/syscall/copy.c \
220 generic/src/mm/km.c \
221 generic/src/mm/reserve.c \
222 generic/src/mm/buddy.c \
223 generic/src/mm/frame.c \
224 generic/src/mm/page.c \
225 generic/src/mm/tlb.c \
226 generic/src/mm/as.c \
227 generic/src/mm/backend_anon.c \
228 generic/src/mm/backend_elf.c \
229 generic/src/mm/backend_phys.c \
230 generic/src/mm/slab.c \
231 generic/src/lib/func.c \
232 generic/src/lib/memstr.c \
233 generic/src/lib/memfnc.c \
234 generic/src/lib/sort.c \
235 generic/src/lib/str.c \
236 generic/src/lib/elf.c \
237 generic/src/lib/ra.c \
238 generic/src/lib/rd.c \
239 generic/src/printf/printf_core.c \
240 generic/src/printf/printf.c \
241 generic/src/printf/snprintf.c \
242 generic/src/printf/vprintf.c \
243 generic/src/printf/vsnprintf.c \
244 generic/src/time/clock.c \
245 generic/src/time/timeout.c \
246 generic/src/time/delay.c \
247 generic/src/preempt/preemption.c \
248 generic/src/synch/spinlock.c \
249 generic/src/synch/condvar.c \
250 generic/src/synch/mutex.c \
251 generic/src/synch/semaphore.c \
252 generic/src/synch/smc.c \
253 generic/src/synch/waitq.c \
254 generic/src/synch/futex.c \
255 generic/src/smp/ipi.c \
256 generic/src/smp/smp.c \
257 generic/src/ipc/ipc.c \
258 generic/src/ipc/sysipc.c \
259 generic/src/ipc/ipcrsc.c \
260 generic/src/ipc/irq.c \
261 generic/src/ipc/event.c \
262 generic/src/security/cap.c \
263 generic/src/sysinfo/sysinfo.c \
264 generic/src/sysinfo/stats.c
265
266## Kernel console support
267#
268
269ifeq ($(CONFIG_KCONSOLE),y)
270GENERIC_SOURCES += \
271 generic/src/console/kconsole.c \
272 generic/src/console/cmd.c
273endif
274
275## Udebug interface sources
276#
277
278ifeq ($(CONFIG_UDEBUG),y)
279GENERIC_SOURCES += \
280 generic/src/ipc/kbox.c \
281 generic/src/udebug/udebug.c \
282 generic/src/udebug/udebug_ops.c \
283 generic/src/udebug/udebug_ipc.c
284endif
285
286## Test sources
287#
288
289ifeq ($(CONFIG_TEST),y)
290 CFLAGS += -Itest/
291 GENERIC_SOURCES += \
292 test/test.c \
293 test/atomic/atomic1.c \
294 test/btree/btree1.c \
295 test/avltree/avltree1.c \
296 test/fault/fault1.c \
297 test/mm/falloc1.c \
298 test/mm/falloc2.c \
299 test/mm/mapping1.c \
300 test/mm/slab1.c \
301 test/mm/slab2.c \
302 test/synch/semaphore1.c \
303 test/synch/semaphore2.c \
304 test/print/print1.c \
305 test/print/print2.c \
306 test/print/print3.c \
307 test/print/print4.c \
308 test/print/print5.c \
309 test/thread/thread1.c
310
311 ifeq ($(KARCH),mips32)
312 GENERIC_SOURCES += test/debug/mips1.c
313 else
314 GENERIC_SOURCES += test/debug/mips1_skip.c
315 endif
316
317 ifeq ($(KARCH),ia64)
318 GENERIC_SOURCES += test/mm/purge1.c
319 else
320 GENERIC_SOURCES += test/mm/purge1_skip.c
321 endif
322
323endif
324
325## Sources where instrumentation is enabled
326#
327
328ifeq ($(CONFIG_TRACE),y)
329 INSTRUMENTED_SOURCES = \
330 generic/src/adt/btree.c \
331 generic/src/cpu/cpu.c \
332 generic/src/ddi/ddi.c \
333 generic/src/interrupt/interrupt.c \
334 generic/src/main/main.c \
335 generic/src/main/kinit.c \
336 generic/src/proc/the.c \
337 generic/src/mm/frame.c \
338 generic/src/mm/page.c \
339 generic/src/mm/tlb.c \
340 generic/src/mm/as.c \
341 generic/src/mm/slab.c \
342 generic/src/sysinfo/sysinfo.c \
343 generic/src/console/kconsole.c
344else
345 INSTRUMENTED_SOURCES =
346endif
347
348GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
349ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
350GENARCH_OBJECTS := $(addsuffix .o,$(basename $(GENARCH_SOURCES)))
351
352LFLAGS_LTO := $(addprefix -Xlinker ,$(LFLAGS))
353
354ifeq ($(CONFIG_SYMTAB),y)
355 SYMTAB_OBJECTS := generic/src/debug/real_map.o
356else
357 SYMTAB_OBJECTS :=
358endif
359
360$(BIN): $(RAW)
361 $(OBJCOPY) -O $(BFD) $< $@
362
363$(DISASM): $(RAW)
364ifeq ($(CONFIG_LINE_DEBUG),y)
365 $(OBJDUMP) -d -S $< > $@
366else
367 $(OBJDUMP) -d $< > $@
368endif
369
370$(RAW): $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(SYMTAB_OBJECTS)
371ifeq ($(CONFIG_LTO),y)
372 $(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
373else
374 $(LD) $(LFLAGS) -Map $(MAP) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
375endif
376ifeq ($(CONFIG_STRIP_BINARIES),y)
377 $(STRIP) $(RAW)
378endif
379
380$(LINK): $(LINK).in $(DEPEND)
381 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $< | grep -v "^\#" > $@
382
383%.o: %.S $(DEPEND)
384 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c -o $@ $<
385ifeq ($(PRECHECK),y)
386 $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(GCC_CFLAGS) -D__ASM__
387endif
388
389%.o: %.s $(DEPEND)
390 $(AS) $(AFLAGS) -o $@ $<
391ifeq ($(PRECHECK),y)
392 $(JOBFILE) $(JOB) $< $@ as asm $(DEFS) $(CFLAGS) $(EXTRA_FLAGS)
393endif
394
395%.o: %.c $(DEPEND)
396 $(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS) $(if $(findstring $<,$(INSTRUMENTED_SOURCES)),$(INSTRUMENTATION)) -c -o $@ $<
397ifeq ($(PRECHECK),y)
398 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS)
399endif
400
401$(REAL_MAP).o: $(REAL_MAP).bin
402 echo $(SYMTAB_SECTION)" .incbin \"$<\"" | $(AS) $(AFLAGS) -o $@
403
404$(REAL_MAP).bin: $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS)
405 echo $(SYMTAB_SECTION) | $(AS) $(AFLAGS) -o $(EMPTY_MAP)
406ifeq ($(CONFIG_LTO),y)
407 $(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP_PREV) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
408else
409 $(LD) $(LFLAGS) -Map $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
410endif
411 $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > $(DUMP)
412 $(GENMAP) $(MAP_PREV) $(DUMP) $@
413
414 # Do it once again, this time to get correct even the symbols
415 # on architectures that have bss after symtab
416
417 echo $(SYMTAB_SECTION)" .incbin \"$@\"" | $(AS) $(AFLAGS) -o $(SIZEOK_MAP)
418ifeq ($(CONFIG_LTO),y)
419 $(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP_PREV) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
420else
421 $(LD) $(LFLAGS) -Map $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
422endif
423 $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > $(DUMP)
424 $(GENMAP) $(MAP_PREV) $(DUMP) $@
425
426$(DEPEND): $(ABI_INCLUDE) $(ARCH_INCLUDE) $(GENARCH_INCLUDE) $(COMMON_HEADER_ARCH)
427 makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) > $@ 2> /dev/null
428 -[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
429
430$(ABI_INCLUDE): ../abi/include/
431 ln -sfn ../../$< $@
432
433$(ARCH_INCLUDE): arch/$(KARCH)/include/
434 ln -sfn ../../$< $@
435
436$(GENARCH_INCLUDE): genarch/include/
437 ln -sfn ../../$< $@
438
439$(COMMON_HEADER_ARCH): $(COMMON_HEADER)
440 ln -sfn ../../../$< $@
Note: See TracBrowser for help on using the repository browser.