Merge branch 'master' of github.com:Minep/lunaix-os
[lunaix-os.git] / lunaix-os / kernel.mk
1 include os.mkinc
2 include toolchain.mkinc
3
4 kexclusion = $(shell cat ksrc.excludes)
5
6 define ksrc_dirs
7         kernel
8         hal
9         libs
10         arch/$(ARCH)
11 endef
12
13 define kinc_dirs
14         includes
15         includes/usr
16         arch/$(ARCH)/includes
17 endef
18
19
20 kbin_dir := $(BUILD_DIR)
21 kbin := $(BUILD_NAME)
22
23 ksrc_files := $(foreach f, $(ksrc_dirs), $(shell find $(f) -name "*.[cS]"))
24 ksrc_files := $(filter-out $(kexclusion),$(ksrc_files))
25 ksrc_objs := $(addsuffix .o,$(ksrc_files))
26 ksrc_deps := $(addsuffix .d,$(ksrc_files))
27
28 kinc_opts := $(addprefix -I,$(kinc_dirs))
29
30 tmp_kbin  := $(BUILD_DIR)/tmpk.bin
31 ksymtable := lunaix_ksyms.o
32
33 CFLAGS += -include flags.h
34 CFLAGS += -include config.h
35
36 %.S.o: %.S
37         $(call status_,AS,$<)
38         @$(CC) $(CFLAGS) $(kinc_opts) -c $< -o $@
39
40 %.c.o: %.c
41         $(call status_,CC,$<)
42         @$(CC) $(CFLAGS) $(kinc_opts) -c $< -o $@
43
44 $(tmp_kbin): $(ksrc_objs)
45         $(call status_,LD,$@)
46         @$(CC) -T link/linker.ld $(LDFLAGS) -o $@ $^
47
48 $(ksymtable): $(tmp_kbin)
49         $(call status_,KSYM,$@)
50         @scripts/gen_ksymtable.sh DdRrTtAGg $< > .lunaix_ksymtable.S
51         @$(CC) $(CFLAGS) -c .lunaix_ksymtable.S -o $@
52
53 .PHONY: __do_relink
54 __do_relink: $(ksrc_objs) $(ksymtable)
55         $(call status_,LD,$(kbin))
56         @$(CC) -T link/linker.ld $(LDFLAGS) -o $(kbin) $^
57         @rm $(tmp_kbin)
58
59 .PHONY: all
60 all: __do_relink
61
62 clean:
63         @rm -f $(ksrc_objs)
64         @rm -f $(ksrc_deps)
65         @rm -f .lunaix_ksymtable.S $(ksymtable)