@@ -25,35 +25,42 @@ CPPFLAGS := -DMIPS -DF3DEX_GBI_2 -DF3DEX_GBI_PL -DGBI_DOWHILE -I include -I incl
2525 -I mm-decomp/include -I mm-decomp/src -I mm-decomp/extracted/n64-us -idirafter include/libc -idirafter mm-decomp/include/libc
2626LDFLAGS := -nostdlib -T $(LDSCRIPT ) -Map $(BUILD_DIR ) /mod.map --unresolved-symbols=ignore-all --emit-relocs -e 0 --no-nmagic -gc-sections
2727
28- C_SRCS := $(wildcard src/* .c)
28+ rwildcard = $(foreach d,$(wildcard $(1:=/* ) ) ,$(call rwildcard,$d,$2) $(filter $(subst * ,% ,$2) ,$d) )
29+ getdirs = $(sort $(dir $(1 ) ) )
30+
31+ C_SRCS := $(call rwildcard,src,* .c)
2932C_OBJS := $(addprefix $(BUILD_DIR ) /, $(C_SRCS:.c=.o ) )
3033C_DEPS := $(addprefix $(BUILD_DIR ) /, $(C_SRCS:.c=.d ) )
3134
3235ALL_OBJS := $(C_OBJS )
3336ALL_DEPS := $(C_DEPS )
37+ BUILD_DIRS := $(call getdirs,$(ALL_OBJS ) )
3438
3539all : $(TARGET )
3640
3741$(TARGET ) : $(ALL_OBJS ) $(LDSCRIPT ) | $(BUILD_DIR )
3842 $(LD ) $(ALL_OBJS ) $(LDFLAGS ) -o $@
3943
40- $(BUILD_DIR ) $(BUILD_DIR ) /src :
44+ $(BUILD_DIR ) $(BUILD_DIRS ) :
4145ifeq ($(OS ) ,Windows_NT)
42- mkdir $(subst /,\,$@)
46+ if not exist "$(subst /,\,$@)" mkdir " $(subst /,\,$@)"
4347else
4448 mkdir -p $@
4549endif
4650
47- $(C_OBJS ) : $(BUILD_DIR ) /% .o : % .c | $(BUILD_DIR ) $( BUILD_DIR ) /src
51+ $(C_OBJS ) : $(BUILD_DIR ) /% .o : % .c | $(BUILD_DIRS )
4852 $(CC ) $(CFLAGS ) $(CPPFLAGS ) $< -MMD -MF $(@:.o=.d ) -c -o $@
4953
5054clean :
5155ifeq ($(OS ) ,Windows_NT)
52- rmdir /S /Q $(BUILD_DIR)
56+ if exist $(BUILD_DIR) rmdir /S /Q $(BUILD_DIR)
5357else
5458 rm -rf $(BUILD_DIR)
5559endif
5660
5761-include $(ALL_DEPS )
5862
5963.PHONY : clean all
64+
65+ # Print target for debugging
66+ print-% : ; $(info $* is a $(flavor $* ) variable set to [$($* ) ]) @true
0 commit comments