source: mainline/kernel/Makefile@ 6ecf5b8

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

Prevent compile-time symlinks in kernel

So far, architecture specific headers for kernel were in
kernel/arch/$ARCH/include directory.
From kernel sources, they were referenced as arch/header.h.

For example, file kernel/arch/$ARCH/include/whatever.h
was included with <arch/whatever.h>.

To allow that, a symbolic link with name `arch' pointing
to the correct `include/' was created during compilation.

This change adds one arch/ directory and instead of
creating a symbolic link for each compilation, -I flag
was added to the compiler (the header mentioned above would
now reside in kernel/arch/$ARCH/include/arch/whatever.h).

The same goes for genarch/ includes.

This change would be followed by similar changes in userspace
and ABI. To overall goal is to simplify job of documenation
generators or IDEs that might have problems with the dynamically
created symbolic links.

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