-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
102 lines (77 loc) · 2.62 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
.SUFFIXES:
.PHONY: objects asmgen events bindmps clean
# making sure devkitARM exists and is set up
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
# including devkitARM tool definitions
include $(DEVKITARM)/base_tools
# setting up main dir
# we want to use an absolute path because EA's wd won't be here
ABS_MAIN_DIR := $(realpath .)
MAIN_DIR := .
# Setting C/ASM include directories up
INCLUDE_DIRS := $(MAIN_DIR)/src/libgbafe
INCFLAGS := $(foreach dir, $(INCLUDE_DIRS), -I "$(dir)")
# adding local binaries to path
PATH := $(abspath .)/bin:$(PATH)
# lyn library object
LYNLIB := $(MAIN_DIR)/src/libgbafe/fe8u.o
# setting up compilation flags
ARCH := -mcpu=arm7tdmi -mthumb -mthumb-interwork
CFLAGS := $(ARCH) $(INCFLAGS) -Wall -Os -mtune=arm7tdmi -fomit-frame-pointer -ffast-math -fno-jump-tables
ASFLAGS := $(ARCH) $(INCFLAGS)
# dependency generation flags for CC
CDEPFLAGS = -MD -MT $*.o -MT $*.asm -MF $*.d -MP
# Finding all possible source files (in src folder)
# CFILES := $(wildcard *.c)
# SFILES := $(wildcard *.s)
CFILES := $(shell find src/ -type f -name '*.c')
SFILES := $(shell find src/ -type f -name '*.s')
# listing possible object files
OFILES := $(CFILES:.c=.o) $(SFILES:.s=.o)
# listing possible generated asm files
ASMFILES := $(CFILES:.c=.asm)
# listing possible lyn event files
LYNFILES := $(OFILES:.o=.lyn.event)
# listing possible dmp files
DMPFILES := $(OFILES:.o=.dmp)
# listing possible dependency files
DEPFILES := $(CFILES:.c=.d)
# defining & making dependency directory
DEPSDIR := .MkDeps
$(shell mkdir -p $(DEPSDIR) > /dev/null)
# listing possible dependency files
DEPFILES := $(addprefix $(DEPSDIR)/, $(notdir $(CFILES:.c=.d)))
# dependency generation flags for CC
CDEPFLAGS = -MD -MT $*.o -MT $*.asm -MF $(DEPSDIR)/$(notdir $*).d -MP
# C to ASM rule
%.asm: %.c
@echo "$(notdir $<) => $(notdir $@)"
@$(CC) $(CFLAGS) $(CDEPFLAGS) -S $< -o $@ -fverbose-asm $(ERROR_FILTER)
# C to OBJ rule
%.o: %.c
@echo "$(notdir $<) => $(notdir $@)"
@$(CC) $(CFLAGS) $(CDEPFLAGS) -c $< -o $@ $(ERROR_FILTER)
# OBJ to DMP rule
%.dmp: %.o
@echo "$(notdir $<) => $(notdir $@)"
@$(OBJCOPY) -S $< -O binary $@
# OBJ to EVENT rule
%.lyn.event: %.o $(LYNLIB)
@echo "$(notdir $<) => $(notdir $@)"
@lyn $< $(LYNLIB) > $@
# ASM to OBJ
%.o: %.s
@echo "$(notdir $<) => $(notdir $@)"
@$(AS) $(ARCH) $< -o $@ $(ERROR_FILTER)
# "make all" phony targets
objects: $(OFILES);
asmgen: $(ASMFILES);
events: $(LYNFILES);
bindmps: $(DMPFILES)
# "Clean" target
clean:
@rm -f $(OFILES) $(ASMFILES) $(LYNFILES) $(DMPFILES) $(DEPFILES)
@echo done.
-include $(DEPFILES)