-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
60 lines (46 loc) · 2.23 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
PATH := $(DEVKITARM)/bin:$(DEVKITPRO)/tools/bin:$(PATH)
ROM := md
# Collect all source/data files to be built
SRC = $(wildcard src/*.cpp) $(wildcard src/**/*.cpp)
GFX = $(wildcard gfx/*.png)
# C files will depend on headers generated for our image data
GFXH = $(GFX:gfx/%.png=build/%.h)
OFILES = $(SRC:src/%.cpp=build/%.o)
# .d files that are generated by the compiler to show what .cpp files depend on what .h files
# so that when a header file is updated, we know which .cpp files need recompiling
DFILES = $(OFILES:.o=.d)
# Both C files and gfx data will need to be compiled into the final rom
OFILES += $(GFX:gfx/%.png=build/%.o)
# Stop make removing generated .h files after build
.PRECIOUS: build/%.h
# Converts our .elf file into a proper nds rom using ndstool, setting some metadata options.
build/$(ROM).nds: build/$(ROM).elf
ndstool -c ./build/$(ROM).nds -9 ./build/$(ROM).elf \
-b /opt/devkitpro/libnds/icon.bmp "$(ROM);built with devkitARM;http://devkitpro.org"
# Links together all our object files into a '.elf' file, a kind of raw binary with our code.
build/$(ROM).elf: $(OFILES)
arm-none-eabi-g++ -specs=ds_arm9.specs -g -mthumb -mthumb-interwork -Wl,-Map,build/$(ROM).map \
$(OFILES) -L/opt/devkitpro/libnds/lib -lnds9 -o ./build/$(ROM).elf
# grit outputs .s (assembly) files which must also be compiled into .o files.
%.o: %.s
arm-none-eabi-g++ -x assembler-with-cpp -g -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s -c $< -o $@
# Compiles any cpp file into a .o file to be linked. the generation of gfx headers must happen first.
build/%.o: src/%.cpp | build/ $(GFXH)
@mkdir -p $(@D)
arm-none-eabi-g++ -g -Wall -O2 \
-MMD -MP \
-march=armv5te -mtune=arm946e-s -mthumb -mthumb-interwork \
-fomit-frame-pointer -ffast-math -fno-rtti -fno-exceptions \
-I/opt/devkitpro/libnds/include -Ibuild -Isrc -DARM9 \
-c $< -o $@
# PNG files must be converted into both .h and .s files for both the definitions and data to be referenced elsewhere
build/%.s build/%.h: gfx/%.png gfx/%.png.grit | build/
grit $< -ff $<.grit -o $(basename $@)
build/:
mkdir build
run: build/$(ROM).nds
~/gamedev/melonDS build/$(ROM).nds
clean:
rm -rf build
# '-include' will add in our .d files without erroring if one does not exist
-include $(DFILES)