aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2023-03-05 11:33:30 +0200
committeraqua <aqua@iserlohn-fortress.net>2023-03-05 11:33:30 +0200
commitc329c44db94a941974d6bfc8a8f661ebf5efa615 (patch)
tree9c990658103b2d0f16fe3f246f4d53e55395670d
parentImport kconfig from the linux kernel (diff)
downloadkernel-c329c44db94a941974d6bfc8a8f661ebf5efa615.tar.xz
Add TARGETBIN and TARGETLIB rules
-rw-r--r--Makefile.all5
-rw-r--r--devices/Makefile1
-rw-r--r--i686/Makefile4
-rw-r--r--lib/Makefile2
-rw-r--r--rules.mk80
-rw-r--r--src/Makefile1
-rw-r--r--tools/kconfig/Makefile8
7 files changed, 56 insertions, 45 deletions
diff --git a/Makefile.all b/Makefile.all
index 0909e0e..a92631f 100644
--- a/Makefile.all
+++ b/Makefile.all
@@ -7,7 +7,9 @@ include Makefile.config
${ARCH}_LDFLAGS += -T ${ARCH}/linker.ld
-TARGETS += glitch.elf
+TARGETBIN += glitch
+glitch.OBJS += ${ARCH}/arch.a src/kernel.a devices/devs.a lib/libk.a
+
include rules.mk
.PHONY: run info
@@ -34,7 +36,6 @@ info:
@echo " QEMU: ${QEMU}"
# build targets
-glitch.elf: ${ARCH}/arch.a src/kernel.a devices/devs.a lib/libk.a
glitch.iso: glitch.elf grub/grub.cfg
@grub-file --is-x86-multiboot2 glitch.elf
diff --git a/devices/Makefile b/devices/Makefile
index 56cbac6..3c61f6d 100644
--- a/devices/Makefile
+++ b/devices/Makefile
@@ -4,6 +4,7 @@ INCLUDES := -I../${ARCH}
${ARCH}_CFLAGS += ${INCLUDES}
${ARCH}_CXXFLAGS += ${INCLUDES}
+TARGETLIB += devs
devs.SRCS = pic_8259.c uart_16550.cpp vga.cpp i8042.c pckbd.c mouse.c
include ../rules.mk
diff --git a/i686/Makefile b/i686/Makefile
index 0a19955..ba780a9 100644
--- a/i686/Makefile
+++ b/i686/Makefile
@@ -4,12 +4,10 @@ INCLUDES := -isystem../grub
${ARCH}_CFLAGS += ${INCLUDES}
${ARCH}_CXXFLAGS += ${INCLUDES}
+TARGETLIB += arch
arch.SRCS = boot.S init.s \
gdt.c lgdt.c \
lidt.c isr.c
include ../rules.mk
-include:
- mkdir -p $@
- ln -sTf ../../grub $@/grub
diff --git a/lib/Makefile b/lib/Makefile
index 4415777..f5eeded 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,5 +1,6 @@
include ../Makefile.config
+TARGETLIB += libk
libk.SRCS = \
libk/endian/little.c \
libk/stdio/printf.c libk/stdio/fprintf.c libk/stdio/vfprintf.cpp \
@@ -8,6 +9,7 @@ libk.SRCS = \
TESTS += tst/endian_little tst/mem tst/string tst/linked_list_allocator
+TARGETLIB += blake2
blake2.SRCS = blake2/blake2s.c
TESTS += tst/blake2s_selftest
diff --git a/rules.mk b/rules.mk
index 05994ab..833664d 100644
--- a/rules.mk
+++ b/rules.mk
@@ -5,50 +5,53 @@
objects = $(foreach f,$($1),$(addsuffix $2.o,$(basename $f)))
# generate depends from .S .c .cpp sources
-# args 1: target.SRCS
+# arg 1: target.SRCS
+# arg 2: dependency suffix prefix
# returns: target.DEPS
-depends = $(foreach f,$(filter %.S %.c %.cpp,$($1)),$(addsuffix .d,$(basename $f)))
+depends = $(foreach f,$(filter %.S %.c %.cpp,$($1)),$(addsuffix $2.d,$(basename $f)))
# default target
all: targets
- @echo " -> Built all in $(shell pwd | xargs basename)"
-
-# for each target.SRCS
-# - generate target.OBJS
-# - generate target.DEPS and include them
-# - generate target.a that depends on target.OBJS
-# - add target.a to TARGETS
-$(foreach V,$(filter %.SRCS, ${.VARIABLES}),\
- $(eval $(V:%.SRCS=%.OBJS) := $(call objects,$V,_${ARCH})) \
- $(eval TARGET.OBJS += $(V:%.SRCS=%.OBJS)) \
- $(eval $(V:%.SRCS=%.DEPS) := $(call depends,$V)) \
- $(eval include $($(V:%.SRCS=%.DEPS))) \
- $(eval TARGET.DEPS += $(V:%.SRCS=%.DEPS)) \
- $(eval $(V:%.SRCS=%.a): $($(V:%.SRCS=%.OBJS))) \
- $(eval TARGETS += $(V:%.SRCS=%.a)) \
+
+
+# TARGETBIN: binaries using the target architecture
+$(foreach T,${TARGETBIN},\
+ $(eval $T.OBJS += $(call objects,$T.SRCS,_${ARCH}) ) \
+ $(eval $T.DEPS += $(call depends,$T.SRCS,_${ARCH}) ) \
+ $(eval include $($T.DEPS) ) \
+ $(eval $T.elf: ${$T.OBJS} ) \
+ $(eval DEFAULT_TARGETS += $T.elf) \
+)
+
+# TARGETLIB: static libraries using the target architecture
+$(foreach T,${TARGETLIB},\
+ $(eval $T.OBJS += $(call objects,$T.SRCS,_${ARCH}) ) \
+ $(eval $T.DEPS += $(call depends,$T.SRCS,_${ARCH}) ) \
+ $(eval include $($T.DEPS) ) \
+ $(eval $T.a: ${$T.OBJS} ) \
+ $(eval DEFAULT_TARGETS += $T.a) \
)
-# for each target in HOSTTARGETBIN
-# - generate target.OBJS from target.SRCS
-# - generate target.DEPS from target.SRCS
-# - include target.DEPS
-# - generate target.exe depending on target.OBJS
+# HOSTTARGETBIN: binaries using the host compiler
$(foreach T,${HOSTTARGETBIN},\
- $(eval $T.OBJS := $(call objects,$T.SRC,) ) \
- $(eval $T.DEPS := $(call depends,$T.SRC) ) \
+ $(eval $T.OBJS += $(call objects,$T.SRCS,) ) \
+ $(eval $T.DEPS += $(call depends,$T.SRCS,) ) \
+ $(eval include $($T.DEPS) ) \
$(eval $T: ${$T.OBJS}; @echo ' LD HOST $T'; ${HOST_CC} ${HOST_LDFLAGS} -o $T ${$T.OBJS} ) \
+ $(eval DEFAULT_TARGETS += $T) \
)
TESTS.DEPS = $(foreach F,${TESTS},$(addsuffix .d,$F))
include ${TESTS.DEPS}
debug:
- @echo "targets: ${TARGETS}"
- @echo " OBJS: ${TARGET.OBJS}"
- @echo " DEPS: ${TARGET.DEPS}"
- @echo "tests : ${TESTS}"
- @echo " DEPS: ${TESTS.DEPS}"
- @echo "HOSTTARGETBIN: ${HOSTTARGETBIN}"
+ @echo "TARGETBIN ${TARGETBIN}"
+ @echo "TARGETLIB ${TARGETLIB}"
+ @echo "HOSTTARGETBIN ${HOSTTARGETBIN}"
+ @echo "HOSTTARGETLIB ${HOSTTARGETLIB}"
+ @echo "DEFAULT_TARGETS ${DEFAULT_TARGETS}"
+ @echo "TESTS ${TESTS}"
+ @echo " DEPS ${TESTS.DEPS}"
%.info:
@echo "Target: $(basename $@)"
@@ -56,25 +59,30 @@ debug:
@echo " OBJS: ${$(basename $@).OBJS}"
@echo " DEPS: ${$(basename $@).DEPS}"
-targets: ${TARGETS}
+targets: ${DEFAULT_TARGETS}
+ @echo " -> Built ${DEFAULT_TARGETS}"
# extra flags
${ARCH}_CFLAGS += -I../lib/libk \
-Werror=implicit-function-declaration
${ARCH}_CXXFLAGS += -I../lib/libk -Drestrict=__restrict__
-# Depndency rules
-%.d: %.S
+# Target depndency rules
+%_${ARCH}.d: %.S
@${${ARCH}_CC} ${${ARCH}_CFLAGS} -M -MT $(<:.S=_${ARCH}.o) $< -MF $@
-%.d: %.c
+%_${ARCH}.d: %.c
@${${ARCH}_CC} ${${ARCH}_CFLAGS} -M -MT $(<:.c=_${ARCH}.o) $< -MF $@
-%.d: %.cpp
+%_${ARCH}.d: %.cpp
@${${ARCH}_CXX} ${${ARCH}_CXXFLAGS} -M -MT $(<:.cpp=_${ARCH}.o) $< -MF $@
+# Host dependency rules
+%.d: %.c
+ @${HOST_CC} ${HOST_CFLAGS} -M -MT $(<:.c=.o) $< -MF $@
+
%.d: %.cc
- @${HOST_CXX} ${HOST_CXXFLAGS} -M -MT $(<:.cc=_${ARCH}.o) $< -MF $@
+ @${HOST_CXX} ${HOST_CXXFLAGS} -M -MT $(<:.cc=) $< -MF $@
# Target suffix rules
%.a:
diff --git a/src/Makefile b/src/Makefile
index b4bdd0a..f9ab6fe 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -4,6 +4,7 @@ INCLUDES := -isystem../grub -I../${ARCH} -I../devices
${ARCH}_CFLAGS += ${INCLUDES}
${ARCH}_CXXFLAGS += ${INCLUDES}
+TARGETLIB += kernel
kernel.SRCS := multiboot2.c mmap.c kernel.cpp mem/vmm.c
kernel.OBJS := conf.h
diff --git a/tools/kconfig/Makefile b/tools/kconfig/Makefile
index 5fa0a0a..b7dd104 100644
--- a/tools/kconfig/Makefile
+++ b/tools/kconfig/Makefile
@@ -2,16 +2,16 @@ include ../../Makefile.config
HOSTTARGETBIN += conf mconf
-lxdiag.SRC := \
+lxdiag_srcs := \
lxdialog/checklist.c lxdialog/inputbox.c lxdialog/menubox.c lxdialog/textbox.c lxdialog/util.c lxdialog/yesno.c
-parser.SRC := \
+parser_srcs := \
confdata.c expr.c menu.c preprocess.c symbol.c util.c \
lex.yy.c parser.tab.c
-conf.SRC := $(parser.SRC) conf.c
+conf.SRCS := ${parser_srcs} conf.c
-mconf.SRC := $(parser.SRC) $(lxdiag.SRC) mconf.c
+mconf.SRCS := ${parser_srcs} ${lxdiag_srcs} mconf.c
HOST_CFLAGS := -D_GNU_SOURCE $(shell pkg-config --cflags ncursesw)
HOST_LDFLAGS := $(shell pkg-config --libs ncursesw)