-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (62 loc) · 2.18 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
PRODUCT_NAME = Project
# You probably won't need to touch anything below here!!!
# The one exception is the cleanup stuff.
SOURCES = $(wildcard *.c)
ASMSOURCES = $(wildcard *.asm)
AUDIOSOURCES = $(wildcard *.wav)
DKPATH = /opt/devkitpro
FIND = find
COPY = cp -r
# --- File Names
ELF_NAME = $(PRODUCT_NAME).elf
ROM_NAME = $(PRODUCT_NAME).gba
BIN_NAME = $(PRODUCT_NAME)
#MODEL = -mthumb-interwork -mthumb
MODEL = -mthumb-interwork -marm -mlong-calls #This makes interrupts work
SPECS = -specs=gba.specs
# --- Archiver
AS = $(DKPATH)/devkitARM/bin/arm-none-eabi-as
ASFLAGS = -mthumb-interwork
# --- Compiler
CC = $(DKPATH)/devkitARM/bin/arm-none-eabi-gcc
CFLAGS = $(MODEL) -O2 -Wall -pedantic -Wextra -std=c99 -save-temps -D_ROM=$(ROM_NAME)
# --- Linker
LD = $(DKPATH)/devkitARM/bin/arm-none-eabi-gcc
LDFLAGS = $(SPECS) $(MODEL) -lm
# --- Object/Executable Packager
OBJCOPY = $(DKPATH)/devkitARM/bin/arm-none-eabi-objcopy
OBJCOPYFLAGS = -O binary
# --- ROM Fixer
GBAFIX = $(DKPATH)/tools/bin/gbafix
# --- Delete
RM = rm -f
ASMOBJECTS = $(ASMSOURCES:.asm=.o)
AUDIOOBJECTS = $(AUDIOSOURCES:.wav=.c)
AUDIOHEADERS = $(AUDIOSOURCES:.wav=.h)
COBJECTS = $(SOURCES:.c=.o) $(AUDIOSOURCES:.wav=.o)
OBJECTS = $(COBJECTS) $(ASMOBJECTS)
# --- Main build target
all : audio build
build : $(ROM_NAME)
# --- Build .elf file into .gba ROM file
$(ROM_NAME) : $(ELF_NAME)
$(OBJCOPY) $(OBJCOPYFLAGS) $(ELF_NAME) $(ROM_NAME)
$(GBAFIX) $(ROM_NAME)
# --- Build .o files into .elf file
$(ELF_NAME) : $(OBJECTS)
$(LD) $^ $(LDFLAGS) -o $@
# -- Build .asm files into .o files
$(ASMOBJECTS) : %.o : %.asm
$(AS) $(ASFLAGS) $< -o $@
# -- Build .c files into .o files
$(COBJECTS) : %.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
# -- Build .wav files into .c and .h files
$(AUDIOOBJECTS) : %.c : %.wav
wav2c $< $@ $*
$(AUDIOHEADERS) : %.h : %.c
clean:
$(RM) $(ROM_NAME) $(ELF_NAME) $(BIN_NAME)
$(RM) $(AUDIOOBJECTS) $(AUDIOHEADERS)
$(RM) *.o *.i *.s
audio: $(AUDIOOBJECTS)