@@ -2,26 +2,37 @@ export ARCH = x86 export OS = lin export BITS = 64 +export TMP = $(PWD)/tmp export TARGET = $(ARCH).$(OS).$(BITS) moddirs = $(wildcard k*) -modules = $(moddirs:k%=%) -headers = $(moddirs:k%=$(OUT)/k/%.h) -objects = $(modules:%=$(OUT)/k%.o) -makefiles = $(moddirs:%=%/makefile) - binaries = $(wildcard */exe.*.c) binmods = $(sort $(dir $(binaries))) -all: obj defs tool +posix-oses = lin fbsd dar and hai mgw + +ifeq ($(findstring $(OS),$(posix-oses)),$(OS)) +export POSIX = yes +else +export POSIX = no +endif + +# include libgcc.a in gcc builds, just in case +ifeq ($(CC),gcc) +export COMPLIB = -lgcc +endif + +all: defs obj tool obj: $(moddirs:%=%.obj) -defs: $(headers) -tool: $(binmods:%=%.tool) +defs: $(moddirs:%=%.def) +tool: $(OUT)/libk.a $(binmods:%=%.tool) +clean: + rm -rf $(TMP) $(OUT) -lists = moddirs modules headers objects makefiles binaries binmods +lists = moddirs objects binaries binmods POSIX dbg: @echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))") %.obj: %/makefile ${TARGET}.calls $(OUT) @@ -31,22 +42,22 @@ cd $* && $(MAKE) tool %.dbg: %/makefile $(OUT) cd $* && $(MAKE) dbg + +%.def: %/makefile $(OUT) $(OUT)/k + cd $* && $(MAKE) def %.calls: arch/makefile - cd arch && make calls.$*.s + cd arch && $(MAKE) $(TMP)/calls.$*.s -$(OUT)/libk.so: mods $(OUT) - $(CC) -shared -o $@ $(objects) +$(OUT)/libk.so: obj $(OUT) + $(CC) -shared -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o -$(OUT)/libk.a: mods $(OUT) - # using `ar c` and ranlib here instead of - # `ar cs` in case `ar` isn't the GNU version - ar c $@ $(objects) +$(OUT)/libk.a: 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)/k/%.h: k%/makefile $(OUT)/k - cd k$* && $(MAKE) $@ - $(OUT) $(OUT)/k: mkdir -p $@