refactor: rewrite kernel's make script
[lunaix-os.git] / lunaix-os / kernel.mk
diff --git a/lunaix-os/kernel.mk b/lunaix-os/kernel.mk
new file mode 100644 (file)
index 0000000..81e8921
--- /dev/null
@@ -0,0 +1,44 @@
+include os.mkinc
+include toolchain.mkinc
+
+define ksrc_dirs
+       kernel
+       hal
+       debug
+       libs
+       arch/$(ARCH)
+endef
+
+define kinc_dirs
+       includes
+       includes/usr
+endef
+
+
+kbin_dir := $(BUILD_DIR)
+kbin := $(BUILD_NAME)
+
+ksrc_files := $(foreach f, $(ksrc_dirs), $(shell find $(f) -name "*.[cS]"))
+ksrc_objs := $(addsuffix .o,$(ksrc_files))
+
+kinc_opts := $(addprefix -I,$(kinc_dirs))
+
+
+CFLAGS += -include flags.h
+
+%.S.o: %.S
+       $(call status_,AS,$<)
+       @$(CC) $(kinc_opts) -c $< -o $@
+
+%.c.o: %.c
+       $(call status_,CC,$<)
+       @$(CC) $(CFLAGS) $(kinc_opts) -c $< -o $@
+
+$(kbin): $(ksrc_objs) $(kbin_dir)
+       $(call status_,LD,$@)
+       @$(CC) -T link/linker.ld -o $(kbin) $(ksrc_objs) $(LDFLAGS)
+
+all: $(kbin)
+
+clean:
+       @rm -f $(ksrc_objs)
\ No newline at end of file