Skip to content

Commit a7f3d8c

Browse files
committed
Support source subfolders in the makefile
1 parent f22c0a8 commit a7f3d8c

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

Makefile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
2626
LDFLAGS := -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)
2932
C_OBJS := $(addprefix $(BUILD_DIR)/, $(C_SRCS:.c=.o))
3033
C_DEPS := $(addprefix $(BUILD_DIR)/, $(C_SRCS:.c=.d))
3134

3235
ALL_OBJS := $(C_OBJS)
3336
ALL_DEPS := $(C_DEPS)
37+
BUILD_DIRS := $(call getdirs,$(ALL_OBJS))
3438

3539
all: $(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):
4145
ifeq ($(OS),Windows_NT)
42-
mkdir $(subst /,\,$@)
46+
if not exist "$(subst /,\,$@)" mkdir "$(subst /,\,$@)"
4347
else
4448
mkdir -p $@
4549
endif
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

5054
clean:
5155
ifeq ($(OS),Windows_NT)
52-
rmdir /S /Q $(BUILD_DIR)
56+
if exist $(BUILD_DIR) rmdir /S /Q $(BUILD_DIR)
5357
else
5458
rm -rf $(BUILD_DIR)
5559
endif
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

Comments
 (0)