-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
103 lines (78 loc) · 2.89 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
NAME := msx-karts
CCZ80 = ~/sdcc-4.0.0/bin/sdcc
ASM = ~/sdcc-4.0.0/bin/sdasz80
MEGALINKER = ~/repos/manel/msx/megalinker/megalinker
OPENMSX_BIN = openmsx
OPENMSX_DEF = $(OPENMSX_BIN) $(OPENMSX_PARAM) -carta
OPENMSX1 = $(OPENMSX_BIN) -machine C-BIOS_MSX1 $(OPENMSX_PARAM) -carta
OPENMSX1_JP = $(OPENMSX_BIN) -machine C-BIOS_MSX1_JP $(OPENMSX_PARAM) -carta
OPENMSX2 = $(OPENMSX_BIN) -machine C-BIOS_MSX2 $(OPENMSX_PARAM) -carta
OPENMSX2P = $(OPENMSX_BIN) -machine C-BIOS_MSX2+_JP $(OPENMSX_PARAM) -carta
OPENMSXTR = $(OPENMSX_BIN) -machine Panasonic_FS-A1GT $(OPENMSX_PARAM) -carta
MAX_ALLOCS = 5000
CCFLAGS_MSX = -mz80 --disable-warning 110 --disable-warning 126 --no-std-crt0 --out-fmt-ihx --max-allocs-per-node $(MAX_ALLOCS) --allow-unsafe-read --nostdlib --no-xinit-opt --opt-code-speed --reserve-regs-iy
MSG = "\033[1;32m[$(@)]\033[1;31m\033[0m"
#recursive wildcard
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
INCLUDES += -Iinc -Isrc
HEADERS += $(call rwildcard, src/ inc/, *.h)
SOURCES_C += $(call rwildcard, src/, *.c)
SOURCES_ASM += $(call rwildcard, src/, *.s)
.PHONY: all clean
.SECONDARY:
all: rom
##########################################################
### MSX SECTION
OBJ_ASM = $(addprefix tmp/,$(SOURCES_ASM:.s=.rel))
OBJ_C = $(addprefix tmp/,$(SOURCES_C:.c=.rel))
tmp/%.rel: %.s $(HEADERS)
@echo $(MSG)
@mkdir -p $(@D)
@$(ASM) -ogslp $@ $<
@echo " "`grep "size" tmp/$*.sym | awk 'strtonum("0x"$$4) {print $$2": "strtonum("0x"$$4)" bytes"}'`
tmp/%.rel: %.c $(HEADERS)
@echo -n $(MSG)
@mkdir -p $(@D)
@$(CCZ80) -c -D MSX $(INCLUDES) $(CCFLAGS_MSX) $< -o $@
@echo " "`grep "size" tmp/$*.sym | awk 'strtonum("0x"$$4) {print $$2": "strtonum("0x"$$4)" bytes"}'`
out/%_[ASCII8].rom: $(OBJ_C) $(OBJ_ASM) tmp/mapper/ascii8.rel
@echo $(MSG)
@mkdir -p $(@D)
@$(MEGALINKER) $(OBJ_C) $(OBJ_ASM) tmp/mapper/ascii8.rel $@
out/%_[Generic8].rom: $(OBJ_C) $(OBJ_ASM) tmp/mapper/generic8.rel
@echo $(MSG)
@mkdir -p $(@D)
@$(MEGALINKER) $(OBJ_C) $(OBJ_ASM) tmp/mapper/generic8.rel $@
rom: out/$(NAME)_[ASCII8].rom out/$(NAME)_[Generic8].rom
msx: out/$(NAME)_[ASCII8].rom
@echo $(MSG)
$(OPENMSX_DEF) $< || true
msx1: out/$(NAME)_[ASCII8].rom
@echo $(MSG)
$(OPENMSX1) $< || true
msx1jp: out/$(NAME)_[ASCII8].rom
@echo $(MSG)
@$(OPENMSX1_JP) $< || true
msx2: out/$(NAME)_[ASCII8].rom
@echo $(MSG)
@$(OPENMSX2) $< || true
msx2p: out/$(NAME)_[ASCII8].rom
@echo $(MSG)
@$(OPENMSX2P) $< || true
msxtr: out/$(NAME)_[ASCII8].rom
@echo $(MSG)
@$(OPENMSXTR) $< || true
##########################################################
### UTILITIES SECTION
INCLUDE := util
tmp/%: %.cc
@echo $(MSG)
@mkdir -p $(@D)
@$(CXX) -o $@ $< $(shell echo `grep -m1 "^// FLAGS:" $< | cut -d: -f2-`)
%: util/%.cc bin/%
@echo $(MSG)
@true
clean:
@echo -n "Cleaning... "
@rm -rf tmp out
@echo "Done!"