-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
79 lines (65 loc) · 2.87 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
.PHONY: all compare clean rom
.SUFFIXES:
.SUFFIXES: .asm .o .gbc .png .wav
.SECONDEXPANSION:
#These tell Make where our files are.
BASE_DIR := base
BUILD_DIR := build
TOOLS_DIR := tools
BASEROM := ${BASE_DIR}/baserom.gba
BUILDROM := ${BUILD_DIR}/baserom.gba
#This configuration is suitable for a single version project.
SRCS := $(shell find src -type f -name "*.asm")
SRCS_ARMIPS := ${SRCS}
PYTHON3 := $(shell tools/interpreters/python3.sh)
PYTHON2 := $(shell tools/interpreters/python2.sh)
PYTHONANY := $(shell tools/interpreters/pythonany.sh)
# Link objects together to build a rom.
all: rom compare
#TODO: fixup ROM headers?
rom: $(SRCS:%.asm=${BUILD_DIR}/%.sym)
# The compare target is a shortcut to check that the build matches the original
# roms exactly. This is for contributors to make sure a change didn't affect
# the contents of the rom. More thorough comparison can be made by diffing the
# output of hexdump -C against both roms.
compare: rom
@$(subst ^, ,$(join $(addprefix cmp^,$(BUILDROM)),$(patsubst %,^%;,$(BASEROM))))
# Remove files generated by the build process.
clean:
rm -r build
#Assemble source files into... er, nothing.
#armips has no object format and writes directly into BUILDROM. Hence we treat
#the symbol format as the build product, which is wrong but :/
$(SRCS:%.asm=${BUILD_DIR}/%.sym): $(BUILD_DIR)/%.sym : %.asm $$($$*_dep)
@echo "Assembling" $<
@mkdir -p $(dir $@)
@armips $< -sym2 $(@:.sym=.sym2) -sym $@
#This rule is needed if we want make to not die. It expects to see .inc files in
#the build directory now that we moved all resources there. We DO want to see
#.inc files as dependencies but I can't be arsed to fiddle with any more arcane
#makefile bullshit to get it to not prefix .inc files.
$(BUILD_DIR)/%.inc: %.inc
@mkdir -p $(dir $@)
@cp $< $@
#This rule exists to copy any baserom into the build directory.
#armips should always reference the built file directly in .open directives.
#Note that this rule requires your base ROMs filenames match your built ROMs.
$(BUILD_DIR)/%: $(BASE_DIR)/%
@mkdir -p $(dir $@)
@cp $< $@
#These rules cover resources. You may add more below, if you want.
#To include a resource, .incbin it's build path (e.g. build/src/someimage.2bpp)
#No resource rules are defined yet. They would look something like;
#$(BUILD_DIR)/%.color.2bpp $(BUILD_DIR)/%.color.gbcpal: %.color.png
# @echo "Building" $<
# @rm -f $@
# @mkdir -p $(dir $(BUILD_DIR)/$*.color.2bpp)
# @mkdir -p $(dir $(BUILD_DIR)/$*.gbcpal)
# @rgbgfx -d 2 -p $(BUILD_DIR)/$*.color.gbcpal -o $(BUILD_DIR)/$*.color.2bpp $<
#This final bit automatically scans for all includes and adds them as build
#dependencies to the objects.
DEPENDENCY_SCAN_EXIT_STATUS := $(shell $(PYTHONANY) $(TOOLS_DIR)/scan_armips_includes.py $(SRCS) > ${BUILD_DIR}/dependencies.d; echo $$?)
ifneq ($(DEPENDENCY_SCAN_EXIT_STATUS), 0)
$(error Dependency scan failed)
endif
include ${BUILD_DIR}/dependencies.d