begin compiling C source in the build process

This commit is contained in:
YamaArashi 2016-01-07 00:45:06 -08:00
parent b18325fc3e
commit cf8f490381
4 changed files with 54 additions and 28 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@
pokeas
pokeld
pokeobjcopy
genasm/*

View File

@ -1,8 +1,15 @@
AS = ./pokeas
ASFLAGS = -mcpu=arm7tdmi
AS := pokeas
ASFLAGS := -mcpu=arm7tdmi
CC := gbacc
CFLAGS := -mthumb-interwork -O2 -Iinclude
SHA1 := sha1sum -c
GFX := @tools/gbagfx/gbagfx
SCANINC := tools/scaninc/scaninc
# Clear the default suffixes.
.SUFFIXES:
@ -11,21 +18,15 @@ SHA1 := sha1sum -c
.PRECIOUS: %.1bpp %.4bpp %.8bpp %.gbapal %.lz
.PHONY: rom tools gbagfx scaninc clean compare
.PHONY: rom tools gbagfx scaninc clean compare deps
gfx := @tools/gbagfx/gbagfx
scaninc := tools/scaninc/scaninc
CSRCS := $(wildcard src/*.c)
OBJS := asm/emerald.o
objs = asm/emerald.o
ROM := pokeemerald.gba
ELF := $(ROM:.gba=.elf)
$(foreach obj, $(objs), \
$(eval $(obj)_deps := $(shell $(scaninc) $(obj:.o=.s))) \
)
rom := pokeemerald.gba
elf := $(rom:.gba=.elf)
rom: $(rom)
rom: $(ROM)
tools: gbagfx scaninc
@ -36,27 +37,49 @@ scaninc:
cd tools/scaninc && make
# For contributors to make sure a change didn't affect the contents of the ROM.
compare: $(rom)
compare: $(ROM)
@$(SHA1) rom.sha1
clean:
$(RM) $(rom) $(elf) $(objs)
$(RM) $(ROM) $(ELF) $(OBJS)
$(RM) genasm/*
find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.latfont' -o -iname '*.hwjpnfont' -o -iname '*.fwjpnfont' \) -exec rm {} +
include graphics_file_rules.mk
%.png: ;
%.pal: ;
%.1bpp: %.png ; $(gfx) $< $@
%.4bpp: %.png ; $(gfx) $< $@
%.8bpp: %.png ; $(gfx) $< $@
%.gbapal: %.pal ; $(gfx) $< $@
%.lz: % ; $(gfx) $< $@
%.1bpp: %.png ; $(GFX) $< $@
%.4bpp: %.png ; $(GFX) $< $@
%.8bpp: %.png ; $(GFX) $< $@
%.gbapal: %.pal ; $(GFX) $< $@
%.lz: % ; $(GFX) $< $@
deps: $(CSRCS:src/%.c=genasm/%.s)
$(foreach obj, $(OBJS), \
$(eval $(obj)_deps := $(shell $(SCANINC) $(obj:.o=.s))) \
)
$(OBJS): deps
# TODO: fix this .syntax hack
genasm/prefix.tmp:
echo -e "\t.syntax divided" >$@
genasm/suffix.tmp:
echo -e "\t.syntax unified" >$@
genasm/%.s: src/%.c genasm/prefix.tmp genasm/suffix.tmp
mkdir -p genasm
$(CC) $(CFLAGS) -o $@.tmp $< -S
cat genasm/prefix.tmp $@.tmp genasm/suffix.tmp >$@
$(RM) $@.tmp
%.o: %.s $$($$@_deps)
$(AS) $(ASFLAGS) -o $@ $<
# Link objects to produce the ROM.
$(rom): $(objs)
./pokeld -T ld_script.txt -T wram_syms.txt -o $(elf) $(objs)
./pokeobjcopy -O binary $(elf) $(rom)
$(ROM): $(OBJS)
./pokeld -T ld_script.txt -T wram_syms.txt -o $(ELF) $(OBJS)
./pokeobjcopy -O binary $(ELF) $(ROM)

View File

@ -13,7 +13,7 @@
Start:
.include "asm/crt0.s"
.include "asm/main.s"
.include "asm/malloc.s"
.include "genasm/malloc.s"
.include "asm/dma3_manager.s"
.include "asm/gpu_reg_manager.s"
.include "asm/gpu_bg.s"

View File

@ -1,3 +1,5 @@
gDma3Requests = 0x3000010;
gDma3ManagerLocked = 0x3000810;
gDma3RequestCursor = 0x3000811;
gHeapStart = 0x03000004;
gHeapSize = 0x03000008;
gDma3Requests = 0x03000010;
gDma3ManagerLocked = 0x03000810;
gDma3RequestCursor = 0x03000811;