Set up Makefile for modern building (#1)

* set build options

* remove COMPARE and MDOERN_* switches

* remove tools makefile

* AR patching is gone too since we want a fullly decomped version

* AR is modern

* remove cwd changes

* edit my own tool to fix compile errors

* compile files generated with my own tool instead of the originals

* inline modern_gcc makefile

* port mips toolchain detection logic

* add util.mk for find-command

* remove forced AR order and strip/mdebug removal commands

* add -mabi=32 to as flags

---------

Co-authored-by: someone2639 <someone2639@gmail.com>
This commit is contained in:
someone2639
2025-02-17 11:28:31 -05:00
committed by GitHub
parent 2717d451b9
commit efbd931cbc
8 changed files with 84 additions and 372 deletions

234
Makefile
View File

@@ -1,34 +1,39 @@
COMPARE ?= 1
MODERN_LD ?= 0
MODERN_GCC ?= 0
ifneq ($(MODERN_LD),0)
COMPARE := 0
endif
# One of:
# libgultra_rom, libgultra_d, libgultra
# libultra_rom, libultra_d, libultra
TARGET ?= libgultra_rom
VERSION ?= L
CROSS ?= mips-linux-gnu-
VERBOSE ?= 0
ifeq ($(findstring libgultra,$(TARGET)),libgultra)
COMPILER := gcc
else ifeq ($(findstring libultra,$(TARGET)),libultra)
COMPILER := ido
include util.mk
ifeq ($(VERBOSE), 0)
V=@
else
$(error Invalid Target)
V=
endif
ifneq ($(MODERN_GCC),0)
COMPILER := modern_gcc
COMPARE := 0
MODERN_LD := 0
# detect prefix for MIPS toolchain
ifneq ($(call find-command,mips64-elf-ld),)
CROSS := mips64-elf-
else ifneq ($(call find-command,mips-n64-ld),)
CROSS := mips-n64-
else ifneq ($(call find-command,mips64-ld),)
CROSS := mips64-
else ifneq ($(call find-command,mips-linux-gnu-ld),)
CROSS := mips-linux-gnu-
else ifneq ($(call find-command,mips64-linux-gnu-ld),)
CROSS := mips64-linux-gnu-
else ifneq ($(call find-command,mips64-none-elf-ld),)
CROSS := mips64-none-elf-
else ifneq ($(call find-command,mips-ld),)
CROSS := mips-
else ifneq ($(call find-command,mips-suse-linux-ld ),)
CROSS := mips-suse-linux-
else
$(error Unable to detect a suitable MIPS toolchain installed)
endif
BASE_DIR := extracted/$(VERSION)/$(TARGET)
BASE_AR := base/$(VERSION)/$(TARGET).a
BUILD_ROOT := build
BUILD_DIR := $(BUILD_ROOT)/$(VERSION)/$(TARGET)
BUILD_AR := $(BUILD_DIR)/$(TARGET).a
@@ -46,17 +51,24 @@ else
DEBUGFLAG := -DNDEBUG
endif
ifeq ($(COMPILER),gcc)
-include makefiles/gcc.mk
else ifeq ($(COMPILER),ido)
-include makefiles/ido.mk
else ifeq ($(COMPILER),modern_gcc)
-include makefiles/modern_gcc.mk
else
$(error Invalid Compiler)
endif
AS := $(CROSS)gcc -x assembler-with-cpp
CC := $(CROSS)gcc
export COMPILER_PATH := $(COMPILER_DIR)
WARNINGS := -Wall -Wextra -Wno-format-security -Wno-unused-function -Wno-unused-parameter -Wno-unused-variable -Wno-builtin-declaration-mismatch
WARNINGS += -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-implicit-function-declaration # TODO: Try adjusting code to remove these
CFLAGS := -G 0 -c -nostdinc -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -mdivide-breaks -fno-PIC -fno-common -ffreestanding -fbuiltin -fno-builtin-sinf -fno-builtin-cosf -funsigned-char $(WARNINGS)
CFLAGS += -fno-strict-aliasing # TODO: Try adjusting code to remove this
ASFLAGS := -w -nostdinc -c -G 0 -march=vr4300 -mabi=32 -mgp32 -mfp32 -DMIPSEB -D_LANGUAGE_ASSEMBLY -D_MIPS_SIM=1 -D_ULTRA64
CPPFLAGS = -DMODERN_CC -D_MIPS_SZLONG=32 -D__USE_ISOC99 $(GBIDEFINE) $(VERSION_DEFINE) $(DEBUGFLAG)
IINC = -I . -I $(WORKING_DIR)/include -I $(WORKING_DIR)/include/compiler/modern_gcc -I $(WORKING_DIR)/include/PR
MIPS_VERSION := -mips3
ASOPTFLAGS :=
ifeq ($(findstring _d,$(TARGET)),_d)
OPTFLAGS := -Og -ggdb3 -ffast-math -fno-unsafe-math-optimizations
else
OPTFLAGS := -Os -ggdb3 -ffast-math -fno-unsafe-math-optimizations
endif
ifeq ($(findstring _rom,$(TARGET)),_rom)
CPPFLAGS += -D_FINALROM
@@ -77,166 +89,44 @@ endif
C_O_FILES := $(foreach f,$(C_FILES:.c=.o),$(BUILD_DIR)/$f)
S_O_FILES := $(foreach f,$(S_FILES:.s=.o),$(BUILD_DIR)/$f)
O_FILES := $(S_O_FILES) $(C_O_FILES)
# Because we patch the object file timestamps, we can't use them as the targets since they'll always be older than the C file
# Therefore instead we use marker files that have actual timestamps as the dependencies for the archive
C_MARKER_FILES := $(C_O_FILES:.o=.marker)
S_MARKER_FILES := $(S_O_FILES:.o=.marker)
S_MARKER_FILES := $(filter-out $(MDEBUG_FILES),$(S_MARKER_FILES))
MARKER_FILES := $(C_MARKER_FILES) $(S_MARKER_FILES) $(MDEBUG_FILES)
ifneq ($(COMPARE),0)
COMPARE_OBJ = cmp $(BASE_DIR)/$(@F:.marker=.o) $(@:.marker=.o) && echo "$(@:.marker=.o): OK"
COMPARE_AR = cmp $(BASE_AR) $@ && echo "$@: OK"
ifeq ($(COMPILER),ido)
COMPARE_OBJ = $(CROSS)objcopy -p --strip-debug $(WORKING_DIR)/$(@:.marker=.o) $(WORKING_DIR)/$(@:.marker=.cmp.o) && \
cmp $(BASE_DIR)/.cmp/$(@F:.marker=.cmp.o) $(WORKING_DIR)/$(@:.marker=.cmp.o) && echo "$(@:.marker=.o): OK"
COMPARE_AR = echo "$@: Cannot compare archive currently"
endif
else
COMPARE_OBJ :=
COMPARE_AR :=
AR_OLD := $(AR)
endif
BASE_OBJS := $(wildcard $(BASE_DIR)/*.o)
# Check to make sure the current version has been set up
ifneq ($(COMPARE),0)
ifeq ($(BASE_OBJS),)
# Ignore this check if the user is currently running setup, clean or distclean
ifeq ($(filter $(MAKECMDGOALS),setup clean distclean),)
$(error Current version ($(TARGET) 2.0$(VERSION)) has not been setup!)
endif
endif
endif
AR_OBJECTS := $(shell cat base/$(VERSION)/$(TARGET).txt)
# If the version and target doesn't have a text file yet, resort back to using the base archive to get objects
ifeq ($(AR_OBJECTS),)
AR_OBJECTS := $(shell ar t $(BASE_AR))
endif
# Try to find a file corresponding to an archive file in src/ or the base directory, prioritizing src then the original file
AR_ORDER = $(foreach f,$(AR_OBJECTS),$(shell find $(BUILD_DIR)/src $(BASE_DIR) -iname $f -type f -print -quit))
MATCHED_OBJS = $(filter-out $(BASE_DIR)/%,$(AR_ORDER))
UNMATCHED_OBJS = $(filter-out $(MATCHED_OBJS),$(AR_ORDER))
NUM_OBJS = $(words $(AR_ORDER))
NUM_OBJS_MATCHED = $(words $(MATCHED_OBJS))
NUM_OBJS_UNMATCHED = $(words $(UNMATCHED_OBJS))
$(shell mkdir -p $(BASE_DIR) src $(foreach dir,$(SRC_DIRS),$(BUILD_DIR)/$(dir)))
$(shell mkdir -p src $(foreach dir,$(SRC_DIRS),$(BUILD_DIR)/$(dir)))
.PHONY: all clean distclean setup
all: $(BUILD_AR)
$(BUILD_AR): $(MARKER_FILES)
$(AR_OLD) rcs $@ $(AR_ORDER)
ifneq ($(COMPARE),0)
# patch archive creation time and individual files' ownership & permissions
dd bs=1 skip=24 seek=24 count=12 conv=notrunc if=$(BASE_AR) of=$@ status=none
python3 tools/patch_ar_meta.py $@ $(BASE_AR) $(PATCH_AR_FLAGS)
@$(COMPARE_AR)
@echo "Matched: $(NUM_OBJS_MATCHED)/$(NUM_OBJS)"
endif
$(BUILD_AR): $(O_FILES)
@printf " [AR] $@\n"
$(V)$(AR) rcs $@ $^
clean:
$(RM) -rf $(BUILD_DIR)
distclean:
$(MAKE) -C tools distclean
$(RM) -rf extracted/ $(BUILD_ROOT)
setup:
$(MAKE) -C tools
ifneq ($(COMPARE),0)
cd $(BASE_DIR) && $(AR) xo $(WORKING_DIR)/$(BASE_AR)
chmod -R +rw $(BASE_DIR)
ifeq ($(COMPILER),ido)
export CROSS=$(CROSS) && ./tools/strip_debug.sh $(BASE_DIR)
endif
endif
$(BUILD_DIR)/$(BASE_DIR)/%.marker: $(BASE_DIR)/%.o
cp $< $(@:.marker=.o)
ifneq ($(COMPARE),0)
# change file timestamps to match original
@touch -r $(BASE_DIR)/$(@F:.marker=.o) $(@:.marker=.o)
@$(COMPARE_OBJ)
@touch $@
endif
GBIDEFINE := -DF3DEX_GBI
$(BUILD_DIR)/src/gu/parse_gbi.marker: GBIDEFINE := -DF3D_GBI
$(BUILD_DIR)/src/gu/us2dex_emu.marker: GBIDEFINE :=
$(BUILD_DIR)/src/gu/us2dex2_emu.marker: GBIDEFINE :=
$(BUILD_DIR)/src/sp/sprite.marker: GBIDEFINE := -DF3D_GBI
$(BUILD_DIR)/src/sp/spriteex.marker: GBIDEFINE :=
$(BUILD_DIR)/src/sp/spriteex2.marker: GBIDEFINE :=
$(BUILD_DIR)/src/voice/%.marker: OPTFLAGS += -DLANG_JAPANESE -I$(WORKING_DIR)/src -I$(WORKING_DIR)/src/voice
$(BUILD_DIR)/src/voice/%.marker: CC := $(WORKING_DIR)/tools/compile_sjis.py -D__CC=$(CC) -D__BUILD_DIR=$(BUILD_DIR)
$(BUILD_DIR)/src/gu/parse_gbi.o: GBIDEFINE := -DF3D_GBI
$(BUILD_DIR)/src/gu/us2dex_emu.o: GBIDEFINE :=
$(BUILD_DIR)/src/gu/us2dex2_emu.o: GBIDEFINE :=
$(BUILD_DIR)/src/sp/sprite.o: GBIDEFINE := -DF3D_GBI
$(BUILD_DIR)/src/sp/spriteex.o: GBIDEFINE :=
$(BUILD_DIR)/src/sp/spriteex2.o: GBIDEFINE :=
$(BUILD_DIR)/src/voice/%.o: OPTFLAGS += -DLANG_JAPANESE -I$(WORKING_DIR)/src -I$(WORKING_DIR)/src/voice
$(BUILD_DIR)/src/voice/%.o: CC := $(WORKING_DIR)/tools/compile_sjis.py -D__CC=$(CC) -D__BUILD_DIR=$(BUILD_DIR)
$(C_MARKER_FILES): $(BUILD_DIR)/%.marker: %.c
cd $(<D) && $(CC) $(CFLAGS) $(MIPS_VERSION) $(CPPFLAGS) $(OPTFLAGS) $(<F) $(IINC) -o $(WORKING_DIR)/$(@:.marker=.o)
ifneq ($(COMPARE),0)
# check if this file is in the archive; patch corrupted bytes and change file timestamps to match original if so
@$(if $(findstring $(BASE_DIR)/$(@F:.marker=.o), $(BASE_OBJS)), \
python3 tools/fix_objfile.py $(@:.marker=.o) $(BASE_DIR)/$(@F:.marker=.o) $(STRIP) && \
$(COMPARE_OBJ) && \
touch -r $(BASE_DIR)/$(@F:.marker=.o) $(@:.marker=.o), \
echo "Object file $(@F:.marker=.o) is not in the current archive" \
)
endif
ifneq ($(MODERN_LD),0)
tools/set_o32abi_bit.py $(WORKING_DIR)/$(@:.marker=.o)
$(CROSS)strip $(WORKING_DIR)/$(@:.marker=.o) -N asdasdasdasd
$(CROSS)objcopy --remove-section .mdebug $(WORKING_DIR)/$(@:.marker=.o)
endif
# create or update the marker file
@touch $@
$(BUILD_DIR)/%.o: %.c
@printf " [CC] $<\n"
$(V)$(CC) $(CFLAGS) $(MIPS_VERSION) $(CPPFLAGS) $(OPTFLAGS) $< $(IINC) -o $@
$(V)tools/set_o32abi_bit.py $@
$(S_MARKER_FILES): $(BUILD_DIR)/%.marker: %.s
cd $(<D) && $(AS) $(ASFLAGS) $(MIPS_VERSION) $(CPPFLAGS) $(ASOPTFLAGS) $(<F) $(IINC) -o $(WORKING_DIR)/$(@:.marker=.o)
ifneq ($(COMPARE),0)
# check if this file is in the archive; patch corrupted bytes and change file timestamps to match original if so
@$(if $(findstring $(BASE_DIR)/$(@F:.marker=.o), $(BASE_OBJS)), \
python3 tools/fix_objfile.py $(@:.marker=.o) $(BASE_DIR)/$(@F:.marker=.o) $(STRIP) && \
$(COMPARE_OBJ) && \
touch -r $(BASE_DIR)/$(@F:.marker=.o) $(@:.marker=.o), \
echo "Object file $(@F:.marker=.o) is not in the current archive" \
)
endif
ifneq ($(MODERN_LD),0)
tools/set_o32abi_bit.py $(WORKING_DIR)/$(@:.marker=.o)
$(CROSS)strip $(WORKING_DIR)/$(@:.marker=.o) -N asdasdasdasd
$(CROSS)objcopy --remove-section .mdebug $(WORKING_DIR)/$(@:.marker=.o)
endif
# create or update the marker file
@touch $@
# Rule for building files that require specific file paths in the mdebug section
$(MDEBUG_FILES): $(BUILD_DIR)/src/%.marker: src/%.s
cp $(<:.marker=.s) $(dir $@)
mkdir -p $(@:.marker=)
export USR_INCLUDE=$(WORKING_DIR)/include && cd $(@:.marker=) && $(AS) $(ASFLAGS) $(CPPFLAGS) ../$(<F) -I/usr/include -o $(notdir $(<:.s=.o))
mv $(@:.marker=)/$(<F:.s=.o) $(@:.marker=)/..
ifneq ($(COMPARE),0)
# check if this file is in the archive; patch corrupted bytes and change file timestamps to match original if so
@$(if $(findstring $(BASE_DIR)/$(@F:.marker=.o), $(BASE_OBJS)), \
python3 tools/fix_objfile.py $(@:.marker=.o) $(BASE_DIR)/$(@F:.marker=.o) && \
$(COMPARE_OBJ) && \
touch -r $(BASE_DIR)/$(@F:.marker=.o) $(@:.marker=.o), \
echo "Object file $(@F:.marker=.o) is not in the current archive" \
)
endif
ifneq ($(MODERN_LD),0)
tools/set_o32abi_bit.py $(WORKING_DIR)/$(@:.marker=.o)
$(CROSS)strip $(WORKING_DIR)/$(@:.marker=.o) -N asdasdasdasd
$(CROSS)objcopy --remove-section .mdebug $(WORKING_DIR)/$(@:.marker=.o)
endif
# create or update the marker file
@touch $@
$(BUILD_DIR)/%.o: %.s
@printf " [AS] $<\n"
$(V)$(AS) $(ASFLAGS) $(MIPS_VERSION) $(CPPFLAGS) $(ASOPTFLAGS) $< $(IINC) -o $@
$(V)tools/set_o32abi_bit.py $@
# Disable built-in rules
.SUFFIXES:

View File

@@ -1,3 +1,3 @@
#ifdef __GNUC__
#include "gcc/sgidefs.h"
#include "compiler/modern_gcc/sgidefs.h"
#endif

View File

@@ -1,66 +0,0 @@
COMPILER_DIR := $(WORKING_DIR)/tools/gcc
AS := $(COMPILER_DIR)/gcc -x assembler-with-cpp
CC := $(COMPILER_DIR)/gcc
AR_OLD := $(COMPILER_DIR)/ar
PATCH_AR_FLAGS := 0 0 37777700
STRIP =
CFLAGS := -w -nostdinc -c -G 0 -mgp32 -mfp32 -D_LANGUAGE_C
ASFLAGS := -w -nostdinc -c -G 0 -mgp32 -mfp32 -DMIPSEB -D_LANGUAGE_ASSEMBLY -D_MIPS_SIM=1 -D_ULTRA64
CPPFLAGS = -D_MIPS_SZLONG=32 -D__USE_ISOC99 $(GBIDEFINE) $(VERSION_DEFINE) $(DEBUGFLAG)
IINC = -I . -I $(WORKING_DIR)/include -I $(WORKING_DIR)/include/compiler/gcc -I $(WORKING_DIR)/include/PR
MIPS_VERSION := -mips3
ASOPTFLAGS :=
ifneq ($(filter $(VERSION),D E F G H I J),)
CFLAGS += -funsigned-char
endif
# 2.0I libgultra_rom was not compiled with -DNDEBUG and instead libgultra had -DNDEBUG
ifneq ($(filter $(VERSION),I),)
ifeq ($(findstring _rom,$(TARGET)),_rom)
DEBUGFLAG :=
else ifeq ($(findstring _d,$(TARGET)),_d)
DEBUGFLAG := -D_DEBUG
else
DEBUGFLAG := -DNDEBUG
endif
endif
ifeq ($(findstring _d,$(TARGET)),_d)
OPTFLAGS := -O0
else
OPTFLAGS := -O3
endif
ifeq ($(findstring _d,$(TARGET)),_d)
$(BUILD_DIR)/src/rmon/%.marker: OPTFLAGS := -O0
endif
# KMC gcc has a custom flag, N64ALIGN, which forces 8 byte alignment on arrays. This can be used to match, but
# an explicit aligned(8) attribute can be used instead. We opted for the latter for better compatibilty with
# other versions of GCC that do not have this flag.
# export N64ALIGN := ON
export VR4300MUL := ON
$(BUILD_DIR)/src/os/initialize_isv.marker: OPTFLAGS := -O2
$(BUILD_DIR)/src/os/initialize_isv.marker: STRIP = && $(COMPILER_DIR)/strip-2.7 -N initialize_isv.c $(WORKING_DIR)/$(@:.marker=.o)
$(BUILD_DIR)/src/os/assert.marker: OPTFLAGS := -O0
ifeq ($(filter $(VERSION),D E F G H I),)
$(BUILD_DIR)/src/os/seterrorhandler.marker: OPTFLAGS := -O0
endif
$(BUILD_DIR)/src/mgu/%.marker: export VR4300MUL := OFF
$(BUILD_DIR)/src/mgu/rotate.marker: export VR4300MUL := ON
$(BUILD_DIR)/src/debug/%.marker: ASFLAGS += -P
$(BUILD_DIR)/src/error/%.marker: ASFLAGS += -P
$(BUILD_DIR)/src/log/%.marker: ASFLAGS += -P
$(BUILD_DIR)/src/os/%.marker: ASFLAGS += -P
$(BUILD_DIR)/src/gu/%.marker: ASFLAGS += -P
$(BUILD_DIR)/src/libc/%.marker: ASFLAGS += -P
$(BUILD_DIR)/src/rmon/%.marker: ASFLAGS += -P
$(BUILD_DIR)/src/host/host_ptn64.marker: CFLAGS += -fno-builtin # Probably a better way to solve this
MDEBUG_FILES := $(BUILD_DIR)/src/monutil.marker
MDEBUG_COMPILER_DIR := $(WORKING_DIR)/tools/ido
$(MDEBUG_FILES): AS := $(MDEBUG_COMPILER_DIR)/cc
$(MDEBUG_FILES): ASFLAGS := -non_shared -mips2 -fullwarn -verbose -Xcpluscomm -G 0 -woff 516,649,838,712 -Wab,-r4300_mul -nostdinc -o32 -c

View File

@@ -1,58 +0,0 @@
COMPILER_DIR := $(WORKING_DIR)/tools/ido
AS := $(COMPILER_DIR)/cc
CC := $(COMPILER_DIR)/cc
AR_OLD := $(WORKING_DIR)/tools/ar.py
PATCH_AR_FLAGS := 40001 110 100644
STRIP =
CFLAGS := -c -Wab,-r4300_mul -G 0 -nostdinc -Xcpluscomm -fullwarn -woff 516,649,838,712
ASFLAGS := -c -Wab,-r4300_mul -G 0 -nostdinc -woff 516,649,838,712
CPPFLAGS = -D_MIPS_SZLONG=32 $(GBIDEFINE) $(VERSION_DEFINE) $(PICFLAGS) $(DEBUGFLAG)
IINC = -I $(WORKING_DIR)/include -I $(WORKING_DIR)/include/compiler/ido -I $(WORKING_DIR)/include/PR
MIPS_VERSION := -mips2 -o32
PICFLAGS := -non_shared
ifeq ($(findstring _d,$(TARGET)),_d)
OPTFLAGS := -O1 -g2
ASOPTFLAGS := -O0 -g2
else
ifneq ($(filter $(VERSION),D E F G H I),)
OPTFLAGS := -O1
else
OPTFLAGS := -O2
endif
ASOPTFLAGS := -O1
endif
ifneq ($(findstring _d,$(TARGET)),_d)
$(BUILD_DIR)/src/debug/%.marker: OPTFLAGS := -O1
$(BUILD_DIR)/src/host/%.marker: OPTFLAGS := -O1
$(BUILD_DIR)/src/os/%.marker: OPTFLAGS := -O1
$(BUILD_DIR)/src/rmon/%.marker: OPTFLAGS := -O1
$(BUILD_DIR)/src/libc/ll.marker: OPTFLAGS := -O1
$(BUILD_DIR)/src/libc/llbit.marker: OPTFLAGS := -O1
$(BUILD_DIR)/src/libc/llcvt.marker: OPTFLAGS := -O1
$(BUILD_DIR)/src/log/%.marker: OPTFLAGS := -O1
$(BUILD_DIR)/src/libc/%.marker: ASOPTFLAGS := -O2
$(BUILD_DIR)/src/mgu/%.marker: ASOPTFLAGS := -O2
endif
$(BUILD_DIR)/src/os/initialize_isv.marker: OPTFLAGS := -O2
$(BUILD_DIR)/src/libc/ll.marker: MIPS_VERSION := -mips3 -32
$(BUILD_DIR)/src/libc/llbit.marker: MIPS_VERSION := -mips3 -32
$(BUILD_DIR)/src/libc/llcvt.marker: MIPS_VERSION := -mips3 -32
$(BUILD_DIR)/src/os/exceptasm.marker: MIPS_VERSION := -mips3 -32
$(BUILD_DIR)/src/log/delay.marker: MIPS_VERSION := -mips1 -o32
$(BUILD_DIR)/src/log/delay.marker: PICFLAGS := -KPIC
ifneq ($(filter $(VERSION),D E F G H I),)
$(BUILD_DIR)/src/libc/%.marker: OPTFLAGS := -O3
$(BUILD_DIR)/src/sched/%.marker: OPTFLAGS := -O3
$(BUILD_DIR)/src/gu/%.marker: OPTFLAGS := -O3
$(BUILD_DIR)/src/mgu/%.marker: OPTFLAGS := -O3
$(BUILD_DIR)/src/sp/%.marker: OPTFLAGS := -O3
$(BUILD_DIR)/src/audio/%.marker: OPTFLAGS := -O3
$(BUILD_DIR)/src/rg/%.marker: OPTFLAGS := -O3
$(BUILD_DIR)/src/gt/%.marker: OPTFLAGS := -O3
endif

View File

@@ -1,21 +0,0 @@
COMPILER_DIR := $(dir $(which $(CROSS)gcc))
AS := $(CROSS)gcc -x assembler-with-cpp
CC := $(CROSS)gcc
AR_OLD := $(CROSS)ar
WARNINGS := -Wall -Wextra -Wno-format-security -Wno-unused-function -Wno-unused-parameter -Wno-unused-variable -Wno-builtin-declaration-mismatch
WARNINGS += -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-implicit-function-declaration # TODO: Try adjusting code to remove these
CFLAGS := -G 0 -c -nostdinc -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -mdivide-breaks -fno-PIC -fno-common -ffreestanding -fbuiltin -fno-builtin-sinf -fno-builtin-cosf -funsigned-char $(WARNINGS)
CFLAGS += -fno-strict-aliasing # TODO: Try adjusting code to remove this
ASFLAGS := -w -nostdinc -c -G 0 -march=vr4300 -mgp32 -mfp32 -DMIPSEB -D_LANGUAGE_ASSEMBLY -D_MIPS_SIM=1 -D_ULTRA64
CPPFLAGS = -DMODERN_CC -D_MIPS_SZLONG=32 -D__USE_ISOC99 $(GBIDEFINE) $(VERSION_DEFINE) $(DEBUGFLAG)
IINC = -I . -I $(WORKING_DIR)/include -I $(WORKING_DIR)/include/compiler/modern_gcc -I $(WORKING_DIR)/include/PR
MIPS_VERSION := -mips3
ASOPTFLAGS :=
ifeq ($(findstring _d,$(TARGET)),_d)
OPTFLAGS := -Og -ggdb3 -ffast-math -fno-unsafe-math-optimizations
else
OPTFLAGS := -Os -ggdb3 -ffast-math -fno-unsafe-math-optimizations
endif

View File

@@ -1,46 +0,0 @@
.PHONY: all clean distclean
# GCC
GCC_DIR := gcc
AR := $(GCC_DIR)/ar
GCC-2.7.2 := $(GCC_DIR)/gcc
STRIP-2.7 := $(GCC_DIR)/strip-2.7
# IDO
IDO_DIR := ido
IDO-5.3 := $(IDO_DIR)/cc
all: $(AR) $(GCC-2.7.2) $(STRIP-2.7) $(IDO-5.3)
$(AR): | $(GCC_DIR)
wget https://github.com/decompals/mips-binutils-2.6/releases/download/main/binutils-2.6-linux.tar.gz
tar xf binutils-2.6-linux.tar.gz -C $(GCC_DIR)
$(RM) binutils-2.6-linux.tar.gz
$(GCC-2.7.2): | $(GCC_DIR)
wget https://github.com/decompals/mips-gcc-2.7.2/releases/download/main/gcc-2.7.2-linux.tar.gz
tar xf gcc-2.7.2-linux.tar.gz -C $(GCC_DIR)
$(RM) gcc-2.7.2-linux.tar.gz
$(STRIP-2.7): | $(GCC_DIR)
wget https://github.com/decompals/mips-binutils-2.7/releases/download/release/binutils-2.7.tar.gz
tar xf binutils-2.7.tar.gz -C $(GCC_DIR)
$(RM) binutils-2.7.tar.gz
$(GCC_DIR):
mkdir -p $@
$(IDO-5.3): | $(IDO_DIR)
wget https://github.com/decompals/ido-static-recomp/releases/latest/download/ido-5.3-recomp-linux.tar.gz
tar xf ido-5.3-recomp-linux.tar.gz -C $(IDO_DIR)
$(RM) ido-5.3-recomp-linux.tar.gz
$(IDO_DIR):
mkdir -p $@
clean:
$(RM) -rf $(GCC_DIR)
$(RM) -rf $(IDO_DIR)
distclean: clean

View File

@@ -3,25 +3,22 @@
import sys, os
from shiftjis_conv import sjis_process
os.chdir("../../")
WORKING_DIR = os.getcwd()
fb = []
original_c_file = [i for i in sys.argv if ".c" in i][0]
input_c_file = [i for i in sys.argv if ".c" in i][0]
CC = [i for i in sys.argv if "-D__CC=" in i][0][7:]
build_dir = [i for i in sys.argv if "-D__BUILD_DIR" in i][0][14:]
output_c_file = original_c_file
sys.argv[sys.argv.index(original_c_file)] = output_c_file
output_c_file = f"{build_dir}/{input_c_file}"
original_c_file = "src/voice/" + original_c_file
# Edit compile command to point to the converted file
sys.argv[sys.argv.index(input_c_file)] = output_c_file
with open(original_c_file) as f:
with open(input_c_file) as f:
fb = f.read()
os.chdir(build_dir + "/src/voice")
with open(output_c_file, "w+") as outf:
sjis_process(fb, outf)

16
util.mk Normal file
View File

@@ -0,0 +1,16 @@
# util.mk - Miscellaneous utility functions for use in Makefiles
# Throws an error if the value of the variable named by $(1) is not in the list given by $(2)
define validate-option
# value must be part of the list
ifeq ($$(filter $($(1)),$(2)),)
$$(error Value of $(1) must be one of the following: $(2))
endif
# value must be a single word (no whitespace)
ifneq ($$(words $($(1))),1)
$$(error Value of $(1) must be one of the following: $(2))
endif
endef
# Returns the path to the command $(1) if exists. Otherwise returns an empty string.
find-command = $(shell which $(1) 2>/dev/null)