-
Notifications
You must be signed in to change notification settings - Fork 3
/
nes.mk
82 lines (68 loc) · 2.97 KB
/
nes.mk
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
80
81
82
override CAFLAGS += -g
LDFLAGS =
VPATH = build
build:
mkdir build
build/%.o: %.s Makefile | build
ca65 $(CAFLAGS) --create-dep [email protected] $< -o $@
build/%: %.cfg
ld65 $(LDFLAGS) -Ln $(basename $@).lbl --dbgfile $(basename $@).dbg -o $@ -C $< $(filter %.o,$^)
build/%.ips.cfg: ips-segments.awk
od65 --dump-options $(filter %.o,$^) | grep '"ips:' | sed -E 's/^ +Data: *"ips: (.*)"$$/\1/' | sort -n | awk -f ips-segments.awk > $@
build/%.nes: build/%.ips
# Second prerequisite is assumed to be a .nes source
# If the first time fails, run it a second time to display output
flips --apply $< $(word 2,$^) $@ > /dev/null || flips --apply $< $(word 2,$^) $@
flips --create $(word 2,$^) $@ build/$*.dist.ips > /dev/null
build/%: %.ips
# Second prerequisite is assumed to be source
# If the first time fails, run it a second time to display output
flips --apply $< $(word 2,$^) $@ > /dev/null || flips --apply $< $(word 2,$^) $@
flips --create $(word 2,$^) $@ build/$*.dist.ips > /dev/null
build/%.chrs/fake: %.chr | build
[ -d build/$*.chrs ] || mkdir build/$*.chrs
# split -x added in coreutils 8.27
split -d -b 16 -a 3 $< build/$*.chrs/
cd build/$*.chrs/ && for X in $$(seq 0 255); do mv $$(printf "%03d %02x" $$X $$X) 2> /dev/null || break; done
touch $@
build/%.rle: % rle-enc.awk | build
# 'basenc --base16 -w2' and 'basenc --base16 -d' would also work, but
# basenc isn't as widely available as xxd since it was added in
# coreutils 8.31
xxd -c1 -p $< | LC_ALL=C awk -f rle-enc.awk | xxd -r -p > $@
build/%.rle.stripe: % stripe-enc.awk | build
# 'basenc --base16 -w2' and 'basenc --base16 -d' would also work, but
# basenc isn't as widely available as xxd since it was added in
# coreutils 8.31
xxd -c1 -p $< | LC_ALL=C awk -f stripe-enc.awk | xxd -r -p > $@
build/%.s: %.bin %.info Makefile | build
# Strip off the first two lines of header, which contain variable
# information; they cause merge conflicts
da65 -i $(word 2,$^) $< | tail -n +3 > $@
da65 -i $(word 2,$^) --comments 2 $< > $(basename $@).v2.s
clean:
[ ! -d build/ ] || rm -r build/
.PHONY: clean
.SUFFIXES:
ifneq "$(V)" "1"
.SILENT:
endif
include $(wildcard build/*.d)
.SECONDEXPANSION:
build/%: %.diff $$(wildcard build/diffhead-$$*)
# Last prerequisite is assumed to be basefile
###
# Sync diffhead and diff for manual edits
if [ build/diffhead-$* -nt $@ ]; then \
diff -u --label orig --label mod -U 5 -F : build/diffbase-$* build/diffhead-$* > [email protected] \
|| [ $$? -eq 1 ] && mv [email protected] $<; \
elif [ $< -nt $@ -a -e build/diffbase-$* ]; then \
cp build/diffbase-$* [email protected] && patch -s [email protected] $< && mv [email protected] build/diffhead-$*; \
fi
# Now do build-triggered updates
if [ ! -e build/diffbase-$* -o $(word $(words $^),$^) -nt build/diffbase-$* ]; then \
cp $(word $(words $^),$^) [email protected] && \
cp $(word $(words $^),$^) [email protected] && patch -s [email protected] $< && \
mv [email protected] build/diffbase-$* && mv [email protected] build/diffhead-$*; \
fi
echo "; DO NOT MODIFY. Modify diffhead-$* instead" | cat - build/diffhead-$* > $@