-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
142 lines (104 loc) · 2.71 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Vulcalien's GBA Makefile
# === Detect OS ===
ifeq ($(OS),Windows_NT)
CURRENT_OS := WINDOWS
else
CURRENT_OS := UNIX
endif
# === Basic Info ===
OUT_FILENAME := minicraft
SRC_DIR := src
OBJ_DIR := obj
BIN_DIR := bin
SRC_SUBDIRS := scene entity
RES_DIR := res
RES_OUT_DIRS := src/res src/res/images src/res/palettes src/res/sounds
# === Compilation ===
CPPFLAGS := -Iinclude -MMD -MP
CFLAGS := -O3 -fomit-frame-pointer -marm -mcpu=arm7tdmi\
-Wall -pedantic
ASFLAGS := -mcpu=arm7tdmi
LDFLAGS := -nostartfiles -Tlib/libsimplegba/lnkscript
LDLIBS :=
# libsimplegba
CPPFLAGS += -Ilib/libsimplegba/include
LDFLAGS += -Llib/libsimplegba/bin
LDLIBS += -lsimplegba
ifeq ($(CURRENT_OS),UNIX)
CC := arm-none-eabi-gcc
AS := arm-none-eabi-as
OBJCOPY := arm-none-eabi-objcopy
EMULATOR := mgba-qt
else ifeq ($(CURRENT_OS),WINDOWS)
CC :=
AS :=
OBJCOPY :=
EMULATOR :=
endif
# if LINK_MAP=1, generate a link map
ifeq ($(LINK_MAP),1)
LDFLAGS += -Wl,-Map=$(BIN_DIR)/output.map
endif
# === Extensions & Commands ===
OBJ_EXT := o
ELF_EXT := elf
GBA_EXT := gba
ifeq ($(CURRENT_OS),UNIX)
MKDIR := mkdir -p
RM := rm -rfv
else ifeq ($(CURRENT_OS),WINDOWS)
MKDIR := mkdir
RM := rmdir /Q /S
endif
# === Resources ===
# list of source file extensions
SRC_EXT := s c
# list of source directories
SRC_DIRS := $(SRC_DIR)\
$(foreach SUBDIR,$(SRC_SUBDIRS),$(SRC_DIR)/$(SUBDIR))
# list of source files
SRC := $(foreach DIR,$(SRC_DIRS),\
$(foreach EXT,$(SRC_EXT),\
$(wildcard $(DIR)/*.$(EXT))))
# list of object directories
OBJ_DIRS := $(SRC_DIRS:%=$(OBJ_DIR)/%)
# list of object files
OBJ := $(SRC:%=$(OBJ_DIR)/%.$(OBJ_EXT))
# output files
OUT_ELF := $(BIN_DIR)/$(OUT_FILENAME).$(ELF_EXT)
OUT := $(BIN_DIR)/$(OUT_FILENAME).$(GBA_EXT)
# === Targets ===
.PHONY: all run build clean
all: build-deps build
run:
$(EMULATOR) $(OUT)
build: $(OUT)
clean: clean-deps
@$(RM) $(BIN_DIR) $(OBJ_DIR) $(RES_OUT_DIRS)
# generate GBA file
$(OUT): $(OUT_ELF)
$(OBJCOPY) -O binary $^ $@
# generate ELF file
$(OUT_ELF): $(OBJ) | $(BIN_DIR)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
# compile .s files
$(OBJ_DIR)/%.s.$(OBJ_EXT): %.s | $(OBJ_DIRS)
$(AS) $(ASFLAGS) -o $@ $<
# compile .c files
$(OBJ_DIR)/%.c.$(OBJ_EXT): %.c | $(OBJ_DIRS)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
# create directories
$(BIN_DIR) $(OBJ_DIRS) $(RES_OUT_DIRS):
$(MKDIR) "$@"
.PHONY: build-deps clean-deps
build-deps:
$(MAKE) -C lib/libsimplegba build
clean-deps:
$(MAKE) -C lib/libsimplegba clean
.PHONY: res
res: $(RES_OUT_DIRS)
tools/convert-resources "$(RES_DIR)/resources.json"
.PHONY: release
release:
tools/release "$(OUT)"
-include $(OBJ:.$(OBJ_EXT)=.d)