libext4: every allocation group contains the number of free blocks, use this informat...
[helenos.git] / kernel / Makefile
blob6ea19ecf173632751f9b5741e799338ca6ab5444
2 # Copyright (c) 2005 Martin Decky
3 # All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
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.
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.
29 ## Configuration
32 ROOT_PATH = ..
34 VERSION_DEF = $(ROOT_PATH)/version
36 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
37 COMMON_HEADER = $(ROOT_PATH)/common.h
38 COMMON_HEADER_ARCH = arch/$(KARCH)/include/arch/common.h
40 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
41 CONFIG_HEADER = $(ROOT_PATH)/config.h
43 -include $(VERSION_DEF)
44 -include $(COMMON_MAKEFILE)
45 -include $(CONFIG_MAKEFILE)
47 ## Common names
50 DEPEND = Makefile.depend
51 DEPEND_PREV = $(DEPEND).prev
52 RAW = kernel.raw
53 BIN = kernel.bin
54 MAP = kernel.map
55 JOB = kernel.job
56 MAP_PREV = $(MAP).prev
57 DISASM = kernel.disasm
58 DUMP = kernel.dump
59 REAL_MAP = generic/src/debug/real_map
61 GENMAP = tools/genmap.py
62 JOBFILE = $(ROOT_PATH)/tools/jobfile.py
64 LINK = arch/$(KARCH)/_link.ld
65 EMPTY_MAP = generic/src/debug/empty_map.o
66 SIZEOK_MAP = generic/src/debug/sizeok_map.o
68 .PHONY: all clean
70 all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(BIN) $(DISASM)
71 -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
73 clean:
74 rm -f $(DEPEND) $(DEPEND_PREV) $(RAW) $(BIN) $(MAP) $(JOB) $(MAP_PREV) $(DISASM) $(DUMP) $(REAL_MAP).* arch/*/_link.ld arch/*/include/arch/common.h
75 find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.o' -follow -exec rm \{\} \;
77 ## Common compiler flags
80 INCLUDES = generic/include genarch/include arch/$(KARCH)/include ../abi/include
81 INCLUDES_FLAGS = $(addprefix -I,$(INCLUDES))
83 ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
84 OPTIMIZATION = s
85 else
86 OPTIMIZATION = 3
87 endif
89 DEFS = -DKERNEL -DRELEASE=$(RELEASE) "-DCOPYRIGHT=$(COPYRIGHT)" "-DNAME=$(NAME)" -D__$(BITS)_BITS__ -D__$(ENDIANESS)__
91 GCC_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
92 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
93 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
94 -std=gnu99 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
95 -Werror-implicit-function-declaration -Wwrite-strings \
96 -pipe
98 ICC_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
99 -ffreestanding -fno-builtin -nostdlib -nostdinc -Wall -Wmissing-prototypes \
100 -Werror-implicit-function-declaration -wd170
102 # clang does not support following options but I am not sure whether
103 # something won't break because of that:
104 # -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) -finput-charset=UTF-8
105 CLANG_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
106 -ffreestanding -fno-builtin -nostdlib -nostdinc \
107 -Wall -Werror -Wextra -Wno-unused-parameter -Wmissing-prototypes \
108 -Werror-implicit-function-declaration -Wwrite-strings \
109 -integrated-as \
110 -pipe -target $(CLANG_TARGET)
112 ifeq ($(CONFIG_DEBUG),y)
113 GCC_CFLAGS += -Werror
114 ICC_CFLAGS += -Werror
115 endif
117 ifeq ($(CONFIG_LTO),y)
118 GCC_CFLAGS += -flto
119 endif
121 ifeq ($(CONFIG_LINE_DEBUG),y)
122 GCC_CFLAGS += -g
123 ICC_CFLAGS += -g
124 CLANG_CFLAGS += -g
125 endif
128 # Mind the mutual ordering with the inclusion of the arch Makefile.inc.
129 # AFLAGS and LFLAGS must be initialized before the inclusion.
131 AFLAGS =
132 LFLAGS = -n -T $(LINK) -M
135 # Mind the mutual ordering with the initialization of AFLAGS and LFLAGS.
136 # The arch Makefile.inc must be included after the initialization.
138 -include arch/$(KARCH)/Makefile.inc
139 -include genarch/Makefile.inc
140 -include $(DEPEND)
142 ## The at-sign
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.
152 ATSIGN ?= @
154 ## Cross-platform assembly to start a symtab.data section
157 SYMTAB_SECTION = ".section symtab.data, \"a\", $(ATSIGN)progbits;"
159 ## Compilation options
162 ifeq ($(COMPILER),gcc_native)
163 CFLAGS = $(GCC_CFLAGS)
164 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
165 INSTRUMENTATION = -finstrument-functions
166 endif
168 ifeq ($(COMPILER),gcc_cross)
169 CFLAGS = $(GCC_CFLAGS)
170 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
171 INSTRUMENTATION = -finstrument-functions
172 endif
174 ifeq ($(COMPILER),gcc_helenos)
175 CFLAGS = $(GCC_CFLAGS)
176 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
177 INSTRUMENTATION = -finstrument-functions
178 endif
180 ifeq ($(COMPILER),icc)
181 CFLAGS = $(ICC_CFLAGS)
182 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
183 INSTRUMENTATION =
184 endif
186 ifeq ($(COMPILER),clang)
187 CFLAGS = $(CLANG_CFLAGS)
188 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
189 INSTRUMENTATION =
190 endif
193 ## Generic kernel sources
196 GENERIC_SOURCES = \
197 generic/src/adt/avl.c \
198 generic/src/adt/bitmap.c \
199 generic/src/adt/btree.c \
200 generic/src/adt/hash_table.c \
201 generic/src/adt/list.c \
202 generic/src/console/chardev.c \
203 generic/src/console/console.c \
204 generic/src/console/prompt.c \
205 generic/src/cpu/cpu.c \
206 generic/src/ddi/ddi.c \
207 generic/src/ddi/irq.c \
208 generic/src/ddi/device.c \
209 generic/src/debug/symtab.c \
210 generic/src/debug/stacktrace.c \
211 generic/src/debug/panic.c \
212 generic/src/debug/debug.c \
213 generic/src/interrupt/interrupt.c \
214 generic/src/log/log.c \
215 generic/src/main/main.c \
216 generic/src/main/kinit.c \
217 generic/src/main/uinit.c \
218 generic/src/main/version.c \
219 generic/src/main/shutdown.c \
220 generic/src/proc/program.c \
221 generic/src/proc/scheduler.c \
222 generic/src/proc/thread.c \
223 generic/src/proc/task.c \
224 generic/src/proc/the.c \
225 generic/src/syscall/syscall.c \
226 generic/src/syscall/copy.c \
227 generic/src/mm/km.c \
228 generic/src/mm/reserve.c \
229 generic/src/mm/frame.c \
230 generic/src/mm/page.c \
231 generic/src/mm/tlb.c \
232 generic/src/mm/as.c \
233 generic/src/mm/backend_anon.c \
234 generic/src/mm/backend_elf.c \
235 generic/src/mm/backend_phys.c \
236 generic/src/mm/slab.c \
237 generic/src/lib/func.c \
238 generic/src/lib/memstr.c \
239 generic/src/lib/memfnc.c \
240 generic/src/lib/sort.c \
241 generic/src/lib/str.c \
242 generic/src/lib/elf.c \
243 generic/src/lib/ra.c \
244 generic/src/lib/rd.c \
245 generic/src/printf/printf_core.c \
246 generic/src/printf/printf.c \
247 generic/src/printf/snprintf.c \
248 generic/src/printf/vprintf.c \
249 generic/src/printf/vsnprintf.c \
250 generic/src/time/clock.c \
251 generic/src/time/timeout.c \
252 generic/src/time/delay.c \
253 generic/src/preempt/preemption.c \
254 generic/src/synch/spinlock.c \
255 generic/src/synch/condvar.c \
256 generic/src/synch/mutex.c \
257 generic/src/synch/semaphore.c \
258 generic/src/synch/smc.c \
259 generic/src/synch/waitq.c \
260 generic/src/synch/futex.c \
261 generic/src/smp/ipi.c \
262 generic/src/smp/smp.c \
263 generic/src/ipc/ipc.c \
264 generic/src/ipc/sysipc.c \
265 generic/src/ipc/sysipc_ops.c \
266 generic/src/ipc/ops/clnestab.c \
267 generic/src/ipc/ops/conctmeto.c \
268 generic/src/ipc/ops/concttome.c \
269 generic/src/ipc/ops/connclone.c \
270 generic/src/ipc/ops/dataread.c \
271 generic/src/ipc/ops/datawrite.c \
272 generic/src/ipc/ops/debug.c \
273 generic/src/ipc/ops/sharein.c \
274 generic/src/ipc/ops/shareout.c \
275 generic/src/ipc/ops/stchngath.c \
276 generic/src/ipc/ipcrsc.c \
277 generic/src/ipc/irq.c \
278 generic/src/ipc/event.c \
279 generic/src/security/cap.c \
280 generic/src/sysinfo/sysinfo.c \
281 generic/src/sysinfo/stats.c
283 ## Kernel console support
286 ifeq ($(CONFIG_KCONSOLE),y)
287 GENERIC_SOURCES += \
288 generic/src/console/kconsole.c \
289 generic/src/console/cmd.c
290 endif
292 ## Udebug interface sources
295 ifeq ($(CONFIG_UDEBUG),y)
296 GENERIC_SOURCES += \
297 generic/src/ipc/kbox.c \
298 generic/src/udebug/udebug.c \
299 generic/src/udebug/udebug_ops.c \
300 generic/src/udebug/udebug_ipc.c
301 endif
303 ## Test sources
306 ifeq ($(CONFIG_TEST),y)
307 CFLAGS += -Itest/
308 GENERIC_SOURCES += \
309 test/test.c \
310 test/atomic/atomic1.c \
311 test/btree/btree1.c \
312 test/avltree/avltree1.c \
313 test/fault/fault1.c \
314 test/mm/falloc1.c \
315 test/mm/falloc2.c \
316 test/mm/mapping1.c \
317 test/mm/slab1.c \
318 test/mm/slab2.c \
319 test/synch/semaphore1.c \
320 test/synch/semaphore2.c \
321 test/print/print1.c \
322 test/print/print2.c \
323 test/print/print3.c \
324 test/print/print4.c \
325 test/print/print5.c \
326 test/thread/thread1.c
328 ifeq ($(KARCH),mips32)
329 GENERIC_SOURCES += test/debug/mips1.c
330 else
331 GENERIC_SOURCES += test/debug/mips1_skip.c
332 endif
334 ifeq ($(KARCH),ia64)
335 GENERIC_SOURCES += test/mm/purge1.c
336 else
337 GENERIC_SOURCES += test/mm/purge1_skip.c
338 endif
340 endif
342 ## Sources where instrumentation is enabled
345 ifeq ($(CONFIG_TRACE),y)
346 INSTRUMENTED_SOURCES = \
347 generic/src/adt/btree.c \
348 generic/src/cpu/cpu.c \
349 generic/src/ddi/ddi.c \
350 generic/src/interrupt/interrupt.c \
351 generic/src/main/main.c \
352 generic/src/main/kinit.c \
353 generic/src/proc/the.c \
354 generic/src/mm/frame.c \
355 generic/src/mm/page.c \
356 generic/src/mm/tlb.c \
357 generic/src/mm/as.c \
358 generic/src/mm/slab.c \
359 generic/src/sysinfo/sysinfo.c \
360 generic/src/console/kconsole.c
361 else
362 INSTRUMENTED_SOURCES =
363 endif
365 GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
366 ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
367 GENARCH_OBJECTS := $(addsuffix .o,$(basename $(GENARCH_SOURCES)))
369 LFLAGS_LTO := $(addprefix -Xlinker ,$(LFLAGS))
371 ifeq ($(CONFIG_SYMTAB),y)
372 SYMTAB_OBJECTS := generic/src/debug/real_map.o
373 else
374 SYMTAB_OBJECTS :=
375 endif
377 $(BIN): $(RAW)
378 $(OBJCOPY) -O $(BFD) $< $@
380 $(DISASM): $(RAW)
381 ifeq ($(CONFIG_LINE_DEBUG),y)
382 $(OBJDUMP) -d -S $< > $@
383 else
384 $(OBJDUMP) -d $< > $@
385 endif
387 $(RAW): $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(SYMTAB_OBJECTS)
388 ifeq ($(CONFIG_LTO),y)
389 $(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
390 else
391 $(LD) $(LFLAGS) -Map $(MAP) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
392 endif
393 ifeq ($(CONFIG_STRIP_BINARIES),y)
394 $(STRIP) $(RAW)
395 endif
397 $(LINK): $(LINK).in $(DEPEND)
398 $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $< | grep -v "^\#" > $@
400 %.o: %.S $(DEPEND)
401 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c -o $@ $<
402 ifeq ($(PRECHECK),y)
403 $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(GCC_CFLAGS) -D__ASM__
404 endif
406 %.o: %.s $(DEPEND)
407 $(AS) $(AFLAGS) -o $@ $<
408 ifeq ($(PRECHECK),y)
409 $(JOBFILE) $(JOB) $< $@ as asm $(DEFS) $(CFLAGS) $(EXTRA_FLAGS)
410 endif
412 %.o: %.c $(DEPEND)
413 $(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS) $(if $(findstring $<,$(INSTRUMENTED_SOURCES)),$(INSTRUMENTATION)) -c -o $@ $<
414 ifeq ($(PRECHECK),y)
415 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS)
416 endif
418 $(REAL_MAP).o: $(REAL_MAP).bin
419 echo $(SYMTAB_SECTION)" .incbin \"$<\"" | $(AS) $(AFLAGS) -o $@
421 $(REAL_MAP).bin: $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS)
422 echo $(SYMTAB_SECTION) | $(AS) $(AFLAGS) -o $(EMPTY_MAP)
423 ifeq ($(CONFIG_LTO),y)
424 $(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP_PREV) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
425 else
426 $(LD) $(LFLAGS) -Map $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
427 endif
428 $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > $(DUMP)
429 $(GENMAP) $(MAP_PREV) $(DUMP) $@
431 # Do it once again, this time to get correct even the symbols
432 # on architectures that have bss after symtab
434 echo $(SYMTAB_SECTION)" .incbin \"$@\"" | $(AS) $(AFLAGS) -o $(SIZEOK_MAP)
435 ifeq ($(CONFIG_LTO),y)
436 $(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP_PREV) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
437 else
438 $(LD) $(LFLAGS) -Map $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
439 endif
440 $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > $(DUMP)
441 $(GENMAP) $(MAP_PREV) $(DUMP) $@
443 $(DEPEND): $(COMMON_HEADER_ARCH)
444 makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) > $@ 2> /dev/null
445 -[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
447 $(COMMON_HEADER_ARCH): $(COMMON_HEADER)
448 ln -sfn ../../../../$< $@