-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
89 lines (72 loc) · 2.63 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
.SUFFIXES:
################################################
# #
# CONSTANT DEFINITIONS #
# #
################################################
# Directory constants
SRCDIR := src
BINDIR := bin
OBJDIR := obj
DEPDIR := dep
RESDIR := res
# Use this to compile using a local copy of RGBDS
RGBDS :=
RGBASM := $(RGBDS)rgbasm
RGBLINK := $(RGBDS)rgblink
RGBFIX := $(RGBDS)rgbfix
RGBGFX := $(RGBDS)rgbgfx
ROMNAME := kirbydreamland2
ROMEXT := gb
ROM = $(BINDIR)/$(ROMNAME).$(ROMEXT)
BASE := $(SRCDIR)/baserom.gb
# Argument constants
INCDIRS = $(SRCDIR)/ $(SRCDIR)/include/
WARNINGS = all extra
ASFLAGS = -h $(addprefix -i,$(INCDIRS)) $(addprefix -W,$(WARNINGS))
LDFLAGS = -d
# The list of "root" ASM files that RGBASM will be invoked on
SRCS = $(wildcard $(SRCDIR)/main.asm)
################################################
# #
# TARGETS #
# #
################################################
# `all` (Default target): build the ROM
all: $(ROM) compare
.PHONY: all
# `clean`: Clean temp and bin files
clean:
rm -rf $(BINDIR)
rm -rf $(OBJDIR)
rm -rf $(DEPDIR)
rm -rf $(RESDIR)
.PHONY: clean
# `rebuild`: Build everything from scratch
# It's important to do these two in order if we're using more than one job
rebuild:
$(MAKE) clean
$(MAKE) all
.PHONY: rebuild
compare: $(BASE) $(ROM)
cmp $^
###############################################
# #
# COMPILATION #
# #
###############################################
# How to build a ROM
$(BINDIR)/%.$(ROMEXT) $(BINDIR)/%.sym $(BINDIR)/%.map: $(patsubst $(SRCDIR)/%.asm,$(OBJDIR)/%.o,$(SRCS))
@mkdir -p $(@D)
$(RGBLINK) $(LDFLAGS) -m $(BINDIR)/$*.map -n $(BINDIR)/$*.sym -o $(BINDIR)/$*.$(ROMEXT) $^ \
&& $(RGBFIX) -v $(BINDIR)/$*.$(ROMEXT)
# `.mk` files are auto-generated dependency lists of the "root" ASM files, to save a lot of hassle.
# Also add all obj dependencies to the dep file too, so Make knows to remake it
# Caution: some of these flags were added in RGBDS 0.4.0, using an earlier version WILL NOT WORK
# (and produce weird errors)
$(OBJDIR)/%.o $(DEPDIR)/%.mk: $(SRCDIR)/%.asm
@mkdir -p $(patsubst %/,%,$(dir $(OBJDIR)/$* $(DEPDIR)/$*))
$(RGBASM) $(ASFLAGS) -M $(DEPDIR)/$*.mk -MG -MP -MQ $(OBJDIR)/$*.o -MQ $(DEPDIR)/$*.mk -o $(OBJDIR)/$*.o $<
ifneq ($(MAKECMDGOALS),clean)
-include $(patsubst $(SRCDIR)/%.asm,$(DEPDIR)/%.mk,$(SRCS))
endif