-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
98 lines (72 loc) · 3.26 KB
/
Copy pathmakefile
File metadata and controls
98 lines (72 loc) · 3.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
# adapted from https://github.com/Exant64/sa2dc/blob/main/makefile
#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)
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
# 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
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))
#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 -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)
ifeq ($(COMPARE),1)
@md5sum -c checksum.md5
endif
setup:
$(MAKE) -C tools
$(DCSPLIT) 1st_read.yaml
clean:
$(RM) -r $(ROM) $(ELF) 1ST_READ_ELF.map build
.PHONY: all clean setup
$(1ST_READ_ROM): $(1ST_READ_ELF)
$(ELF2BIN) -s $(1ST_READ_KEY) $< $@
$(1ST_READ_ELF): $(O_FILES)
$(PATHHELP) $(WIBO) $(LD) $(LDFLAGS) -sub=1st_read_lnk.sub
# wibo doesn't support envvar conversion so we use wine for shc
# wine crashes asmsh, and asmsh doesn't use the envvars
# so wibo works
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=$@
build/asm/1st_read.obj:
$(PATHHELP) $(WIBO) $(AS) $(ASFLAGS) -object=$@