-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
111 lines (79 loc) · 2.8 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
BASENAME := conker
VERSION := us
BUILD_DIR = build
TARGET = $(BUILD_DIR)/$(BASENAME).$(VERSION)
GAME_DIR = $(BASENAME)
BIN_DIR = assets
ifeq ($(VERSION),ects)
BIN_FILES = $(wildcard $(BIN_DIR)/*.bin)
else
# don't compile game.$(VERSION).bin
BIN_FILES = $(filter-out $(BIN_DIR)/game.$(VERSION).bin, $(wildcard $(BIN_DIR)/*.bin))
endif
EXTRACT_DIR = extracted
RZIP_DIRS = $(wildcard $(BIN_DIR)/rzip/assets*)
RZIP_FILES = $(wildcard $(BIN_DIR)/rzip/assets*/assets*.bin)
O_FILES = $(foreach file,$(BIN_FILES) $(RZIP_FILES),$(BUILD_DIR)/$(file:.bin=.bin.o))
CROSS = mips-linux-gnu-
CPP = cpp
LD = $(CROSS)ld
OBJCOPY = $(CROSS)objcopy
PYTHON = python3
LD_SCRIPT = $(BASENAME).ld
LDFLAGS = -T $(BUILD_DIR)/$(LD_SCRIPT) -Map $(TARGET).map --no-check-sections
ifeq ($(NON_MATCHING),1)
VERIFY :=
else
VERIFY := verify
endif
### Targets
default: all
all: dirs $(TARGET).z64 $(VERIFY)
dirs:
$(foreach dir,$(BIN_DIR) $(RZIP_DIRS),$(shell mkdir -p $(BUILD_DIR)/$(dir)))
clean:
rm -rf build
really-clean: clean
rm -rf assets
rm -rf rzip
make -C $(GAME_DIR) really-clean
check: .baserom.$(VERSION).ok
extract: check $(GAME_DIR)/$(BASENAME).$(VERSION).bin
decompress: $(EXTRACT_DIR)/00000000.bin
verify: $(TARGET).z64
@echo "$$(cat $(BASENAME).$(VERSION).sha1) $<" | sha1sum --check
### Recipes
$(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT)
$(CPP) -P -DBUILD_DIR=$(BUILD_DIR) -o $@ $<
$(TARGET).elf: $(O_FILES) $(BUILD_DIR)/$(LD_SCRIPT)
@$(LD) $(LDFLAGS) -o $@
$(BUILD_DIR)/%.bin.o: %.bin
$(LD) -r -b binary -o $@ $<
$(TARGET).bin: $(TARGET).elf
$(OBJCOPY) $(OBJCOPYFLAGS) -O binary $< $@
$(TARGET).z64: $(TARGET).bin
@cp $< $@
# combine
$(GAME_DIR)/$(BASENAME).$(VERSION).bin: $(BIN_DIR)/game.$(VERSION).bin
cat $(BIN_DIR)/header.$(VERSION).bin $(BIN_DIR)/boot.$(VERSION).bin $(BIN_DIR)/init.$(VERSION).bin $(BIN_DIR)/game.$(VERSION).bin $(BIN_DIR)/debugger.$(VERSION).bin > $@
# game code is not compressed in ECTS ROM
ifeq ($(VERSION),ects)
$(BIN_DIR)/game.$(VERSION).bin: $(BASENAME).$(VERSION).yaml
$(PYTHON) tools/n64splat/split.py $<
else
$(BIN_DIR)/game.$(VERSION).bin: $(BIN_DIR)/game/rzip/data/0000.bin
cat $(BIN_DIR)/game/rzip/code/0*.bin $(BIN_DIR)/game/rzip/data/0000.bin > $@
$(BIN_DIR)/game/rzip/data/0000.bin: $(BIN_DIR)/game.$(VERSION).rzip.bin
$(PYTHON) tools/n64splat/split.py game.$(VERSION).rzip.yaml --modes bin rzip
$(BIN_DIR)/game.$(VERSION).rzip.bin: $(BASENAME).$(VERSION).yaml
$(PYTHON) tools/n64splat/split.py $<
endif
.baserom.$(VERSION).ok: baserom.$(VERSION).z64
@echo "$$(cat $(BASENAME).$(VERSION).sha1) $<" | sha1sum --check
@touch $@
$(EXTRACT_DIR)/00000000.bin:
@mkdir -p $(EXTRACT_DIR)
$(PYTHON) tools/extract_compressed.py config/compressed.$(VERSION).yaml $(BIN_DIR)/compressed.bin $(EXTRACT_DIR)
# settings
.PHONY: all clean default
SHELL = /bin/bash -e -o pipefail