2025-02-27 17:55:33 -05:00
|
|
|
BUILD_DIR := build
|
|
|
|
|
|
|
|
|
|
# Allow the user to specify the compiler and linker on macOS
|
|
|
|
|
# as Apple Clang does not support MIPS architecture
|
2025-12-18 23:42:37 -05:00
|
|
|
ifeq ($(OS),Windows_NT)
|
2025-02-27 17:55:33 -05:00
|
|
|
CC := clang
|
|
|
|
|
LD := ld.lld
|
2025-12-18 23:42:37 -05:00
|
|
|
else ifneq ($(shell uname),Darwin)
|
|
|
|
|
CC := clang
|
|
|
|
|
LD := ld.lld
|
|
|
|
|
else
|
|
|
|
|
CC ?= clang
|
|
|
|
|
LD ?= ld.lld
|
2025-02-27 17:55:33 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
TARGET := $(BUILD_DIR)/mod.elf
|
|
|
|
|
|
|
|
|
|
LDSCRIPT := mod.ld
|
2025-12-18 23:42:37 -05:00
|
|
|
ARCHFLAGS := -target mips -mips2 -mabi=32 -O2 -G0 -mno-abicalls -mno-odd-spreg -mno-check-zero-division \
|
|
|
|
|
-fomit-frame-pointer -ffast-math -fno-unsafe-math-optimizations -fno-builtin-memset -funsigned-char -fno-builtin-sinf -fno-builtin-cosf
|
|
|
|
|
WARNFLAGS := -Wall -Wextra -Wno-incompatible-library-redeclaration -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-variable \
|
|
|
|
|
-Wno-missing-braces -Wno-unsupported-floating-point-opt -Wno-cast-function-type-mismatch -Werror=section -Wno-visibility
|
|
|
|
|
CFLAGS := $(ARCHFLAGS) $(WARNFLAGS) -D_LANGUAGE_C -nostdinc -ffunction-sections
|
|
|
|
|
CPPFLAGS := -nostdinc -DMIPS -DF3DEX_GBI -I include -I include/dummy_headers \
|
|
|
|
|
-I bk-decomp/include -I bk-decomp/include/2.0L -I bk-decomp/include/2.0L/PR
|
|
|
|
|
LDFLAGS := -nostdlib -T $(LDSCRIPT) -Map $(BUILD_DIR)/mod.map --unresolved-symbols=ignore-all --emit-relocs -e 0 --no-nmagic -gc-sections
|
2025-02-27 17:55:33 -05:00
|
|
|
|
2025-12-18 23:42:37 -05:00
|
|
|
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
|
|
|
|
|
getdirs = $(sort $(dir $(1)))
|
|
|
|
|
|
|
|
|
|
C_SRCS := $(call rwildcard,src,*.c)
|
2025-02-27 17:55:33 -05:00
|
|
|
C_OBJS := $(addprefix $(BUILD_DIR)/, $(C_SRCS:.c=.o))
|
|
|
|
|
C_DEPS := $(addprefix $(BUILD_DIR)/, $(C_SRCS:.c=.d))
|
|
|
|
|
|
2025-12-18 23:42:37 -05:00
|
|
|
ALL_OBJS := $(C_OBJS)
|
|
|
|
|
ALL_DEPS := $(C_DEPS)
|
|
|
|
|
BUILD_DIRS := $(call getdirs,$(ALL_OBJS))
|
2025-02-27 17:55:33 -05:00
|
|
|
|
2025-12-18 23:42:37 -05:00
|
|
|
all: $(TARGET)
|
|
|
|
|
|
|
|
|
|
$(TARGET): $(ALL_OBJS) $(LDSCRIPT) | $(BUILD_DIR)
|
|
|
|
|
$(LD) $(ALL_OBJS) $(LDFLAGS) -o $@
|
|
|
|
|
|
|
|
|
|
$(BUILD_DIR) $(BUILD_DIRS):
|
2025-02-27 17:55:33 -05:00
|
|
|
ifeq ($(OS),Windows_NT)
|
2025-12-18 23:42:37 -05:00
|
|
|
if not exist "$(subst /,\,$@)" mkdir "$(subst /,\,$@)"
|
2025-02-27 17:55:33 -05:00
|
|
|
else
|
|
|
|
|
mkdir -p $@
|
|
|
|
|
endif
|
|
|
|
|
|
2025-12-18 23:42:37 -05:00
|
|
|
$(C_OBJS): $(BUILD_DIR)/%.o : %.c | $(BUILD_DIRS)
|
2025-02-27 17:55:33 -05:00
|
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) $< -MMD -MF $(@:.o=.d) -c -o $@
|
|
|
|
|
|
|
|
|
|
clean:
|
2025-12-18 23:42:37 -05:00
|
|
|
ifeq ($(OS),Windows_NT)
|
|
|
|
|
if exist $(BUILD_DIR) rmdir /S /Q $(BUILD_DIR)
|
|
|
|
|
else
|
2025-02-27 17:55:33 -05:00
|
|
|
rm -rf $(BUILD_DIR)
|
2025-12-18 23:42:37 -05:00
|
|
|
endif
|
2025-02-27 17:55:33 -05:00
|
|
|
|
2025-12-18 23:42:37 -05:00
|
|
|
-include $(ALL_DEPS)
|
2025-02-27 17:55:33 -05:00
|
|
|
|
2025-12-18 23:42:37 -05:00
|
|
|
.PHONY: clean all
|
|
|
|
|
|
|
|
|
|
# Print target for debugging
|
|
|
|
|
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
|