-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
113 lines (81 loc) · 2.76 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
#!/usr/bin/env make
INPUT := snakewood.gba
INPUT_DECAPPED := snakewood_decapped.gba
OUTPUT := output.gba
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/base_tools
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif
SRC_FILES := $(shell find src -name "*.c")
ASM_FILES := $(shell find assembly -name "*.s")
SRC_OBJS := $(SRC_FILES:src/%.c=build/src/%.o)
ASM_OBJS := $(ASM_FILES:assembly/%.s=build/assembly/%.o)
OBJ_FILES ?= $(SRC_OBJS) $(ASM_OBJS)
CFLAGS = -Wall -std=c99 -O2 -Iinclude -g -mthumb -mthumb-interwork -specs=gba.specs -x c -c -Wparentheses -Wno-unused -Werror
AS := $(PREFIX)as
ASFLAGS := -mthumb -I assembly -I include
LD = $(PREFIX)ld
LDFLAGS = -i rom.ld -T linker.ld
ARMIPS := armips
ARMIPSFLAGS := -strequ INPUT_FILE $(INPUT_DECAPPED) -strequ OUTPUT_FILE $(OUTPUT)
ELFEDIT := tools/elfedit/elfedit$(EXE)
DECAP := tools/decap/decap$(EXE)
PREPROC := tools/preproc/preproc$(EXE)
SCANINC := tools/scaninc/scaninc$(EXE)
.DEFAULT_GOAL = all
MAKEFLAGS += --no-print-directory
.SUFFIXES:
.SECONDARY:
.DELETE_ON_ERROR:
.SECONDEXPANSION:
.PHONY: all clean tools clean_tools
ifeq (,$(filter-out all,$(MAKECMDGOALS)))
$(shell $(MAKE) tools > /dev/null)
include $(OBJ_FILES:%.o=%.d)
endif
all: $(OUTPUT)
@$(DECAP) $(INPUT) $(INPUT_DECAPPED)
@echo "$(DECAP) $(INPUT) $(INPUT_DECAPPED)"
@$(ARMIPS) $(ARMIPSFLAGS) main.asm -sym2 output.map
@echo "$(ARMIPS) <flags> main.asm -sym2 output.map"
$(OUTPUT): build/linked_processed.o
format:
@find . -not -path "./tools/*" -name *.c -o -not -path "./tools/*" -name *.h | xargs clang-format -i
@echo "Done."
tools:
@$(MAKE) -C tools/elfedit
@$(MAKE) -C tools/preproc
@$(MAKE) -C tools/scaninc
@$(MAKE) -C tools/decap
clean_tools:
@$(MAKE) -C tools/elfedit clean
@$(MAKE) -C tools/preproc clean
@$(MAKE) -C tools/scaninc clean
@$(MAKE) -C tools/decap clean
clean: clean_tools
rm -rf build
build/assembly/%.d: assembly/%.s
@mkdir -p $(dir $@)
@echo "build/assembly/$*.o : \\" > $@
@$(SCANINC) $< | awk '{print $$0 " \\"}' >> $@
build/assembly/%.o: assembly/%.s build/assembly/%.d
@echo "$(AS) <flags> -o $@ $<"
@$(PREPROC) $< charmap.txt | $(CC) -w -E - | $(AS) $(ASFLAGS) -o $@
build/src/%.d: src/%.c
@mkdir -p $(dir $@)
@echo "build/src/$*.o : \\" > $@
@$(SCANINC) -I include $< | awk '{print $$0 " \\"}' >> $@
build/src/%.o: src/%.c build/src/%.d
@echo "$(CC) <flags> -c $< -o $@"
@$(PREPROC) $< charmap.txt | $(CC) $(CFLAGS) -o $@ -
build/linked.o: $(OBJ_FILES) linker.ld rom.ld linker/**.ld
@mkdir -p build
@echo "$(LD) $(LDFLAGS) -Map build/linked.map -o $@ <objects> <libs>"
@$(LD) $(LDFLAGS) -Map build/linked.map -o $@ $(OBJ_FILES)
build/linked_processed.o: build/linked.o
@$(ELFEDIT) $< $@