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 pokeas
pokeld pokeld
pokeobjcopy pokeobjcopy
genasm/*

View file

@ -1,8 +1,15 @@
AS = ./pokeas AS := pokeas
ASFLAGS = -mcpu=arm7tdmi ASFLAGS := -mcpu=arm7tdmi
CC := gbacc
CFLAGS := -mthumb-interwork -O2 -Iinclude
SHA1 := sha1sum -c SHA1 := sha1sum -c
GFX := @tools/gbagfx/gbagfx
SCANINC := tools/scaninc/scaninc
# Clear the default suffixes. # Clear the default suffixes.
.SUFFIXES: .SUFFIXES:
@ -11,21 +18,15 @@ SHA1 := sha1sum -c
.PRECIOUS: %.1bpp %.4bpp %.8bpp %.gbapal %.lz .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 CSRCS := $(wildcard src/*.c)
scaninc := tools/scaninc/scaninc OBJS := asm/emerald.o
objs = asm/emerald.o ROM := pokeemerald.gba
ELF := $(ROM:.gba=.elf)
$(foreach obj, $(objs), \ rom: $(ROM)
$(eval $(obj)_deps := $(shell $(scaninc) $(obj:.o=.s))) \
)
rom := pokeemerald.gba
elf := $(rom:.gba=.elf)
rom: $(rom)
tools: gbagfx scaninc tools: gbagfx scaninc
@ -36,27 +37,49 @@ scaninc:
cd tools/scaninc && make cd tools/scaninc && make
# For contributors to make sure a change didn't affect the contents of the ROM. # For contributors to make sure a change didn't affect the contents of the ROM.
compare: $(rom) compare: $(ROM)
@$(SHA1) rom.sha1 @$(SHA1) rom.sha1
clean: 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 {} + 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 include graphics_file_rules.mk
%.png: ; %.png: ;
%.pal: ; %.pal: ;
%.1bpp: %.png ; $(gfx) $< $@ %.1bpp: %.png ; $(GFX) $< $@
%.4bpp: %.png ; $(gfx) $< $@ %.4bpp: %.png ; $(GFX) $< $@
%.8bpp: %.png ; $(gfx) $< $@ %.8bpp: %.png ; $(GFX) $< $@
%.gbapal: %.pal ; $(gfx) $< $@ %.gbapal: %.pal ; $(GFX) $< $@
%.lz: % ; $(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) %.o: %.s $$($$@_deps)
$(AS) $(ASFLAGS) -o $@ $< $(AS) $(ASFLAGS) -o $@ $<
# Link objects to produce the ROM. # Link objects to produce the ROM.
$(rom): $(objs) $(ROM): $(OBJS)
./pokeld -T ld_script.txt -T wram_syms.txt -o $(elf) $(objs) ./pokeld -T ld_script.txt -T wram_syms.txt -o $(ELF) $(OBJS)
./pokeobjcopy -O binary $(elf) $(rom) ./pokeobjcopy -O binary $(ELF) $(ROM)

View file

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

View file

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