forked from Decompollaborate/zelda64_compare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
134 lines (93 loc) · 4.55 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
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
133
134
MAKEFLAGS += --no-builtin-rules
# Build options can either be changed by modifying the makefile, or by building with 'make SETTING=value'
GAME ?= oot
VERSION ?= ne0
# if SPLIT_FUNCTIONS is non-zero, the disassembler will try to split functions and rodata
SPLIT_FUNCTIONS ?= 0
# if PRINT_BOUNDARIES is non-zero, the disassembler will print any detected new boundaries
PRINT_BOUNDARIES ?= 0
DISASM_VERBOSITY ?= -q
DISASM_EXTRA_PARAMS ?=
DISASM_EXTRA_PARAMS += --no-use-fpccsr
DISASM_EXTRA_PARAMS += --Mreg-names o32
DISASM_EXTRA_PARAMS += --function-info $(GAME)/function_info/$(VERSION)_$*_function_info.csv
DISASM_EXTRA_PARAMS += --custom-suffix _$(VERSION)
DISASM_EXTRA_PARAMS += --sequential-label-names
OVL_DIS_EXTRA_PARAMS ?=
ifeq ($(GAME), dnm)
OVL_DIS_EXTRA_PARAMS += --reloc-separate
endif
DISASM_FUNC_SPLIT =
ifneq ($(SPLIT_FUNCTIONS), 0)
DISASM_FUNC_SPLIT = --split-functions $(BASE_DIR)/asm/functions/$*
endif
ifneq ($(PRINT_BOUNDARIES), 0)
DISASM_EXTRA_PARAMS += --print-new-file-boundaries
endif
MAKE = make
DISASSEMBLER ?= python3 -m spimdisasm.singleFileDisasm
OVL_DISASSEMBLER ?= ./z64OvlDisasm.py
#### Files ####
BASE_DIR := $(GAME)/$(VERSION)
# ROM image
BASE_ROM := $(GAME)/$(GAME)_$(VERSION).z64
# ASM_DIRS := $(shell find $(BASE_DIR)/asm/ -type d)
# S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
BASEROM_FILES := $(wildcard $(BASE_DIR)/baserom/*)
DISASM_LIST := $(shell cat $(GAME)/tables/disasm_list.txt) \
$(shell [ -f $(BASE_DIR)/tables/disasm_list.txt ] && cat $(BASE_DIR)/tables/disasm_list.txt)
CSV_FILES_ORIGINAL := $(wildcard $(GAME)/tables/*.text.csv)
CSV_FILES := $(CSV_FILES_ORIGINAL:$(GAME)/tables/%.text.csv=$(BASE_DIR)/tables/files_%.csv) \
$(BASE_DIR)/tables/functions.csv $(BASE_DIR)/tables/variables.csv
DISASM_TARGETS := $(DISASM_LIST:%=$(BASE_DIR)/asm/text/%/.disasm)
.PHONY: all splitcsvs disasm clean downloadcsvs csvs
.DEFAULT_GOAL := all
#### Main commands ####
## Cleaning ##
clean:
$(RM) -rf $(BASE_DIR)/asm $(BASE_DIR)/context
asmclean:
$(RM) -rf $(BASE_DIR)/asm $(BASE_DIR)/context
## Extraction step
setup:
./decompress_baserom.py $(GAME) $(VERSION)
./extract_baserom.py $(GAME) $(VERSION)
## Assembly generation
disasm: $(DISASM_TARGETS)
@echo "Disassembly done!"
all: disasm
disasm: splitcsvs
splitcsvs: $(CSV_FILES)
downloadcsvs:
./tools/csvhelpers/download_csv_$(GAME).sh
csvs:
$(MAKE) downloadcsvs
$(MAKE) splitcsvs
#### Various Recipes ####
$(BASE_DIR)/tables/%.txt: $(GAME)/tables/%.csv
./csvSplit.py $(GAME) $<
$(BASE_DIR)/tables/%.csv: $(GAME)/tables/%.csv
./csvSplit.py $(GAME) $<
$(BASE_DIR)/tables/files_%.csv: $(GAME)/tables/%.*.csv
./csvSplit.py $(GAME) $<
$(BASE_DIR)/asm/text/%/.disasm: $(BASE_DIR)/baserom/% $(BASE_DIR)/tables/variables.txt $(BASE_DIR)/tables/functions.txt $(BASE_DIR)/tables/files_%.csv
$(RM) -rf $(BASE_DIR)/asm/text/$* $(BASE_DIR)/asm/data/$* $(BASE_DIR)/asm/functions/$* $(BASE_DIR)/context/$*.txt
$(DISASSEMBLER) $< $(BASE_DIR)/asm/text/$* $(DISASM_VERBOSITY) --data-output $(BASE_DIR)/asm/data/$* $(DISASM_FUNC_SPLIT) \
--file-splits $(BASE_DIR)/tables/files_$*.csv \
--symbol-addrs $(BASE_DIR)/tables/variables.txt --symbol-addrs $(BASE_DIR)/tables/functions.txt \
--constants $(GAME)/tables/constants.csv --constants $(BASE_DIR)/tables/constants_$*.csv \
--save-context $(BASE_DIR)/context/$*.txt $(DISASM_EXTRA_PARAMS) \
--default-banned --libultra-syms --hardware-regs --named-hardware-regs
@touch $@
$(BASE_DIR)/asm/text/ovl_%/.disasm: $(BASE_DIR)/baserom/ovl_% $(BASE_DIR)/tables/variables.txt $(BASE_DIR)/tables/functions.txt
$(RM) -rf $(BASE_DIR)/asm/text/ovl_$* $(BASE_DIR)/asm/data/ovl_$* $(BASE_DIR)/asm/functions/ovl_$* $(BASE_DIR)/context/ovl_$*.txt
$(OVL_DISASSEMBLER) $< $(BASE_DIR)/asm/text/ovl_$* $(DISASM_VERBOSITY) --data-output $(BASE_DIR)/asm/data/ovl_$* $(DISASM_FUNC_SPLIT) \
--file-splits $(BASE_DIR)/tables/files_ovl_$*.csv \
--symbol-addrs $(BASE_DIR)/tables/variables.txt --symbol-addrs $(BASE_DIR)/tables/functions.txt \
--constants $(GAME)/tables/constants.csv --constants $(BASE_DIR)/tables/constants_ovl_$*.csv \
--file-addresses $(BASE_DIR)/tables/file_addresses.csv \
--save-context $(BASE_DIR)/context/ovl_$*.txt $(DISASM_EXTRA_PARAMS) $(OVL_DIS_EXTRA_PARAMS) \
--default-banned --libultra-syms --hardware-regs --named-hardware-regs
@touch $@
# Print target for debugging
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true