-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
132 lines (102 loc) · 4.26 KB
/
Copy pathmakefile
File metadata and controls
132 lines (102 loc) · 4.26 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#I used the zeldaret oot makefile as reference cuz i never did makefile before, sorry about that lol
#idk how we should do this with other overlay files + 1st_read later on
1ST_READ_KEY := 8C010000
1ST_READ_ROM := build/1ST_READ.bin
1ST_READ_ELF := $(1ST_READ_ROM:.bin=.elf)
CHAO_KEY := 0C500000
CHAO_ROM := build/CHAO.bin
CHAO_ELF := $(CHAO_ROM:.bin=.elf)
CHAOSTGRACE_KEY := 0C9C0000
CHAOSTGRACE_ROM := build/CHAOSTGRACE.bin
CHAOSTGRACE_ELF := $(CHAOSTGRACE_ROM:.bin=.elf)
COMPARE ?= 1
SRC_DIRS := $(shell find src -type d)
ASM_DIRS := $(shell find asm -type d -not -path '*/nonmatching/*')
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.src))
#i use obj to "differentiate" between regular elf object files and the SYSROF thing that hitachi uses
O_FILES := $(foreach f,$(S_FILES:.src=.obj),build/$f) \
$(foreach f,$(C_FILES:.c=.obj),build/$f)
#using inline_asm automatically creates a .align 4, rts, and nop at the end of the function regardless of its contents
#we have to remove those to be able to include asm
#i guess this is sort of our equivalent of asm-processor
PYTHON := /usr/bin/env python3
BASH := /usr/bin/env bash
FIX_INLINE := $(PYTHON) tools/fix_inline_asm.py
FIX_INLINE_C := $(PYTHON) tools/inline_asm_c.py
DCSPLIT := $(PYTHON) tools/dcsplit/dcsplit.py
GENFSY := $(PYTHON) tools/genfsy.py
# path conversion for msys2 (msys2 doesnt seem to automatically convert foo/bar paths because windows apps are
# apparently supposed to support that, except SHC doesn't lol) (pls correct me if im wrong)
PATHHELP := $(BASH) tools/path_helper.sh
SHC_DIR := shc
MAKE = make
CC := $(SHC_DIR)/bin/shc.exe
AS := $(SHC_DIR)/bin/asmsh.exe
LD := $(SHC_DIR)/bin/lnk.exe
ELF2BIN := tools/elf2bin
WINPATH := $(BASH) tools/winpath.sh
UNAME:=$(shell uname)
ifeq ($(UNAME), Linux)
WIBO := tools/wibo
# wibo doesn't convert env vars yet afaik, so we do it manually
export SHC_LIB := $(shell $(WINPATH) $(abspath $(SHC_DIR)/bin))
export SHC_TMP := $(shell $(WINPATH) $(abspath $(SHC_DIR)/temp))
else
export SHC_LIB := $(shell cygpath -w $(realpath $(SHC_DIR)/bin))
export SHC_TMP := $(shell cygpath -w $(realpath $(SHC_DIR)/temp))
endif
#the source dir (original layout was like that too) and katana includes
INCLUDEDIRS := src,Include,$(SHC_DIR)\\include
CFLAGS := -comment=nonest -cpu=sh4 -division=cpu -fpu=single -endian=little -extra=a=1800 -optimize=1 -pic=0 -macsave=0 \
-speed -sjis -loop -string=const -round=nearest -inline -aggressive=2 -code=asmcode -include=$(INCLUDEDIRS)
ASFLAGS := -cpu=sh4 -endian=little -sjis -include=asm
LDFLAGS :=
$(shell mkdir -p asm)
$(shell mkdir -p build $(foreach dir, $(SRC_DIRS) $(ASM_DIRS), build/$(dir)))
$(shell mkdir -p shc/temp)
#also stolen from oot makefile
all: $(1ST_READ_ROM) $(CHAO_ROM) $(CHAOSTGRACE_ROM)
ifeq ($(COMPARE),1)
@md5sum -c checksum.md5
endif
setup:
$(MAKE) -C tools
$(GENFSY) symbols.1st_read.txt > asm/1st_read_symbols.src
$(GENFSY) symbols.chao.txt > asm/chao_symbols.src
$(GENFSY) symbols.chaomodel.txt > asm/chaomodel_symbols.src
$(DCSPLIT) 1st_read.yaml
$(DCSPLIT) chao.yaml
$(DCSPLIT) chaostgrace.yaml
clean:
$(RM) -r $(ROM) $(ELF) CHAO.map build
.PHONY: all clean setup
$(CHAO_ROM): $(CHAO_ELF)
$(ELF2BIN) -s $(CHAO_KEY) $< $@
$(CHAO_ELF): $(O_FILES)
$(LD) $(LDFLAGS) -sub=chao_lnk.sub
$(CHAOSTGRACE_ROM): $(CHAOSTGRACE_ELF)
$(ELF2BIN) -s $(CHAOSTGRACE_KEY) $< $@
$(CHAOSTGRACE_ELF): $(O_FILES)
$(LD) $(LDFLAGS) -sub=chaostgrace_lnk.sub
$(1ST_READ_ROM): $(1ST_READ_ELF)
$(ELF2BIN) -s $(1ST_READ_KEY) $< $@
$(1ST_READ_ELF): $(O_FILES)
$(LD) $(LDFLAGS) -sub=1st_read_lnk.sub
ifeq ($(UNAME), Linux)
build/src/%.obj: src/%.c
$(FIX_INLINE_C) $< build/$<
$(PATHHELP) $(WIBO) $(CC) build/$< $(CFLAGS) -objectfile=$(@:.obj=.src)
$(FIX_INLINE) $(@:.obj=.src)
$(PATHHELP) $(WIBO) $(AS) $(@:.obj=.src) $(ASFLAGS) -object=$@
build/asm/%.obj: asm/%.src
$(PATHHELP) $(WIBO) $(AS) $< $(ASFLAGS) -object=$@
else
build/src/%.obj: src/%.c
$(FIX_INLINE_C) $< build/$<
$(PATHHELP) $(CC) build/$< $(CFLAGS) -objectfile=$(@:.obj=.src)
$(FIX_INLINE) $(@:.obj=.src)
$(AS) $(shell cygpath -w $(@:.obj=.src)) $(ASFLAGS) -object=$(shell cygpath -w $@)
build/asm/%.obj: asm/%.src
$(AS) $(shell cygpath -w $<) $(ASFLAGS) -object=$(shell cygpath -w $@)
endif