@@ -7,11 +7,32 @@ export TARGET = $(ARCH).$(OS).$(BITS) moddirs = $(wildcard k*) -binaries = $(wildcard */exe.*.c) +binaries = $(wildcard k*/*.exe.c) +functions = $(wildcard k*/*.fn.c) +assemblies = $(wildcard k*/*.fn.${TARGET}.s) binmods = $(sort $(dir $(binaries))) +# i'm sorry +collect = $(strip $(foreach dir,$(moddirs),$(addprefix $(OUT)/$(dir).,$(notdir $(wildcard $(dir)/$1))))) + +cfnsources = $(call collect,*.fn.c) +sfnsources = $(call collect,*.fn.${TARGET}.s) +crtsources = $(call collect,*.rt.c) +srtsources = $(call collect,*.rt.${TARGET}.s) +fnsources = $(cfnsources) $(sfnsources) +rtsources = $(crtsources) $(srtsources) +sources = $(fnsources) $(rtsources) + +cfnobjects = $(cfnsources:%.c=%.o) +sfnobjects = $(sfnsources:%.s=%.o) +crtobjects = $(crtsources:%.c=%.o) +srtobjects = $(srtsources:%.s=%.o) +fnobjects = $(cfnobjects) $(sfnobjects) +rtobjects = $(crtobjects) $(srtobjects) +objects = $(fnobjects) $(rtobjects) + header-dir = /usr/include lib-dir = /usr/lib posix-oses = lin fbsd dar and hai mgw @@ -26,9 +47,9 @@ ifeq ($(CC),gcc) export COMPLIB = -lgcc endif -all: defs obj tool lib.static lib.shared +all: $(OUT) defs obj tool lib.static $(OUT)/boot.o lib.shared lib.static: defs obj $(OUT)/libk.a lib.shared: defs obj $(OUT)/libk.so obj: $(moddirs:%=%.obj) defs: $(moddirs:%=%.def) @@ -45,9 +66,9 @@ uninstall: $(header-dir)/k $(lib-dir)/k rm -rf $^ -lists = moddirs objects binaries binmods POSIX +lists = moddirs functions assemblies cfnobjects sfnobjects crtobjects srtobjects rtobjects binaries binmods POSIX dbg: @echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))") %.obj: %/makefile ${TARGET}.calls $(OUT) @@ -64,19 +85,19 @@ %.calls: arch/makefile cd arch && $(MAKE) $(TMP)/calls.$*.s -$(OUT)/libk.so: obj $(OUT) $(OUT)/boot.o - ld -shared $(COMPLIB) -o $@ $(filter-out kcore.boot.%, $(wildcard *.o)) - # $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o +$(OUT)/libk.so: $(fnobjects) + ld -shared $(COMPLIB) -o $@ $^ + @# $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o -$(OUT)/boot.o: $(OUT)/kcore.boot.o $(OUT)/kcore.boot.$(TARGET).o +$(OUT)/boot.o: $(rtobjects) ld -r $^ -o $(OUT)/boot.o -$(OUT)/libk.a: obj $(OUT) - # using `ar rc` and ranlib here instead of - # `ar rcs` in case `ar` isn't the GNU version +$(OUT)/libk.a: $(fnobjects) $(rtobjects) obj $(OUT) + @# using `ar rc` and ranlib here instead of + @# `ar rcs` in case `ar` isn't the GNU version ar rc $@ $(OUT)/*.o ranlib $@ $(OUT) $(OUT)/k: mkdir -p $@