remove makefile functionality, small build cleanup

This commit is contained in:
Rainchus 2023-07-09 18:10:56 -05:00
parent cd70c4ec15
commit 4cd014e60c
8 changed files with 135 additions and 181 deletions

174
Makefile
View File

@ -1,168 +1,16 @@
BASENAME = quest64
VERSION := us
BUILD_DIR = build
ASM_DIRS = asm asm/data
BIN_DIRS = assets
SRC_DIR = src src/os
SRC_DIRS = $(SRC_DIR)
TOOLS_DIR := tools
S_FILES = $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
C_FILES = $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
H_FILES = $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))
BIN_FILES = $(foreach dir,$(BIN_DIRS),$(wildcard $(dir)/*.bin))
O_FILES := $(foreach file,$(S_FILES),$(BUILD_DIR)/$(file).o) \
$(foreach file,$(C_FILES),$(BUILD_DIR)/$(file).o) \
$(foreach file,$(BIN_FILES),$(BUILD_DIR)/$(file).o)
TARGET = $(BUILD_DIR)/$(BASENAME).$(VERSION)
LD_SCRIPT = $(BASENAME).ld
CROSS = mips-linux-gnu-
AS = $(CROSS)as
CPP = cpp
LD = $(CROSS)ld
OBJDUMP = $(CROSS)objdump
OBJCOPY = $(CROSS)objcopy
PYTHON = python3
OBJCOPYFLAGS = -O binary
CC := $(TOOLS_DIR)/ido_5.3/usr/lib/cc
OPT_FLAGS := -O2 -g3
OBJECTS := $(shell grep -E 'build.+\.o' quest64.ld -o)
DEPENDS := $(OBJECTS:=.d)
MIPSISET := -mips2 -o32
INCLUDE_CFLAGS := -I . -I include -I include/2.0I -I include/2.0I/PR
ASFLAGS = -EB -mtune=vr4300 -march=vr4300 -mabi=32 -I include
# Files requiring pre/post-processing
GREP := grep -rl
GLOBAL_ASM_C_FILES := $(shell $(GREP) GLOBAL_ASM $(SRC_DIR) </dev/null 2>/dev/null)
GLOBAL_ASM_O_FILES := $(foreach file,$(GLOBAL_ASM_C_FILES),$(BUILD_DIR)/$(file).o)
CFLAGS := -G 0 -Xfullwarn -Xcpluscomm -signed -nostdinc -non_shared -Wab,-r4300_mul
CFLAGS += -D_LANGUAGE_C -D_FINALROM -DF3DEX_GBI -DWIN32
# ignore compiler warnings about anonymous structs
CFLAGS += -woff 649,838
CFLAGS += $(INCLUDE_CFLAGS)
ifeq ($(VERSION),us)
CFLAGS += -DVERSION_US
endif
ifeq ($(VERSION),eu)
CFLAGS += -DVERSION_EU
endif
LDFLAGS = -T $(LD_SCRIPT) -Map $(TARGET).map -T undefined_syms_auto.txt -T undefined_funcs_auto.txt -T undefined_syms.$(VERSION).txt --no-check-sections
ASM_PROCESSOR_DIR := $(TOOLS_DIR)/asm-processor
### Optimisation Overrides
build/src/seqpgetstate.c.o: OPT_FLAGS := -O2
build/src/aigetlen.c.o: OPT_FLAGS := -O1
build/src/pfssearchfile.c.o: OPT_FLAGS := -O1
build/src/pfsreadwritefile.c.o: OPT_FLAGS := -O1
build/src/pfsfreeblocks.c.o: OPT_FLAGS := -O1
build/src/pfsfilestate.c.o: OPT_FLAGS := -O1
build/src/pfsdeletefile.c.o: OPT_FLAGS := -O1
build/src/pfsallocatefile.c.o: OPT_FLAGS := -O1
build/src/pfsnumfiles.c.o: OPT_FLAGS := -O1
build/src/pfsgetstatus.c.o: OPT_FLAGS := -O1
build/src/contpfs.c.o: OPT_FLAGS := -O1
build/src/leodiskinit.c.o: OPT_FLAGS := -O1
build/src/controller.c.o: OPT_FLAGS := -O1
build/src/initialize.c.o: OPT_FLAGS := -O1
build/src/createthread.c.o: OPT_FLAGS := -O1
build/src/startthread.c.o: OPT_FLAGS := -O1
build/src/createmesgqueue.c.o: OPT_FLAGS := -O1
build/src/visetevent.c.o: OPT_FLAGS := -O1
build/src/pfsisplug.c.o: OPT_FLAGS := -O1
build/src/pfschecker.c.o: OPT_FLAGS := -O1
build/src/sptaskyielded.c.o: OPT_FLAGS := -O1
build/src/sptask.c.o: OPT_FLAGS := -O1
build/src/viblack.c.o: OPT_FLAGS := -O1
build/src/viswapbuf.c.o: OPT_FLAGS := -O1
build/src/vigetcurrframebuf.c.o: OPT_FLAGS := -O1
build/src/vimgr.c.o: OPT_FLAGS := -O1
### Targets
default: all
all: dirs $(TARGET).z64 verify
dirs:
$(foreach dir,$(SRC_DIRS) $(ASM_DIRS) $(BIN_DIRS),$(shell mkdir -p $(BUILD_DIR)/$(dir)))
check: .baserom.$(VERSION).ok
verify: $(TARGET).z64
@echo "$$(cat $(BASENAME).$(VERSION).sha1) $(TARGET).z64" | sha1sum --check
extract: check
$(PYTHON) $(TOOLS_DIR)/splat/split.py $(BASENAME).$(VERSION).yaml
clean:
rm -rf assets
@echo "If you meant to build, use ./configure && ninja"
@echo "If ninja errors, run ./install.sh"
rm -rf build
#rm -f *auto.txt
### Recipes
distclean: clean
rm -rf asm
rm -rf assets
rm -f *auto.txt
rm -f quest64.ld
.baserom.$(VERSION).ok: baserom.$(VERSION).z64
@echo "$$(cat $(BASENAME).$(VERSION).sha1) $<" | sha1sum --check
@touch $@
expectedclean:
rm -rf expected
$(TARGET).elf: $(O_FILES) $(LANG_O_FILES)
@$(LD) $(LDFLAGS) -o $@
# ifndef PERMUTER
# $(GLOBAL_ASM_O_FILES): $(BUILD_DIR)/%.c.o: %.c
# $(PYTHON) $(ASM_PROCESSOR_DIR)/asm_processor.py $(OPT_FLAGS) $< > $(BUILD_DIR)/$<
# $(CC) -c -32 $(CFLAGS) $(OPT_FLAGS) $(MIPSISET) -o $@ $(BUILD_DIR)/$<
# $(PYTHON) $(ASM_PROCESSOR_DIR)/asm_processor.py $(OPT_FLAGS) $< --post-process $@ \
# --assembler "$(AS) $(ASFLAGS)" --asm-prelude $(ASM_PROCESSOR_DIR)/prelude.s
# endif
ifndef PERMUTER
$(GLOBAL_ASM_O_FILES): $(BUILD_DIR)/%.c.o: %.c
$(PYTHON) $(ASM_PROCESSOR_DIR)/asm_processor.py $(OPT_FLAGS) $< > $(BUILD_DIR)/$<
$(CC) -c -32 $(CFLAGS) $(OPT_FLAGS) $(MIPSISET) -o $@ $(BUILD_DIR)/$<
$(PYTHON) $(ASM_PROCESSOR_DIR)/asm_processor.py $(OPT_FLAGS) $< --post-process $@ \
--assembler "$(AS) $(ASFLAGS)" --asm-prelude include/macro.inc
endif
# non asm-processor recipe
$(BUILD_DIR)/%.c.o: %.c
$(CC) -c $(CFLAGS) $(OPT_FLAGS) $(MIPSISET) -o $@ $<
$(BUILD_DIR)/%.s.o: %.s
$(AS) $(ASFLAGS) -o $@ $<
$(BUILD_DIR)/%.bin.o: %.bin
$(LD) -r -b binary -o $@ $<
$(TARGET).bin: $(TARGET).elf
$(OBJCOPY) $(OBJCOPYFLAGS) $< $@
$(TARGET).z64: $(TARGET).bin
@cp $< $@
### Settings
.SECONDARY:
.PHONY: all clean default
SHELL = /bin/bash -e -o pipefail
.DEFAULT_GOAL: all
.PHONY: all clean distclean

View File

@ -7,4 +7,4 @@ def apply(config, args):
config['mapfile'] = f'build/{basename}.{version}.map'
config['source_directories'] = ['src', 'include']
config['objdump_flags'] = ['-M','reg-names=32']
config['makeflags'] = ['COMPARE=0']
config["make_command"] = ["ninja"]

View File

@ -8,6 +8,7 @@ options:
symbol_addrs_path: symbol_addrs.us.txt
migrate_rodata_to_functions: True
target_path: baserom.us.z64
asm_emit_size_directive: false
segments:
- name: header
type: header

View File

@ -58,19 +58,9 @@ void func_80031F1C(s16 arg0, s16 arg1) {
}
//#pragma GLOBAL_ASM("asm/nonmatchings/328F0/func_80031F74.s")
void func_80031F74(u8 *arg0)
{
s32 var_s0;
if (0 != (*arg0))
{
do
{
var_s0 = *arg0;
arg0++;
func_80031DD4(var_s0);
var_s0 = *arg0;
}
while (*arg0 != 0);
void func_80031F74(u8* arg0) {
while (*arg0 != 0) {
func_80031DD4(*arg0++);
}
}

@ -1 +1 @@
Subproject commit e7cd45ba18620d1a50c9dcdaba30bbefd02414c9
Subproject commit 247994f34820afc2ed7e173427caad6199c4b666

@ -1 +1 @@
Subproject commit 41c1b303e7761a35fd67d85de09cec5ea4b4eac6
Subproject commit 6dd4d3adcbfb3ee607b9a1e2bba3502d27217d44

115
tools/progress.py Executable file
View File

@ -0,0 +1,115 @@
#!/usr/bin/env python3
import argparse
import git
import os
import subprocess
import sys
from colour import Color
script_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = os.path.join(script_dir, "..")
asm_dir = os.path.join(root_dir, "asm", "nonmatchings")
build_dir = os.path.join(root_dir, "build")
elf_path = os.path.join(build_dir, "marioparty.elf")
def get_func_sizes():
try:
result = subprocess.run(['objdump', '-x', elf_path], stdout=subprocess.PIPE)
nm_lines = result.stdout.decode().split("\n")
except:
print(f"Error: Could not run objdump on {elf_path} - make sure that the project is built")
sys.exit(1)
sizes = {}
total = 0
for line in nm_lines:
if " F " in line:
components = line.split()
size = int(components[4], 16)
name = components[5]
total += size
sizes[name] = size
return sizes, total
def get_nonmatching_funcs():
funcs = set()
for root, dirs, files in os.walk(asm_dir):
for f in files:
if f.endswith(".s"):
funcs.add(f[:-2])
return funcs
def get_funcs_sizes(sizes, matchings, nonmatchings):
msize = 0
nmsize = 0
for func in matchings:
msize += sizes[func]
for func in nonmatchings:
if func not in sizes:
pass
# print(func)
else:
nmsize += sizes[func]
return msize, nmsize
def lerp(a, b, alpha):
return a + (b - a) * alpha
def main(args):
func_sizes, total_size = get_func_sizes()
all_funcs = set(func_sizes.keys())
nonmatching_funcs = get_nonmatching_funcs()
matching_funcs = all_funcs - nonmatching_funcs
matching_size, nonmatching_size = get_funcs_sizes(func_sizes, matching_funcs, nonmatching_funcs)
if len(all_funcs) == 0:
funcs_matching_ratio = 0.0
matching_ratio = 0.0
else:
funcs_matching_ratio = (len(matching_funcs) / len(all_funcs)) * 100
matching_ratio = (matching_size / total_size) * 100
if args.csv:
version = 1
git_object = git.Repo().head.object
timestamp = str(git_object.committed_date)
git_hash = git_object.hexsha
csv_list = [str(version), timestamp, git_hash, str(len(all_funcs)), str(len(nonmatching_funcs)),
str(len(matching_funcs)), str(total_size), str(nonmatching_size), str(matching_size)]
print(",".join(csv_list))
elif args.shield_json:
import json
# https://shields.io/endpoint
color = Color("#50ca22", hue=lerp(0, 105/255, matching_ratio / 100))
print(json.dumps({
"schemaVersion": 1,
"label": f"progress ({args.version})",
"message": f"{matching_ratio:.2f}%",
"color": color.hex,
}))
else:
print (f" Matching Size:{matching_size}\n Nonmatching Size:{nonmatching_size}\n Calculated Size:{matching_size + nonmatching_size}\n Total Size:{total_size}\n")
if matching_size + nonmatching_size != total_size:
print("Warning: category/total size mismatch!\n")
print(f"{len(matching_funcs)} matched functions / {len(all_funcs)} total ({funcs_matching_ratio:.2f}%)")
print(f"{matching_size} matching bytes / {total_size} total ({matching_ratio:.2f}%)")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Reports progress for the project")
parser.add_argument("--csv", action="store_true")
parser.add_argument("--shield-json", action="store_true")
args = parser.parse_args()
main(args)

@ -1 +1 @@
Subproject commit d87e50f4ed96bc2a00e3b0c65d453608fb6b57cc
Subproject commit 312d57a03d5fd03bbd98106e9986f1257b75d950