-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
83 lines (65 loc) · 2.47 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
# No SPACES AFTER THE NAME.
PROGNAME = HelmetMan
SRCDIR = src
BINDIR = bin
# We use globstar in most places, this list is for mkbin
# Pending future cleanup?
SRC_SUBDIRS = assets game render tonc_lib
# The object files you want to compile into your program
CFILES = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/**/*.c) $(SRCDIR)/bios.c
HFILES = $(wildcard $(SRCDIR)/*.h) $(wildcard $(SRCDIR)/**/*.h)
TOOLDIR = /usr/local/cs2110-tools
ARMLIB = $(TOOLDIR)/arm-thumb-eabi/lib
CFLAGS = -Wall -Werror -std=c99 -pedantic -Wextra
CFLAGS += -mthumb-interwork -mlong-calls -nostartfiles -MMD -MP -I $(TOOLDIR)/include
LDFLAGS = -L $(TOOLDIR)/lib \
-L $(TOOLDIR)/lib/gcc/arm-thumb-eabi/4.4.1/thumb \
-L $(ARMLIB) \
--script $(ARMLIB)/arm-gba.ld
CDEBUG = -O2 -g -DDEBUG # omitting the O2 makes the HUD tear
CRELEASE = -O2 -DRELEASE
CC = $(TOOLDIR)/bin/arm-thumb-eabi-gcc
AS = $(TOOLDIR)/bin/arm-thumb-eabi-as
LD = $(TOOLDIR)/bin/arm-thumb-eabi-ld
OBJCOPY = $(TOOLDIR)/bin/arm-thumb-eabi-objcopy
GDB = $(TOOLDIR)/bin/arm-thumb-eabi-gdb
OFILES = $(CFILES:$(SRCDIR)/%.c=$(BINDIR)/%.o)
GAME_ELF = $(BINDIR)/$(PROGNAME).elf
all : debug vba
debug : CFLAGS += $(CDEBUG)
debug: $(PROGNAME).gba
@echo "[FINISH] Created $(PROGNAME).gba"
.PHONY : all clean mkbin
release : CFLAGS += $(CRELEASE)
release : $(PROGNAME).gba
@echo "[FINISH] Created release $(PROGNAME).gba"
$(PROGNAME).gba : mkbin $(GAME_ELF)
@echo "[LINK] Linking objects together to create $(PROGNAME).gba"
@$(OBJCOPY) -O binary $(GAME_ELF) $(PROGNAME).gba
$(GAME_ELF) : $(BINDIR)/crt0.o $(OFILES)
@$(LD) $(LDFLAGS) -o $(GAME_ELF) $^ -lgcc -lc -lgcc $(LDDEBUG)
@rm -f *.d
$(BINDIR)/crt0.o : $(ARMLIB)/crt0.s
@$(AS) -mthumb-interwork $^ -o $(BINDIR)/crt0.o
$(BINDIR)/%.o : $(SRCDIR)/%.c
@echo "[COMPILE] Compiling $<"
@$(CC) $(CFLAGS) -c $< -o $@
$(BINDIR)/%.o : $(SRCDIR)/%.s
@echo "[ASSEMBLE] Assembling $<"
@$(AS) $< -o $@ -mthumb -mthumb-interwork
clean :
@echo "[CLEAN] Removing all compiled files"
@rm -rf $(BINDIR) $(PROGNAME).gba
vba : CFLAGS += $(CRELEASE)
vba : $(PROGNAME).gba
@echo "[EXECUTE] Running Emulator VBA-M"
@vbam $(VBAOPT) $(PROGNAME).gba > /dev/null 2> /dev/null
# Create all the necessary subdirectories from src
# TODO: make this cleaner
mkbin :
$(foreach d,$(SRC_SUBDIRS), mkdir -p $(BINDIR)/$(d);)
med : CFLAGS += $(CRELEASE)
med : $(PROGNAME).gba
@echo "[EXECUTE] Running emulator Mednafen"
@mednafen $(PROGNAME).gba > /dev/null 2>&1
-include $(CFILES:%.c=%.d)