-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
138 lines (107 loc) · 3.43 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
CACHE_DIR := .cache_dir
$(shell mkdir -p $(CACHE_DIR) > /dev/null)
TOOL_DIR := Tools
LIB_DIR := $(TOOL_DIR)/FE-CLib-Mokha
FE8_GBA := fe8.gba
FE8_REF := $(LIB_DIR)/reference/fireemblem8.ref.s
FE8_SYM := $(LIB_DIR)/reference/fireemblem8.sym
EXT_REF := usr-defined.ref.s
MAIN := main.event
FE8_CHX := fe8-chax.gba
CLEAN_FILES :=
CLEAN_DIRS := $(CACHE_DIR)
WIZARDRY_DIR := wizardry
SPRITANS_DIR :=
WRITANS_DIR :=
GAMEDATA_DIR :=
HACK_DIRS := $(WIZARDRY_DIR) $(SPRITANS_DIR) $(WRITANS_DIR) $(GAMEDATA_DIR)
# =========
# = Tools =
# =========
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif
PREFIX ?= arm-none-eabi-
CC := $(PREFIX)gcc
AS := $(PREFIX)as
OBJCOPY := $(PREFIX)objcopy
EA_DIR := $(TOOL_DIR)/EventAssembler
EA := $(EA_DIR)/ColorzCore$(EXE)
PARSEFILE := $(EA_DIR)/Tools/ParseFile$(EXE)
PORTRAITFORMATTER := $(EA_DIR)/Tools/PortraitFormatter$(EXE)
PNG2DMP := $(EA_DIR)/Tools/Png2Dmp$(EXE)
COMPRESS := $(EA_DIR)/Tools/compress$(EXE)
LYN := $(EA_DIR)/Tools/lyn$(EXE) -longcalls
EA_DEP := $(EA_DIR)/ea-dep$(EXE)
# ========
# = Main =
# ========
MAIN_DEPS := $(shell $(EA_DEP) $(MAIN) -I $(EA_DIR) --add-missings)
$(FE8_CHX): $(MAIN) $(FE8_GBA) $(FE8_SYM) $(MAIN_DEPS)
@echo "[EA ] $@"
@cp -f $(FE8_GBA) $(FE8_CHX)
@$(EA) A FE8 -input:$(MAIN) -output:$(FE8_CHX) --nocash-sym || rm -f $(FE8_CHX)
@cat $(FE8_SYM) >> $(FE8_CHX:.gba=.sym)
CLEAN_FILES += $(FE8_CHX) $(FE8_CHX:.gba=.sym)
# ============
# = Wizardry =
# ============
INC_DIRS := include $(LIB_DIR)/include
INC_FLAG := $(foreach dir, $(INC_DIRS), -I $(dir))
ARCH := -mcpu=arm7tdmi -mthumb -mthumb-interwork
CFLAGS := $(ARCH) $(INC_FLAG) -Wall -Wextra -Wno-unused-parameter -O2 -mtune=arm7tdmi -mlong-calls
ASFLAGS := $(ARCH) $(INC_FLAG)
CDEPFLAGS = -MMD -MT "$*.o" -MT "$*.asm" -MF "$(CACHE_DIR)/$(notdir $*).d" -MP
SDEPFLAGS = --MD "$(CACHE_DIR)/$(notdir $*).d"
LYN_REF := $(CACHE_DIR)/lyn-ref.o
$(LYN_REF): $(FE8_REF) $(EXT_REF)
@echo "[AS ] $@"
@cp $(FE8_REF) $(LYN_REF:.o=.s)
@cat $(EXT_REF) >> $(LYN_REF:.o=.s)
@$(AS) $(LYN_REF:.o=.s) -o $@
%.lyn.event: %.o $(LYN_REF)
@echo "[LYN] $@"
@$(LYN) $< $(LYN_REF) > $@
%.dmp: %.o
@echo "[GEN] $@"
@$(OBJCOPY) -S $< -O binary $@
%.o: %.s
@echo "[AS ] $@"
@$(AS) $(ASFLAGS) $(SDEPFLAGS) -I $(dir $<) $< -o $@
%.o: %.c
@echo "[CC ] $@"
@$(CC) $(CFLAGS) $(CDEPFLAGS) -g -c $< -o $@
%.asm: %.c
@echo "[CC ] $@"
@$(CC) $(CFLAGS) $(CDEPFLAGS) -S $< -o $@ -fverbose-asm
# Avoid make deleting objects it thinks it doesn't need anymore
# Without this make may fail to detect some files as being up to date
.PRECIOUS: %.o;
-include $(wildcard $(CACHE_DIR)/*.d)
CFILES := $(shell find $(HACK_DIRS) -type f -name '*.c')
CLEAN_FILES += $(CFILES:.c=.o) $(CFILES:.c=.asm) $(CFILES:.c=.dmp) $(CFILES:.c=.lyn.event)
SFILES := $(shell find $(HACK_DIRS) -type f -name '*.s')
CLEAN_FILES += $(SFILES:.s=.o) $(SFILES:.s=.dmp) $(SFILES:.s=.lyn.event)
# ============
# = Spritans =
# ============
%.4bpp: %.png
@echo "[GEN] $@"
@$(PNG2DMP) $< -o $@
%.gbapal: %.png
@echo "[GEN] $@"
@$(PNG2DMP) $< -po $@ --palette-only
%.lz: %
@echo "[LZ ] $@"
@$(COMPRESS) $< $@
PNG_FILES := $(shell find $(HACK_DIRS) -type f -name '*.png')
CLEAN_FILES += $(PNG_FILES:.png=.gbapal) $(PNG_FILES:.png=.4bpp) $(PNG_FILES:.png=.4bpp.lz)
# ==============
# = MAKE CLEAN =
# ==============
clean:
@rm -f $(CLEAN_FILES)
@rm -rf $(CLEAN_DIRS)
@echo "[RM] $(notdir $(CLEAN_FILES)) $(notdir $(CLEAN_DIRS))"