-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
61 lines (46 loc) · 1.93 KB
/
Copy pathMakefile
File metadata and controls
61 lines (46 loc) · 1.93 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
61
TARGET := game
BUILD := build
SOURCES := source
INCLUDE := include
CC := arm-none-eabi-gcc
AS := arm-none-eabi-gcc
OBJCOPY := arm-none-eabi-objcopy
ARCH := -mcpu=arm7tdmi -mtune=arm7tdmi
CFLAGS := $(ARCH) -mthumb -mthumb-interwork -O2 -Wall -Wextra \
-ffreestanding -fno-builtin -DGBA_BUILD -I$(INCLUDE)
ASFLAGS := $(ARCH) -mthumb-interwork -x assembler-with-cpp
# -lgcc: software integer division/64-bit helpers (ARM7TDMI has no divider)
LDFLAGS := $(ARCH) -mthumb -mthumb-interwork -T gba.ld -nostartfiles -nostdlib -Wl,-Map,$(BUILD)/$(TARGET).map
LDLIBS := -lgcc
C_FILES := $(wildcard $(SOURCES)/*.c)
S_FILES := $(SOURCES)/crt0.s $(filter-out $(SOURCES)/crt0.s,$(wildcard $(SOURCES)/*.s))
OBJS := $(patsubst $(SOURCES)/%.c,$(BUILD)/%.o,$(C_FILES)) \
$(patsubst $(SOURCES)/%.s,$(BUILD)/%.o,$(S_FILES))
.PHONY: all clean run host model
all: $(BUILD)/$(TARGET).gba
# regenerate source/model_data.c + include/model_data.h from the weights
model:
python3 tools/export_model.py model/stories260K.bin model/tok512.bin .
# native build of the same engine, for fast testing (host/test_llm.c)
host: | $(BUILD)
gcc -O2 -Wall -I$(INCLUDE) host/test_llm.c $(SOURCES)/llm.c $(SOURCES)/model_data.c -o $(BUILD)/host_llm
$(BUILD)/%.o: $(SOURCES)/%.c | $(BUILD)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD)/%.o: $(SOURCES)/%.s | $(BUILD)
$(AS) $(ASFLAGS) -c $< -o $@
$(BUILD)/$(TARGET).elf: $(OBJS) gba.ld
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
# gbafix (vendored from devkitPro gba-tools) embeds the Nintendo logo and
# fixes the header checksums -- required for the ROM to boot on real hardware.
$(BUILD)/gbafix: tools/gbafix.c | $(BUILD)
cc -O2 -o $@ $<
$(BUILD)/$(TARGET).gba: $(BUILD)/$(TARGET).elf $(BUILD)/gbafix
$(OBJCOPY) -O binary $< $@
$(BUILD)/gbafix $@
@echo "Built $@ (real-hardware ready)"
$(BUILD):
mkdir -p $(BUILD)
run: $(BUILD)/$(TARGET).gba
mgba $(BUILD)/$(TARGET).gba
clean:
rm -rf $(BUILD)