mirror of https://github.com/zeldaret/mm.git
Makefile rework. Add init and uncompressed targets. (#15)
* Makefile rework. Add init and uncompressed targets * Update file_setup.sh for new makefile * Change CFLAGS
This commit is contained in:
parent
0844c24773
commit
b930732494
169
Makefile
169
Makefile
|
@ -1,4 +1,15 @@
|
|||
# TODO think about how to split this up
|
||||
# If COMPARE is 1, check the output md5sum after building
|
||||
COMPARE ?= 1
|
||||
# If NON_MATCHING is 1, define the NON_MATCHING C flag when building
|
||||
NON_MATCHING ?= 0
|
||||
# If ORIG_COMPILER is 1, compile with QEMU_IRIX and the original compiler
|
||||
# TODO we do not support static recomp, so force this to 1
|
||||
ORIG_COMPILER = 1
|
||||
|
||||
ifeq ($(NON_MATCHING),1)
|
||||
CFLAGS := -DNON_MATCHING
|
||||
COMPARE := 0
|
||||
endif
|
||||
|
||||
#### Tools ####
|
||||
ifeq ($(shell type mips-linux-gnu-ld >/dev/null 2>/dev/null; echo $$?), 0)
|
||||
|
@ -7,47 +18,41 @@ else
|
|||
MIPS_BINUTILS_PREFIX := mips64-elf-
|
||||
endif
|
||||
|
||||
AS := $(MIPS_BINUTILS_PREFIX)as
|
||||
LD := $(MIPS_BINUTILS_PREFIX)ld
|
||||
CC := tools/ido_recomp/linux/7.1/cc
|
||||
CC_OLD := tools/ido_recomp/linux/5.3/cc
|
||||
QEMU_IRIX ?= ./tools/qemu-mips
|
||||
|
||||
QEMU_IRIX ?= ./tools/qemu-mips
|
||||
IRIX_71_ROOT := ./tools/ido7.1_compiler/
|
||||
IRIX_53_ROOT := ./tools/ido5.3_compiler/
|
||||
# if ORIG_COMPILER is 1, check that either QEMU_IRIX is set or qemu-irix package installed
|
||||
ifeq ($(ORIG_COMPILER),1)
|
||||
ifndef QEMU_IRIX
|
||||
QEMU_IRIX := $(shell which qemu-irix)
|
||||
ifeq (, $(QEMU_IRIX))
|
||||
$(error Please install qemu-irix package or set QEMU_IRIX env var to the full qemu-irix binary path)
|
||||
endif
|
||||
endif
|
||||
CC = $(QEMU_IRIX) -L tools/ido7.1_compiler tools/ido7.1_compiler/usr/bin/cc
|
||||
CC_OLD = $(QEMU_IRIX) -L tools/ido5.3_compiler tools/ido5.3_compiler/usr/bin/cc
|
||||
endif
|
||||
|
||||
CFLAGS := -G 0 -non_shared -Xfullwarn -Xcpluscomm
|
||||
AS := $(MIPS_BINUTILS_PREFIX)as
|
||||
LD := $(MIPS_BINUTILS_PREFIX)ld
|
||||
OBJCOPY := $(MIPS_BINUTILS_PREFIX)objcopy
|
||||
OBJDUMP := $(MIPS_BINUTILS_PREFIX)objdump
|
||||
|
||||
OPTFLAGS := -O2 -g3
|
||||
ASFLAGS := -march=vr4300 -32
|
||||
|
||||
MIPS_VERSION := -mips2
|
||||
OPTIMIZATION := -O2 -g3
|
||||
|
||||
build/src/libultra/os/%: OPTIMIZATION := -O1
|
||||
build/src/libultra/io/%: OPTIMIZATION := -O2
|
||||
build/src/libultra/libc/%: OPTIMIZATION := -O2
|
||||
build/src/libultra/libc/ll%: OPTIMIZATION := -O1
|
||||
build/src/libultra/libc/ll%: MIPS_VERSION := -mips3 -32
|
||||
build/src/libultra/gu/%: OPTIMIZATION := -O2
|
||||
build/src/libultra/rmon/%: OPTIMIZATION := -O2
|
||||
build/src/libultra/%: CC := $(QEMU_IRIX) -L $(IRIX_53_ROOT) $(IRIX_53_ROOT)/usr/bin/cc
|
||||
build/src/libultra/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
|
||||
build/src/boot_O1/%: OPTIMIZATION := -O1
|
||||
build/src/boot_O2/%: OPTIMIZATION := -O2
|
||||
build/src/boot_O2_g3/%: OPTIMIZATION := -O2 -g3
|
||||
build/src/boot_O2_g3_trapuv/%: OPTIMIZATION := -O2 -g3
|
||||
build/src/code/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
|
||||
build/src/actors/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
|
||||
build/src/boot_O2_g3_trapuv/%: CFLAGS := $(CFLAGS) -trapuv
|
||||
test.txt: OPTIMIZATION := -O2 -g3
|
||||
test.txt: CC := $(QEMU_IRIX) -L $(IRIX_71_ROOT) $(IRIX_71_ROOT)/usr/bin/cc
|
||||
test.txt: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
|
||||
# we support Microsoft extensions such as anonymous structs, which the compiler does support but warns for their usage. Surpress the warnings with -woff.
|
||||
CFLAGS += -G 0 -non_shared -Xfullwarn -Xcpluscomm -Iinclude -Isrc -Wab,-r4300_mul -woff 649,838
|
||||
|
||||
CC := $(QEMU_IRIX) -L $(IRIX_71_ROOT) $(IRIX_71_ROOT)/usr/bin/cc
|
||||
#### Files ####
|
||||
|
||||
test.txt: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
||||
build/src/boot_O2/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
||||
build/src/boot_O2_g3/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
||||
build/src/boot_O2_g3_trapuv/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
||||
build/src/code/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
||||
build/src/actors/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
||||
# ROM image
|
||||
ROM_NAME := rom
|
||||
ROM := $(ROM_NAME).z64
|
||||
UNCOMPRESSED_ROM := $(ROM_NAME)_uncompressed.z64
|
||||
ELF := $(ROM_NAME).elf
|
||||
|
||||
BASEROM_FILES := $(wildcard baserom/*)
|
||||
# Exclude dmadata, it will be generated right before packing the rom
|
||||
|
@ -69,51 +74,67 @@ SRC_DIRS := $(shell find src -type d)
|
|||
# Because we may not have disassembled the code files yet, there might not be any assembly files.
|
||||
# Instead, generate a list of assembly files based on what's listed in the linker script.
|
||||
S_FILES := $(shell grep build/asm ./linker_scripts/code_script.txt | sed 's/\s*build\///g; s/\.o(\..*)/\.asm/g')
|
||||
S_O_FILES = $(S_FILES:asm/%.asm=build/asm/%.o)
|
||||
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
|
||||
C_O_FILES = $(C_FILES:src/%.c=build/src/%.o)
|
||||
O_FILES := $(C_FILES:src/%.c=build/src/%.o) \
|
||||
$(S_FILES:asm/%.asm=build/asm/%.o)
|
||||
ROM_FILES := $(shell cat ./tables/makerom_files.txt)
|
||||
UNCOMPRESSED_ROM_FILES := $(shell cat ./tables/makerom_uncompressed_files.txt)
|
||||
|
||||
# create build directories
|
||||
$(shell mkdir -p build/asm build/baserom build/comp build/decomp $(foreach dir,$(SRC_DIRS),$(shell mkdir -p build/$(dir))))
|
||||
|
||||
ROM := rom.z64
|
||||
build/src/libultra/os/%: OPTFLAGS := -O1
|
||||
build/src/libultra/io/%: OPTFLAGS := -O2
|
||||
build/src/libultra/libc/%: OPTFLAGS := -O2
|
||||
build/src/libultra/libc/ll%: OPTFLAGS := -O1
|
||||
build/src/libultra/libc/ll%: MIPS_VERSION := -mips3 -32
|
||||
build/src/libultra/gu/%: OPTFLAGS := -O2
|
||||
build/src/libultra/rmon/%: OPTFLAGS := -O2
|
||||
build/src/boot_O1/%: OPTFLAGS := -O1
|
||||
build/src/boot_O2/%: OPTFLAGS := -O2
|
||||
build/src/boot_O2_g3/%: OPTFLAGS := -O2 -g3
|
||||
build/src/boot_O2_g3_trapuv/%: OPTFLAGS := -O2 -g3
|
||||
build/src/boot_O2_g3_trapuv/%: CFLAGS := $(CFLAGS) -trapuv
|
||||
|
||||
BUILD_DIR := ./build
|
||||
build/src/libultra/%: CC := $(CC_OLD)
|
||||
|
||||
# make build directories
|
||||
$(shell mkdir -p $(BUILD_DIR)/asm)
|
||||
$(shell mkdir -p $(BUILD_DIR)/baserom)
|
||||
$(shell mkdir -p $(BUILD_DIR)/comp)
|
||||
$(shell mkdir -p $(BUILD_DIR)/decomp)
|
||||
$(foreach dir,$(SRC_DIRS),$(shell mkdir -p build/$(dir)))
|
||||
CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
||||
|
||||
.PHONY: check
|
||||
.PHONY: all clean setup diff-init init
|
||||
# disasm is not a file so we must tell make not to check it when evaluating timestamps
|
||||
.INTERMEDIATE: disasm
|
||||
|
||||
check: $(ROM)
|
||||
@md5sum -c checksum.md5
|
||||
all: $(ROM) $(UNCOMPRESSED_ROM)
|
||||
|
||||
$(ROM): $(ROM_FILES)
|
||||
./tools/makerom.py ./tables/dmadata_table.txt $@ -c
|
||||
ifeq ($(COMPARE),1)
|
||||
@md5sum $(ROM)
|
||||
@md5sum -c checksum.md5
|
||||
endif
|
||||
|
||||
$(UNCOMPRESSED_ROM): $(UNCOMPRESSED_ROM_FILES)
|
||||
./tools/makerom.py ./tables/dmadata_table.txt $@
|
||||
ifeq ($(COMPARE),1)
|
||||
@md5sum $(UNCOMPRESSED_ROM)
|
||||
@md5sum -c checksum_uncompressed.md5
|
||||
endif
|
||||
|
||||
build/code_pre_dmadata.elf: $(S_O_FILES) $(C_O_FILES) linker_scripts/code_script.txt undef.txt linker_scripts/object_script.txt
|
||||
$(LD) -r -T linker_scripts/code_script.txt -T undef.txt -T linker_scripts/object_script.txt --no-check-sections --accept-unknown-input-arch -N -o $@
|
||||
|
||||
build/code.elf: $(S_O_FILES) $(C_O_FILES) linker_scripts/code_script.txt undef.txt linker_scripts/object_script.txt linker_scripts/dmadata_script.txt
|
||||
build/code.elf: $(O_FILES) linker_scripts/code_script.txt undef.txt linker_scripts/object_script.txt linker_scripts/dmadata_script.txt
|
||||
$(LD) -T linker_scripts/code_script.txt -T undef.txt -T linker_scripts/object_script.txt -T linker_scripts/dmadata_script.txt --no-check-sections --accept-unknown-input-arch -Map build/mm.map -N -o $@
|
||||
|
||||
build/code_pre_dmadata.elf: $(O_FILES) linker_scripts/code_script.txt undef.txt linker_scripts/object_script.txt
|
||||
$(LD) -r -T linker_scripts/code_script.txt -T undef.txt -T linker_scripts/object_script.txt --no-check-sections --accept-unknown-input-arch -N -o $@
|
||||
|
||||
linker_scripts/dmadata_script.txt: $(DMADATA_FILES) build/code_pre_dmadata.elf
|
||||
./tools/dmadata.py ./tables/dmadata_table.txt /dev/null -u -l linker_scripts/dmadata_script.txt -e build/code_pre_dmadata.elf
|
||||
|
||||
test.txt: build/src/test.o
|
||||
$(MIPS_BINUTILS_PREFIX)objdump -d -z --adjust-vma=0x80080790 $< > test.txt
|
||||
|
||||
clean:
|
||||
rm -f $(ROM) -r build
|
||||
|
||||
build/baserom/dmadata: $(COMP_FILES) $(DECOMP_FILES) $(BASEROM_BUILD_FILES)
|
||||
build/dmadata: $(COMP_FILES) $(DECOMP_FILES) $(BASEROM_BUILD_FILES)
|
||||
./tools/dmadata.py ./tables/dmadata_table.txt $@
|
||||
|
||||
build/uncompressed_dmadata: $(DECOMP_FILES) $(BASEROM_BUILD_FILES)
|
||||
./tools/dmadata.py ./tables/dmadata_table.txt $@ -u
|
||||
|
||||
build/baserom/boot: build/boot.bin
|
||||
cp $< $@
|
||||
|
||||
|
@ -121,7 +142,7 @@ build/decomp/code: build/code.bin
|
|||
cp $< $@
|
||||
|
||||
build/decomp/ovl_%: build/code.elf
|
||||
$(MIPS_BINUTILS_PREFIX)objcopy --dump-section ovl_$*=$@ $< /dev/null
|
||||
$(OBJCOPY) --dump-section ovl_$*=$@ $< /dev/null
|
||||
|
||||
$(S_FILES): disasm
|
||||
|
||||
|
@ -131,10 +152,24 @@ disasm: tables/files.txt tables/functions.txt tables/objects.txt tables/variable
|
|||
./tools/split_asm.py ./asm/$$file.asm ./asm/non_matchings/$$file; \
|
||||
done < ./tables/files_with_nonmatching.txt
|
||||
|
||||
clean:
|
||||
rm -f $(ROM) $(UNCOMPRESSED_ROM) -r build asm
|
||||
|
||||
setup:
|
||||
git submodule update --init --recursive
|
||||
python3 -m pip install -r requirements.txt
|
||||
|
||||
diff-init: all
|
||||
rm -rf expected/
|
||||
mkdir -p expected/
|
||||
cp -r build expected/build
|
||||
|
||||
init: setup all diff-init
|
||||
|
||||
# Recipes
|
||||
|
||||
build/%.bin: build/code.elf
|
||||
$(MIPS_BINUTILS_PREFIX)objcopy --dump-section $*=$@ $< /dev/null
|
||||
$(OBJCOPY) --dump-section $*=$@ $< /dev/null
|
||||
|
||||
build/baserom/%: baserom/%
|
||||
cp $< $@
|
||||
|
@ -142,20 +177,20 @@ build/baserom/%: baserom/%
|
|||
build/asm/%.o: asm/%.asm
|
||||
$(AS) $(ASFLAGS) $^ -o $@
|
||||
|
||||
build/src/actors/%.o: src/actors/%.c include/* disasm
|
||||
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $<
|
||||
build/src/actors/%.o: src/actors/%.c include/* $(S_FILES)
|
||||
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTFLAGS) -o $@ $<
|
||||
./tools/overlay.py $@ build/src/actors/$*_overlay.s
|
||||
$(AS) $(ASFLAGS) build/src/actors/$*_overlay.s -o build/src/actors/$*_overlay.o
|
||||
|
||||
build/src/%.o: src/%.c include/* disasm
|
||||
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $<
|
||||
build/src/%.o: src/%.c include/* $(S_FILES)
|
||||
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTFLAGS) -o $@ $<
|
||||
|
||||
build/src/libultra/libc/ll.o: src/libultra/libc/ll.c include/*
|
||||
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $<
|
||||
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTFLAGS) -o $@ $<
|
||||
./tools/set_o32abi_bit.py $@
|
||||
|
||||
build/src/libultra/libc/llcvt.o: src/libultra/libc/llcvt.c include/*
|
||||
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $<
|
||||
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTFLAGS) -o $@ $<
|
||||
./tools/set_o32abi_bit.py $@
|
||||
|
||||
build/decomp/%: decomp/%
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
2a0a8acb61538235bc1094d297fb6556 rom.z64
|
||||
4e8afbb44e6a4b9bc00eaa318bb1650c build/code.bin
|
||||
b0145fad4be13d63d5d7aa75062db400 build/boot.bin
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
7c6bfd6daf33ebfc0145a97c611cb3d8 rom_uncompressed.z64
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ "$#" -ne "1" ];
|
||||
then
|
||||
echo "usage: $0 func_name"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tools/asm-differ/diff.py -mwo $1
|
|
@ -15,8 +15,4 @@ echo "$1" >> tables/files_with_nonmatching.txt
|
|||
sed -i "s/asm\/$1.o/src\/${2//\//\\\/}\/$1.o/g" linker_scripts/code_script.txt
|
||||
|
||||
# Build with new file
|
||||
make build/code.elf
|
||||
|
||||
# Copy newly-built .o file to expected/ for use by the diff script
|
||||
mkdir -p "expected/build/src/$2/"
|
||||
cp "build/src/$2/$1.o" "expected/build/src/$2/$1.o"
|
||||
make diff-init
|
|
@ -2,7 +2,7 @@
|
|||
[
|
||||
('build/baserom/makerom', '', 0x10, 0),
|
||||
('build/baserom/boot', '', 0x10, 0),
|
||||
('build/baserom/dmadata', '', 0x10, 0),
|
||||
('build/uncompressed_dmadata', 'build/dmadata', 0x10, 0),
|
||||
('build/baserom/Audiobank', '', 0x10, 0),
|
||||
('build/baserom/Audioseq', '', 0x10, 0),
|
||||
('build/baserom/Audiotable', '', 0x10, 0),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
build/baserom/makerom
|
||||
build/baserom/boot
|
||||
build/baserom/dmadata
|
||||
build/dmadata
|
||||
build/baserom/Audiobank
|
||||
build/baserom/Audioseq
|
||||
build/baserom/Audiotable
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -29,7 +29,7 @@ if __name__ == "__main__":
|
|||
for base_file, comp_file, alignment, size_if_missing in dmadata_table:
|
||||
try:
|
||||
file_name = base_file.split('/')[-1]
|
||||
uncompressed = comp_file == ''
|
||||
uncompressed = comp_file == '' or args.uncompressed
|
||||
missing = base_file == '' and comp_file == ''
|
||||
blank = missing and size_if_missing == 0
|
||||
is_dmadata = base_file.endswith('dmadata')
|
||||
|
@ -48,7 +48,7 @@ if __name__ == "__main__":
|
|||
phys_size = vrom_size
|
||||
else:
|
||||
vrom_size = os.path.getsize(base_file)
|
||||
if uncompressed or args.uncompressed:
|
||||
if uncompressed:
|
||||
phys_size = vrom_size
|
||||
else:
|
||||
phys_size = os.path.getsize(comp_file)
|
||||
|
@ -68,7 +68,7 @@ if __name__ == "__main__":
|
|||
phys_end = 0xFFFFFFFF
|
||||
else:
|
||||
phys_start = align_up(curr_phys, 0x10)
|
||||
phys_end = 0 if uncompressed else phys_start + phys_size
|
||||
phys_end = 0 if uncompressed or is_dmadata else phys_start + phys_size
|
||||
|
||||
curr_vrom = align_up(curr_vrom, alignment) + vrom_size
|
||||
curr_phys = align_up(curr_phys, 0x10) + phys_size
|
||||
|
@ -79,7 +79,8 @@ if __name__ == "__main__":
|
|||
dmadata.write(phys_end.to_bytes(4, 'big'))
|
||||
|
||||
if base_file != '':
|
||||
linker_info.append((os.path.basename(base_file), vrom_start, vrom_end))
|
||||
file_name = 'dmadata' if is_dmadata else base_file
|
||||
linker_info.append((os.path.basename(file_name), vrom_start, vrom_end))
|
||||
except:
|
||||
print('Error when processing entry ' + base_file)
|
||||
sys.exit(1)
|
||||
|
|
|
@ -38,6 +38,7 @@ if __name__ == "__main__":
|
|||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('files', help='file list')
|
||||
parser.add_argument('out', help='output file')
|
||||
parser.add_argument('-c', '--compress', help='decompress file, otherwise compress it', action='store_true', default=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
outputBuffer = bytearray()
|
||||
|
@ -47,23 +48,20 @@ if __name__ == "__main__":
|
|||
|
||||
dmadata_table = ast.literal_eval(f.read())
|
||||
for base_file, comp_file, _, _ in dmadata_table:
|
||||
if base_file.endswith('dmadata'):
|
||||
dma_file_name = base_file
|
||||
break
|
||||
if args.compress:
|
||||
if comp_file.endswith('dmadata'):
|
||||
dma_file_name = comp_file
|
||||
break
|
||||
else:
|
||||
if base_file.endswith('dmadata'):
|
||||
dma_file_name = base_file
|
||||
break
|
||||
else:
|
||||
print('Could not find dmadata')
|
||||
sys.exit(1)
|
||||
|
||||
has_compressed_files = False
|
||||
with open(dma_file_name, 'rb') as dma_file:
|
||||
dma_data = dma_file.read()
|
||||
for i in range(0xC, len(dma_data), 0x10):
|
||||
if read_uint32_be(dma_data, i) != 0:
|
||||
has_compressed_files = True
|
||||
break
|
||||
|
||||
for base_file, comp_file, _, _ in dmadata_table:
|
||||
file_name = base_file if not has_compressed_files or comp_file == '' else comp_file
|
||||
file_name = comp_file if args.compress and comp_file != '' else base_file
|
||||
if file_name != '':
|
||||
try:
|
||||
with open(file_name, 'rb') as current_file:
|
||||
|
|
Loading…
Reference in New Issue