-
Notifications
You must be signed in to change notification settings - Fork 20
/
Makefile.nspire
104 lines (83 loc) · 2.9 KB
/
Makefile.nspire
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
# Note to future self:
#
# This file is pretty much a minimal copy of make_base modified to build for the
# TI-Nspire. Since the original project is archived, it would make more sense
# to simply fork the original and merge them together. For now, I'll just keep
# using this separate Makefile.
# ------------
# Configurable
# ------------
# Project Name
EXE = haxagon
# Directories
SOURCE_DIRS := source/Core source/Factories source/Objects source/States source/Driver/Nspire
INCLUDE_DIRS := include
MEMORYFS_DIR := romfs
BUILD_DIR := build
OUTPUT_DIR := output
# MemoryFS Packable Extensions
MEMORYFS_EXT = haxagon txt
# Compilers
CC = nspire-gcc
CXX = nspire-g++
LD = nspire-ld
GENZEHN = genzehn
OPTIMIZE ?= fast
# Flags
COMMONFLAGS := -O$(OPTIMIZE) $(patsubst %,-I%,$(INCLUDE_DIRS)) -D_nspire -DOLD_SCREEN_API
COMMONFLAGS += -Wall -W -marm -ffast-math -mcpu=arm926ej-s -fno-math-errno -fomit-frame-pointer -flto -fgcse-sm -fgcse-las -funsafe-loop-optimizations -fno-fat-lto-objects -frename-registers -fprefetch-loop-arrays -Wno-narrowing
CCFLAGS := $(COMMONFLAGS)
CXXFLAGS := $(COMMONFLAGS) -fno-rtti -std=gnu++17
LDFLAGS = -lm -lnspireio
ZEHNFLAGS = --name "Super-Haxagon" --version 00 --240x320-support true
# --------
# Internal
# --------
TARGET_BUILD_DIR := $(BUILD_DIR)/nspire-arm
TARGET_OUTPUT_DIR := $(OUTPUT_DIR)/nspire-arm
rwildcard=$(wildcard $1/$2) $(foreach d,$(wildcard $1/*),$(call rwildcard,$d,$2))
OUTPUT_FILES := $(TARGET_OUTPUT_DIR)/$(EXE).tns $(TARGET_OUTPUT_DIR)/$(EXE).elf
MEMORYFS_OBJECT_FILES := $(foreach ext,$(MEMORYFS_EXT),$(patsubst %.$(ext),$(TARGET_BUILD_DIR)/%.o,$(call rwildcard,$(MEMORYFS_DIR),*.$(ext))))
OBJECT_FILES := $(MEMORYFS_OBJECT_FILES) $(foreach dir,$(SOURCE_DIRS), \
$(patsubst %.c,$(TARGET_BUILD_DIR)/%.o,$(call rwildcard,$(dir),*.c)) \
$(patsubst %.cpp,$(TARGET_BUILD_DIR)/%.o,$(call rwildcard,$(dir),*.cpp)) \
)
all: $(OUTPUT_FILES)
$(TARGET_BUILD_DIR)/%.o: %.c
@echo $@
@$(CC) $(CCFLAGS) -c $< -o $@
$(TARGET_BUILD_DIR)/%.o: $(TARGET_BUILD_DIR)/%.cc
@echo $@
@$(CC) $(CCFLAGS) -x c -c $< -o $@
$(TARGET_BUILD_DIR)/%.o: %.cpp
@echo $@
@$(CXX) $(CXXFLAGS) -c $< -o $@
%.elf: $(OBJECT_FILES)
@echo $@
@$(LD) $^ -o $@ $(COMMONFLAGS) $(LDFLAGS)
%.tns: $(TARGET_OUTPUT_DIR)/$(EXE).elf
@echo $@
@$(GENZEHN) $(ZEHNFLAGS) --input $^ --output $@.zehn
@make-prg $@.zehn $@
@rm $@.zehn
.PHONY: clean
clean:
@rm -rf $(TARGET_BUILD_DIR) $(TARGET_OUTPUT_DIR)
@echo "Cleaned."
define createdirrule
$(1): | $(dir $(1))
ifndef $(dir $(1))_DIRECTORY_RULE_IS_DEFINED
$(dir $(1)):
@mkdir -p $$@
$(dir $(1))_DIRECTORY_RULE_IS_DEFINED := 1
endif
endef
define memoryfs
.PRECIOUS: $$(TARGET_BUILD_DIR)/%.cc
$$(TARGET_BUILD_DIR)/%.cc: %.$1
@echo $$@
@xxd -i $$< > $$@
endef
$(foreach file,$(OBJECT_FILES),$(eval $(call createdirrule,$(file))))
$(foreach file,$(OUTPUT_FILES),$(eval $(call createdirrule,$(file))))
$(foreach extension,$(MEMORYFS_EXT),$(eval $(call memoryfs,$(extension))))