Unifying the Lunaix's Physical Memory Model (#28)
[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
31 CFLAGS += -include flags.h
32 CFLAGS += -include config.h
33
34 %.S.o: %.S
35         $(call status_,AS,$<)
36         @$(CC) $(CFLAGS) $(kinc_opts) -c $< -o $@
37
38 %.c.o: %.c
39         $(call status_,CC,$<)
40         @$(CC) $(CFLAGS) $(kinc_opts) -c $< -o $@
41
42 $(kbin_dir)/modksyms: $(kbin)
43         $(call status_,MOD,$@)
44         @$(PY) scripts/syms_export.py --bits=32 --order=little -o "$@"  "$<" 
45
46 .PHONY: __do_relink
47 __do_relink: $(ksrc_objs)
48         $(call status_,LD,$(kbin))
49         @$(CC) -T link/linker.ld -o $(kbin) $(ksrc_objs) $(LDFLAGS)
50
51 .PHONY: all
52 all: __do_relink $(kbin_dir)/modksyms
53
54 clean:
55         @rm -f $(ksrc_objs)
56         @rm -f $(ksrc_deps)