-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
60 lines (43 loc) · 1.34 KB
/
Copy pathMakefile
File metadata and controls
60 lines (43 loc) · 1.34 KB
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
PROJECTS = gba-savedump gba-saveedit
ROMS = $(addsuffix .gba,$(PROJECTS))
ELFS = $(addsuffix .elf,$(PROJECTS))
BUILDDIR = build
TARGET_ROMS = $(addprefix $(BUILDDIR)/,$(ROMS))
TARGET_ELFS = $(addprefix $(BUILDDIR)/,$(ELFS))
TRIPLE = arm-none-eabi
CPU = arm7tdmi
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
AS = arm-none-eabi-as
OBJCOPY = arm-none-eabi-objcopy
CFLAGS = -c -g -O0 -Wall -Wextra -Werror -mthumb -mthumb-interwork -mcpu=$(CPU) -mtune=$(CPU) -ffast-math -fomit-frame-pointer -std=gnu11 -Iinclude
ASFLAGS = -c -mthumb -mthumb-interwork -g
ARFLAGS = -crs
LDFLAGS = -g -Lbuild/
LDSCRIPT = scripts/linker.ld
LIB_SRCS = $(wildcard lib/*.c lib/*.s)
LIB_OBJS = $(addprefix $(BUILDDIR)/,$(subst .c,.o,$(subst .s,.o,$(LIB_SRCS))))
.PHONY: all
all: $(TARGET_ROMS) | $(BUILDDIR)
$(BUILDDIR): $(BUILDDIR)/
$(BUILDDIR)/:
mkdir -p $(BUILDDIR)
$(TARGET_ROMS): %.gba: %.elf | $(BUILDDIR)
$(OBJCOPY) -O binary $< $@
define app_dependencies
endef
.SECONDEXPANSION:
$(TARGET_ELFS): $(BUILDDIR)/%.elf: $(LDSCRIPT) $(LIB_OBJS) $(BUILDDIR)/%/$$(subst .c,.o,$$(shell ls apps/%))
$(LD) -o $@ $(LDFLAGS) -Map=$(basename $@).map -T$^
$(BUILDDIR)/%.o: %.s
mkdir -p $(@D)
$(AS) -o $@ $(ASFLAGS) $<
$(BUILDDIR)/%.o: %.c
mkdir -p $(@D)
$(CC) -o $@ $(CFLAGS) $<
$(BUILDDIR)/%.o: apps/%.c
mkdir -p $(@D)
$(CC) -o $@ $(CFLAGS) $<
.PHONY: clean
clean:
rm -rf $(BUILDDIR)