Makefile: make the linker rules generic

Rather than re-defining the linker rules, only specify the linker
options in a variable.
This commit is contained in:
Pierre de La Morinerie 2020-06-29 23:04:13 +00:00
parent e75107881d
commit acddec4425

View File

@ -37,109 +37,93 @@ gfx_files = $(shell find src/gfx -type f -name '*.png')
asm_files += $(shell find revisions -type f -name '*.asm') asm_files += $(shell find revisions -type f -name '*.asm')
gfx_files += $(shell find revisions -type f -name '*.png') gfx_files += $(shell find revisions -type f -name '*.png')
deps = $(asm_files) $(gfx_files:.png=.2bpp)
#
# Generic rules
#
# Compile a PNG file to a 2BPP file
%.2bpp: %.png %.2bpp: %.png
$(2BPP) -o $@ $< $(2BPP) -o $@ $<
deps = $(asm_files) $(gfx_files:.png=.2bpp) # Link an object file to a GBC file
%.gbc: src/main.%.o
$(LD) $(LDFLAGS) $($*_ld_opt) -n $*.sym -o $@ $^
$(FX) $(FXFLAGS) $($*_fx_opt) $@
# #
# Japanese # Japanese
# #
games += azlj.gbc games += azlj.gbc
j0_obj = src/main.azlj.o
src/main.azlj.o: src/main.asm $(deps) src/main.azlj.o: src/main.asm $(deps)
$(ASM) $(ASFLAGS) -DLANG=JP -DVERSION=0 -i revisions/J0/src/ -i src/ -o $@ $< $(ASM) $(ASFLAGS) -DLANG=JP -DVERSION=0 -i revisions/J0/src/ -i src/ -o $@ $<
azlj.gbc: $(j0_obj) azlj_fx_opt = --rom-version 0 --title "ZELDA"
$(LD) $(LDFLAGS) -n $*.sym -o $@ $^
$(FX) $(FXFLAGS) --rom-version 0 --title "ZELDA" $@
games += azlj-r1.gbc games += azlj-r1.gbc
j1_obj = src/main.azlj-1.o src/main.azlj-r1.o: src/main.asm $(deps)
src/main.azlj-1.o: src/main.asm $(deps)
$(ASM) $(ASFLAGS) -DLANG=JP -DVERSION=1 -i revisions/J1/src/ -i revisions/J0/src/ -i src/ -o $@ $< $(ASM) $(ASFLAGS) -DLANG=JP -DVERSION=1 -i revisions/J1/src/ -i revisions/J0/src/ -i src/ -o $@ $<
azlj-r1.gbc: $(j1_obj) azlj-r1_fx_opt = --rom-version 1 --title "ZELDA"
$(LD) $(LDFLAGS) -n $*.sym -o $@ $^
$(FX) $(FXFLAGS) --rom-version 1 --title "ZELDA" $@
games += azlj-r2.gbc games += azlj-r2.gbc
j2_obj = src/main.azlj-2.o src/main.azlj-r2.o: src/main.asm $(deps)
src/main.azlj-2.o: src/main.asm $(deps)
$(ASM) $(ASFLAGS) -DLANG=JP -DVERSION=2 -i revisions/J2/src/ -i revisions/J1/src/ -i revisions/J0/src/ -i src/ -o $@ $< $(ASM) $(ASFLAGS) -DLANG=JP -DVERSION=2 -i revisions/J2/src/ -i revisions/J1/src/ -i revisions/J0/src/ -i src/ -o $@ $<
azlj-r2.gbc: $(j2_obj) azlj-r2_fx_opt = --rom-version 2 --title "ZELDA" --game-id "AZLJ"
$(LD) $(LDFLAGS) -n $*.sym -o $@ $^
$(FX) $(FXFLAGS) --rom-version 2 --title "ZELDA" --game-id "AZLJ" $@
# #
# German # German
# #
games += azlg.gbc games += azlg.gbc
g0_obj = src/main.azlg.o
src/main.azlg.o: src/main.asm $(deps) src/main.azlg.o: src/main.asm $(deps)
$(ASM) $(ASFLAGS) -DLANG=DE -DVERSION=0 -i revisions/G0/src/ -i src/ -o $@ $< $(ASM) $(ASFLAGS) -DLANG=DE -DVERSION=0 -i revisions/G0/src/ -i src/ -o $@ $<
azlg.gbc: $(g0_obj) azlg_fx_opt = --rom-version 0 --non-japanese --title "ZELDA"
$(LD) $(LDFLAGS) -n $*.sym -o $@ $^
$(FX) $(FXFLAGS) --rom-version 0 --non-japanese --title "ZELDA" $@
games += azlg-r1.gbc games += azlg-r1.gbc
g1_obj = src/main.azlg-1.o src/main.azlg-r1.o: src/main.asm $(deps) azlj-r2.gbc
src/main.azlg-1.o: src/main.asm $(deps)
$(ASM) $(ASFLAGS) -DLANG=DE -DVERSION=1 -i revisions/G1/src/ -i revisions/G0/src/ -i src/ -o $@ $< $(ASM) $(ASFLAGS) -DLANG=DE -DVERSION=1 -i revisions/G1/src/ -i revisions/G0/src/ -i src/ -o $@ $<
azlg-r1.gbc: $(g1_obj) azlj-r2.gbc azlg-r1_ld_opt = -O azlj-r2.gbc
$(LD) $(LDFLAGS) -O "azlj-r2.gbc" -n $*.sym -o $@ $< azlg-r1_fx_opt = --rom-version 1 --non-japanese --title "ZELDA" --game-id "AZLD"
$(FX) $(FXFLAGS) --rom-version 1 --non-japanese --title "ZELDA" --game-id "AZLD" $@
# #
# French # French
# #
games += azlf.gbc games += azlf.gbc
f0_obj = src/main.azlf.o
src/main.azlf.o: src/main.asm $(deps) src/main.azlf.o: src/main.asm $(deps)
$(ASM) $(ASFLAGS) -DLANG=FR -DVERSION=0 -i revisions/F0/src/ -i src/ -o $@ $< $(ASM) $(ASFLAGS) -DLANG=FR -DVERSION=0 -i revisions/F0/src/ -i src/ -o $@ $<
azlf.gbc: $(f0_obj) azlf_fx_opt = --rom-version 0 --non-japanese --title "ZELDA"
$(LD) $(LDFLAGS) -n $*.sym -o $@ $^
$(FX) $(FXFLAGS) --rom-version 0 --non-japanese --title "ZELDA" $@
games += azlf-r1.gbc games += azlf-r1.gbc
f1_obj = src/main.azlf-1.o src/main.azlf-r1.o: src/main.asm $(deps) azlg-r1.gbc
src/main.azlf-1.o: src/main.asm $(deps)
$(ASM) $(ASFLAGS) -DLANG=FR -DVERSION=1 -i revisions/F1/src/ -i revisions/F0/src/ -i src/ -o $@ $< $(ASM) $(ASFLAGS) -DLANG=FR -DVERSION=1 -i revisions/F1/src/ -i revisions/F0/src/ -i src/ -o $@ $<
azlf-r1.gbc: $(f1_obj) azlg-r1.gbc azlf-r1_ld_opt = -O azlg-r1.gbc
$(LD) $(LDFLAGS) -O "azlg-r1.gbc" -n $*.sym -o $@ $< azlf-r1_fx_opt = --rom-version 1 --non-japanese --title "ZELDA" --game-id "AZLF"
$(FX) $(FXFLAGS) --rom-version 1 --non-japanese --title "ZELDA" --game-id "AZLF" $@
# #
# English # English
# #
games += azle.gbc games += azle.gbc
e0_obj = src/main.azle.o
src/main.azle.o: src/main.asm $(deps) src/main.azle.o: src/main.asm $(deps)
$(ASM) $(ASFLAGS) -DLANG=EN -DVERSION=0 -i src/ -o $@ $< $(ASM) $(ASFLAGS) -DLANG=EN -DVERSION=0 -i src/ -o $@ $<
azle.gbc: $(e0_obj) azle_fx_opt = --rom-version 0 --non-japanese --title "ZELDA"
$(LD) $(LDFLAGS) -n $*.sym -o $@ $^
$(FX) $(FXFLAGS) --rom-version 0 --non-japanese --title "ZELDA" $@
games += azle-r1.gbc games += azle-r1.gbc
e1_obj = src/main.azle-1.o src/main.azle-r1.o: src/main.asm $(deps)
src/main.azle-1.o: src/main.asm $(deps)
$(ASM) $(ASFLAGS) -DLANG=EN -DVERSION=1 -i revisions/E1/src/ -i src/ -o $@ $< $(ASM) $(ASFLAGS) -DLANG=EN -DVERSION=1 -i revisions/E1/src/ -i src/ -o $@ $<
azle-r1.gbc: $(e1_obj) azle-r1_fx_opt = --rom-version 1 --non-japanese --title "ZELDA"
$(LD) $(LDFLAGS) -n $*.sym -o $@ $^
$(FX) $(FXFLAGS) --rom-version 1 --non-japanese --title "ZELDA" $@
games += azle-r2.gbc games += azle-r2.gbc
e2_obj = src/main.azle-2.o src/main.azle-r2.o: src/main.asm $(deps) azlf-r1.gbc
src/main.azle-2.o: src/main.asm $(deps)
$(ASM) $(ASFLAGS) -DLANG=EN -DVERSION=2 -i revisions/E2/src/ -i revisions/E1/src/ -i src/ -o $@ $< $(ASM) $(ASFLAGS) -DLANG=EN -DVERSION=2 -i revisions/E2/src/ -i revisions/E1/src/ -i src/ -o $@ $<
azle-r2.gbc: $(e2_obj) azlf-r1.gbc azle-r2_ld_opt = -O azlf-r1.gbc
$(LD) $(LDFLAGS) -O "azlf-r1.gbc" -n $*.sym -o $@ $< azle-r2_fx_opt = --rom-version 2 --non-japanese --title "ZELDA" --game-id "AZLE"
$(FX) $(FXFLAGS) --rom-version 2 --non-japanese --title "ZELDA" --game-id "AZLE" $@
# #
# General rules # Main targets
# #
# By default, build the US 1.0 revision. # By default, build the US 1.0 revision.
@ -159,7 +143,6 @@ test-all: build-all
all: build-all test-all all: build-all test-all
clean: clean:
rm -f $(obj)
rm -f $(games) rm -f $(games)
rm -f $(games:.gbc=.o) rm -f $(games:.gbc=.o)
rm -f $(games:.gbc=.map) rm -f $(games:.gbc=.map)