-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
70 lines (54 loc) · 1.91 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
# Name of the ROM.
NAME := 10 PRINT
# Version number of the ROM. Only one byte allowed so no SemVer. :(
VERSION := 0x02
# Path to SD Card, used by the `sd` target.
SD_CARD_PATH ?= /Volumes/DMG/
# Current operating system.
OPERATING_SYSTEM := $(shell uname -s)
ifeq ($(OPERATING_SYSTEM), Darwin)
SED_FLAGS := -i '' -E
else
SED_FLAGS := -i -r
endif
# Phony targets is "recipes" and not the name of a file.
.PHONY: all clean realclean bgb sd sloc check
# Build Game Boy ROM and generate annotated source in Markdown format.
all: 10-print.gb 10-pretty.md rom-data.js
# Build Game Boy ROM.
10-print.gb: 10-print.o
rgblink -d -t -n "$(@:.gb=.sym)" -m "$(@:.gb=.map)" -o "$@" "$<"
rgbfix -j -p 0x0 -t "$(NAME)" -n "$(VERSION)" -v "$@"
# Assamble object file from source.
%.o: %.asm
rgbasm -E -v -o "$@" "$<"
# Generate annotated source in Markdown format for easy reading on GitHub.
10-pretty.md: 10-print.asm
tr '\n' '@' < "$<" > "$@"
sed $(SED_FLAGS) 's/@@;/@```@@;/g' "$@"
sed $(SED_FLAGS) 's/;(@[^;])/@```assembly\1/g' "$@"
tr '@' '\n' < "$@" >> tempfile.md
mv tempfile.md "$@"
sed $(SED_FLAGS) 's/^; *//g' "$@"
# Generates a JavaScript array representation of the ROM.
rom-data.js: 10-print.gb
xxd -i < "$<" | tr -d '\n' > "$@"
sed $(SED_FLAGS) 's/^[ ]+(.+)$$/var romData = \[\1\];/g' "$@"
# Remove (almost) all generated files.
clean:
rm -f *.gb *.map *.o *.sym *.js
# Remove all generated files (including pretty source).
realclean: clean
rm -f "10-pretty.md"
# Start ROM in the BGB Game Boy emulator.
bgb: 10-print.gb
bgb "$<"
# Copy ROM to SD Card.
sd: 10-print.gb
until cp "$<" "$(SD_CARD_PATH)" && diskutil unmount "$(SD_CARD_PATH)"; do sleep 3; done
# Count number of source code lines, excluding comments.
sloc: 10-print.asm
grep -cvE "^;|^$$" "$<"
# Verify that it's a Game Boy ROM of correct size.
check: 10-print.gb
file "$<" | grep -iE "(Game Boy|GameBoy).*$(NAME).*256Kbit"