From a4330e37e9d27799754e1f553cbe9dee9180bc17 Mon Sep 17 00:00:00 2001 From: Aetias Date: Sat, 20 Apr 2024 13:08:56 +0200 Subject: [PATCH] Support `.c` files in `Makefile` --- Makefile | 16 ++++++++++++---- docs/decompiling.md | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 90534997..6b9973e7 100644 --- a/Makefile +++ b/Makefile @@ -26,10 +26,12 @@ ARM7_BIOS := arm7_bios.bin ASSETS_TXT := assets.txt ASM_FILES := $(shell find asm -name *.s) -CXX_FILES := $(shell find src -name *.cpp) +CXX_FILES := $(shell find src -name *.cpp) $(shell find libs -name *.cpp) +C_FILES := $(shell find src -name *.c) $(shell find libs -name *.c) ASM_OBJS = $(ASM_FILES:%.s=$(TARGET_DIR)/%.s.o) ASM_INCS = $(ASM_FILES:%.s=%.inc) CXX_OBJS = $(CXX_FILES:%.cpp=$(TARGET_DIR)/%.cpp.o) +C_OBJS = $(C_FILES:%.c=$(TARGET_DIR)/%.c.o) OV_BINS := $(wildcard $(TARGET_DIR)/overlays/*.bin) OV_LZS = $(OV_BINS:%.bin=%.lz) @@ -47,7 +49,9 @@ LCF_FILE := $(ROOT)/$(BUILD_DIR)/arm9_linker_script.lcf OBJS_FILE := $(ROOT)/$(BUILD_DIR)/arm9_objects.txt ASM_FLAGS := -proc arm5te -d $(REGION) -i asm -msgstyle gcc -CC_FLAGS := -proc arm946e -interworking -O4,p -enum int -i include -i- -i libs/c/include -nolink -d $(REGION) -char signed -lang=c++ -sym on -msgstyle gcc +CC_FLAGS := -proc arm946e -interworking -O4,p -enum int -i include -i- -i libs/c/include -i libs/cpp/include -nolink -d $(REGION) -char signed -sym on -msgstyle gcc +C_FLAGS := -lang=c +CXX_FLAGS := -lang=c++ LD_FLAGS := -proc arm946e -nostdlib -interworking -nodead -m Entry -map closure,unused -o main.bin -msgstyle gcc ifeq ($(NONMATCHING),1) @@ -121,10 +125,14 @@ $(ASM_OBJS): $(TARGET_DIR)/%.o: % $(CXX_OBJS): $(TARGET_DIR)/%.o: % mkdir -p $(dir $@) - LM_LICENSE_FILE=$(MW_LICENSE) $(WINE) $(MW_CC) $(CC_FLAGS) $< -o $@ + LM_LICENSE_FILE=$(MW_LICENSE) $(WINE) $(MW_CC) $(CC_FLAGS) $(CXX_FLAGS) $< -o $@ + +$(C_OBJS): $(TARGET_DIR)/%.o: % + mkdir -p $(dir $@) + LM_LICENSE_FILE=$(MW_LICENSE) $(WINE) $(MW_CC) $(CC_FLAGS) $(C_FLAGS) $< -o $@ .PHONY: link -link: lcf $(ASM_OBJS) $(CXX_OBJS) +link: lcf $(ASM_OBJS) $(CXX_OBJS) $(C_OBJS) cd $(TARGET_DIR) && LM_LICENSE_FILE=$(MW_LICENSE) $(WINE) $(MW_LD) $(LD_FLAGS) $(LCF_FILE) @$(OBJS_FILE) .PHONY: compress diff --git a/docs/decompiling.md b/docs/decompiling.md index 2625a4c4..a779f120 100644 --- a/docs/decompiling.md +++ b/docs/decompiling.md @@ -39,6 +39,7 @@ _0211bf50: .word data_ov09_0211f59c - If no suitable header file exists, make a new one and put any structs and types you need in there. 1. Paste the context into decomp.me, and create the scratch. 1. Copy the `CC_FLAGS` from `Makefile` into the arguments field in decomp.me. + - Also copy `CXX_FLAGS` if your function comes from a `.cpp` file. Otherwise, copy `C_FLAGS` if it's a `.c` file. - Replace the `-d $(REGION)` flag with whichever region you intend to decompile for. You can also delete the flag entirely if the function contains no region differences. 1. Decompile the function and try to get a 100% match.