add automatic dependency generation

This commit is contained in:
camthesaxman 2018-03-08 20:20:18 -06:00
parent bb1d40879e
commit a5caa19cfa
2 changed files with 10 additions and 2 deletions

1
.gitignore vendored
View File

@ -61,3 +61,4 @@ src/*.s
*.dump
tools/agbcc
*.exe
.dep

View File

@ -22,23 +22,29 @@ SYM_FILES := sym_iwram.txt sym_ewram.txt
CFILES := $(wildcard src/*.c)
SFILES := $(wildcard asm/*.s) $(wildcard asm/libc/*.s) $(wildcard data/*.s)
OFILES := $(SFILES:.s=.o) $(CFILES:.c=.o)
DEPS_DIR := .dep
# Use the older compiler to build the m4a library
# Use the older compiler to build library code
src/agb_sram.o: CC1FLAGS := -mthumb-interwork -Wimplicit -Wparentheses -Werror -O1
src/m4a_2.o: CC1 := tools/agbcc/bin/old_agbcc
src/m4a_4.o: CC1 := tools/agbcc/bin/old_agbcc
#### Main Targets ####
compare: $(ROM)
sha1sum -c checksum.sha1
clean:
$(RM) $(ROM) $(ELF) $(MAP) $(OFILES) src/*.s
$(RM) $(ROM) $(ELF) $(MAP) $(OFILES) src/*.s -r $(DEPS_DIR)
#### Recipes ####
# Automatic dependency generation
MAKEDEPEND = mkdir -p $(DEPS_DIR)/$(@D) && $(CPP) $(CPPFLAGS) $< -MM -MG -MT $@ $(DEPS_DIR)/$*.d > $(DEPS_DIR)/$*.d
-include $(addprefix $(DEPS_DIR)/,$(CFILES:.c=.d))
$(ELF): $(OFILES) $(LDSCRIPT) $(SYM_FILES)
$(LD) -T $(LDSCRIPT) -Map $(MAP) $(OFILES) tools/agbcc/lib/libgcc.a tools/agbcc/lib/libc.a -o $@
@ -46,6 +52,7 @@ $(ELF): $(OFILES) $(LDSCRIPT) $(SYM_FILES)
$(OBJCOPY) -O binary --pad-to 0x9000000 $< $@
%.o: %.c
@$(MAKEDEPEND)
$(CPP) $(CPPFLAGS) $< | $(CC1) $(CC1FLAGS) -o $*.s
echo '.ALIGN 2, 0' >> $*.s
$(AS) $(ASFLAGS) $*.s -o $*.o