-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
117 lines (93 loc) · 4.51 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# This attempts to build the game for you.
# Note: This is a pretty poor excuse for a makefile. I'd look elsewhere for better examples.
# Prequisites:
# - A few fairly standard unix applications available; Gow/Cygwin installed for Windows.
# - ca65 binaries in the tools folder
### USER EDITABLE STUFF STARTS HERE
ROM_NAME=lava_lamp
OBJECTS_TO_BUILD=$(ROM_NAME).c bin/build_info.h levels/processed/lvl1_tiles.asm bin/crt0.o bin/$(ROM_NAME).o bin/title.o bin/level.o bin/hud.o bin/sprite.o bin/movement.o
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
MAIN_COMPILER=./tools/cc65/bin/cc65
MAIN_ASM_COMPILER=./tools/cc65/bin/ca65
MAIN_LINKER=./tools/cc65/bin/ld65
MAIN_EMULATOR=tools/fceux/fceux
DEBUG_EMULATOR=tools/nintendulatordx/nintendulator
SPACE_CHECKER=tools/nessc/nessc
LEVEL_CONVERTER=node tools/level-converter
CONFIG_FILE=$(ROOT_DIR)/cfg/game.cfg
ifeq ($(OS),Windows_NT)
TEXT2DATA=tools/famitone2/tools/text2data
NSF2DATA=tools/famitone2/tools/nsf2data
BUILD_DATE=$(shell echo %DATE% %TIME:~0,5%)
BUILD_DATE_ONLY=$(shell echo %DATE:~4%)
# NOTE: I cheated and hard-coded my timezone here :( No good way to get it on Windows
BUILD_TIME_ONLY=$(shell echo %TIME:~0,5% EDT)
else
TEXT2DATA=echo Music compilation can only be done under Windows. There is not a good linux/osx port. Exiting without doing anything.
NSF2DATA=echo Sound effect compilation can only be done under Windows. There is not a good linux/osx port. Exiting without doing anything.
BUILD_DATE=$(shell date +"%a %m/%d/%Y %H:%M")
BUILD_DATE_ONLY=$(shell date +"%m/%d/%Y")
BUILD_TIME_ONLY=$(shell date +"%H:%M %Z")
endif
### USER EDITABLE STUFF ENDS HERE
.PHONY: clean fceux run nintendulator debug space_check .FORCE
.FORCE:
# Empty target used to regenerate constants every single time.
all: $(ROM_NAME).nes
bin/%.s: %.c
$(MAIN_COMPILER) -Oi $< --add-source --include-dir ./tools/cc65/include -o $@
bin/%.s: src/%.c
$(MAIN_COMPILER) -Oi $< --add-source --include-dir ./tools/cc65/include -o $@
bin/crt0.o: lib/crt0.asm sound/sfx.s sound/music.s lib/boilerplate.asm
$(MAIN_ASM_COMPILER) lib/crt0.asm -o bin/crt0.o
sound/sfx.s: sound/sfx.nsf
$(NSF2DATA) sound/sfx.nsf -ntsc -ca65
sound/music.s: sound/music.txt
$(TEXT2DATA) sound/music.txt -ca65 -ntsc
levels/processed/%_tiles.asm: levels/%.json
$(LEVEL_CONVERTER) $<
bin/%.o: bin/%.s
$(MAIN_ASM_COMPILER) $<
bin/build_info.h: .FORCE
# Outputs a bunch of build stats info build_info.h. Use it in your project to show details about the build in-game!
@printf "// WARNING: This file is autogenerated by your makefile. Never edit it by hand.\n\n" > bin/build_info.h
@printf "#define BUILD_DATE \"$(BUILD_DATE)\"\n" >> bin/build_info.h
@printf "#define BUILD_DATE_ONLY \"$(BUILD_DATE_ONLY)\"\n" >> bin/build_info.h
@printf "#define BUILD_TIME_ONLY \"$(BUILD_TIME_ONLY)\"\n" >> bin/build_info.h
@printf "#define COMMIT_COUNT $(shell git rev-list --count HEAD)\n" >> bin/build_info.h
@printf "#define COMMIT_COUNT_STR \"$(shell git rev-list --count HEAD)\"\n" >> bin/build_info.h
@printf "#define GIT_COMMIT_ID \"$(shell git rev-parse HEAD)\"\n" >> bin/build_info.h
@printf "#define GIT_COMMIT_ID_SHORT \"$(shell git rev-parse --short HEAD)\"\n" >> bin/build_info.h
# We also can get some info from environment variables in CircleCI... otherwise we kinda have to improvise a little.
ifeq ($(CIRCLECI), true)
@printf "#define REPOSITORY_NAME \"$(value CIRCLE_PROJECT_REPONAME)\"\n" >> bin/build_info.h
@printf "#define GIT_BRANCH \"$(value CIRCLE_BRANCH)\"\n" >> bin/build_info.h
@printf "#define GIT_TAG \"$(value CIRCLE_TAG)\"\n" >> bin/build_info.h
@printf "#define BUILD_NUMBER $(value CIRCLE_BUILD_NUM)\n" >> bin/build_info.h
@printf "#define BUILD_NUMBER_STR \"$(value CIRCLE_BUILD_NUM)\"\n" >> bin/build_info.h
else
@printf "#define REPOSITORY_NAME \"$(ROM_NAME)\"\n" >> bin/build_info.h
@printf "#define GIT_BRANCH \"$(shell git symbolic-ref --short HEAD)\"\n" >> bin/build_info.h
@printf "#define GIT_TAG \"\"\n" >> bin/build_info.h
@printf "#define BUILD_NUMBER 0\n" >> bin/build_info.h
@printf "#define BUILD_NUMBER_STR \"0\"\n" >> bin/build_info.h
endif
$(ROM_NAME).nes: $(OBJECTS_TO_BUILD)
$(MAIN_LINKER) -C $(CONFIG_FILE) -o $(ROM_NAME).nes bin/*.o lib/runtime.lib
fceux:
$(MAIN_EMULATOR) $(ROM_NAME).nes
run: fceux
nintendulator:
$(DEBUG_EMULATOR) $(ROM_NAME).nes
debug: nintendulator
space_check:
ifeq ($(OS),Windows_NT)
$(SPACE_CHECKER) $(ROM_NAME).nes
else
@echo "Space check is only available on Windows right now, sorry!"
endif
clean:
-rm -f *.nes
-rm -f *.o
-rm -f bin/*.o
-rm -f bin/*.s