1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-10-20 05:30:26 +00:00

Add GCC compiler option. (#1056)

* GCC support.

* Add note about gcc-mips-linux-gnu requirement to README.md.

* changes

* changes based on Tharo's suggestion

* Cant reproduce file_choose.h error. Removing unnecessary -I

* changes

* wording based on Fig's suggestion

* add AVOID_UB for eyes/mouth reordering issue.

* remove unneeded flags and deprecate ZAPDFLAGS.

* some changes, waiting on prs for the rest

* fixes

* discard header sections

* change section handling in mkldscript

* avoid_ub in DmaMgr_GetFileNameImpl

* move asm to inline asm (consolidate gcc functions)

* change prefix back

* remove space

* fix warnings

* Revert "remove space"

This reverts commit 94af6977b3.

* Revert "fix warnings"

This reverts commit d729ddf457.

* finish up missing_gcc_functions

* revert unwanted mkldscript change

* temporary workaround. TODO: Stop the asm processor from choking

* fix ido build

* Revert "temporary workaround. TODO: Stop the asm processor from choking"

This reverts commit 9df892b7ac.

* review

* remove unused line in mkldscript

* remove tabs

* clarify zf comment

* review2

* review

* remove duplicate cc_check

* vanilla code always come first

* std_dma avoid ub

* add compiler_gcc to cflags

* only use two blocks when necessary

* clarify zf comment

Co-authored-by: fig02 <fig02srl@gmail.com>
This commit is contained in:
Revo 2022-02-19 16:50:56 -05:00 committed by GitHub
commit c3533052ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 420 additions and 42 deletions

View file

@ -8,14 +8,32 @@ COMPARE ?= 1
NON_MATCHING ?= 0
# If ORIG_COMPILER is 1, compile with QEMU_IRIX and the original compiler
ORIG_COMPILER ?= 0
# If COMPILER is "gcc", compile with GCC instead of IDO.
COMPILER ?= ido
CFLAGS ?=
CPPFLAGS ?=
# ORIG_COMPILER cannot be combined with a non-IDO compiler. Check for this case and error out if found.
ifneq ($(COMPILER),ido)
ifeq ($(ORIG_COMPILER),1)
$(error ORIG_COMPILER can only be used with the IDO compiler. Please check your Makefile variables and try again)
endif
endif
ifeq ($(COMPILER),gcc)
CFLAGS += -DCOMPILER_GCC
CPPFLAGS += -DCOMPILER_GCC
NON_MATCHING := 1
endif
# Set prefix to mips binutils binaries (mips-linux-gnu-ld => 'mips-linux-gnu-') - Change at your own risk!
# In nearly all cases, not having 'mips-linux-gnu-*' binaries on the PATH is indicative of missing dependencies
MIPS_BINUTILS_PREFIX ?= mips-linux-gnu-
ifeq ($(NON_MATCHING),1)
CFLAGS := -DNON_MATCHING
CPPFLAGS := -DNON_MATCHING
CFLAGS += -DNON_MATCHING
CPPFLAGS += -DNON_MATCHING
COMPARE := 0
endif
@ -45,8 +63,17 @@ ifneq ($(shell type $(MIPS_BINUTILS_PREFIX)ld >/dev/null 2>/dev/null; echo $$?),
$(error Please install or build $(MIPS_BINUTILS_PREFIX))
endif
CC := tools/ido_recomp/$(DETECTED_OS)/7.1/cc
CC_OLD := tools/ido_recomp/$(DETECTED_OS)/5.3/cc
# Detect compiler and set variables appropriately.
ifeq ($(COMPILER),gcc)
CC := $(MIPS_BINUTILS_PREFIX)gcc
else
ifeq ($(COMPILER),ido)
CC := tools/ido_recomp/$(DETECTED_OS)/7.1/cc
CC_OLD := tools/ido_recomp/$(DETECTED_OS)/5.3/cc
else
$(error Unsupported compiler. Please use either ido or gcc as the COMPILER variable.)
endif
endif
# if ORIG_COMPILER is 1, check that either QEMU_IRIX is set or qemu-irix package installed
ifeq ($(ORIG_COMPILER),1)
@ -71,7 +98,6 @@ INC := -Iinclude -Isrc -Iassets -Ibuild -I.
# Check code syntax with host compiler
CHECK_WARNINGS := -Wall -Wextra -Wno-format-security -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-variable -Wno-missing-braces -Wno-int-conversion
CC_CHECK := gcc -fno-builtin -fsyntax-only -fsigned-char -std=gnu90 -D _LANGUAGE_C -D NON_MATCHING $(INC) $(CHECK_WARNINGS)
CPP := cpp
MKLDSCRIPT := tools/mkldscript
@ -80,19 +106,34 @@ ELF2ROM := tools/elf2rom
ZAPD := tools/ZAPD/ZAPD.out
FADO := tools/fado/fado.elf
OPTFLAGS := -O2
ASFLAGS := -march=vr4300 -32 -Iinclude
MIPS_VERSION := -mips2
# 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 $(INC) -Wab,-r4300_mul -woff 649,838,712
ifeq ($(shell getconf LONG_BIT), 32)
# Work around memory allocation bug in QEMU
export QEMU_GUEST_BASE := 1
ifeq ($(COMPILER),gcc)
OPTFLAGS := -Os -ffast-math -fno-unsafe-math-optimizations
else
# Ensure that gcc treats the code as 32-bit
CC_CHECK += -m32
OPTFLAGS := -O2
endif
ASFLAGS := -march=vr4300 -32 -Iinclude
ifeq ($(COMPILER),gcc)
CFLAGS += -G 0 -nostdinc $(INC) -DAVOID_UB -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -mdivide-breaks -fno-zero-initialized-in-bss -fno-toplevel-reorder -ffreestanding -fno-common -fno-merge-constants -mno-explicit-relocs -mno-split-addresses $(CHECK_WARNINGS) -funsigned-char
MIPS_VERSION := -mips3
else
# 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 $(INC) -Wab,-r4300_mul -woff 649,838,712
MIPS_VERSION := -mips2
endif
ifeq ($(COMPILER),ido)
CC_CHECK = gcc -fno-builtin -fsyntax-only -funsigned-char -std=gnu90 -D_LANGUAGE_C -DNON_MATCHING $(INC) $(CHECK_WARNINGS)
ifeq ($(shell getconf LONG_BIT), 32)
# Work around memory allocation bug in QEMU
export QEMU_GUEST_BASE := 1
else
# Ensure that gcc (warning check) treats the code as 32-bit
CC_CHECK += -m32
endif
else
CC_CHECK = @:
endif
#### Files ####
@ -103,7 +144,12 @@ ELF := $(ROM:.z64=.elf)
# description of ROM segments
SPEC := spec
ifeq ($(COMPILER),ido)
SRC_DIRS := $(shell find src -type d -not -path src/gcc_fix)
else
SRC_DIRS := $(shell find src -type d)
endif
ASM_DIRS := $(shell find asm -type d -not -path "asm/non_matchings*") $(shell find data -type d)
ASSET_BIN_DIRS := $(shell find assets/* -type d -not -path "assets/xml*" -not -path "assets/text")
ASSET_FILES_XML := $(foreach dir,$(ASSET_BIN_DIRS),$(wildcard $(dir)/*.xml))
@ -134,6 +180,7 @@ TEXTURE_FILES_OUT := $(foreach f,$(TEXTURE_FILES_PNG:.png=.inc.c),build/$f) \
# create build directories
$(shell mkdir -p build/baserom build/assets/text $(foreach dir,$(SRC_DIRS) $(ASM_DIRS) $(ASSET_BIN_DIRS),build/$(dir)))
ifeq ($(COMPILER),ido)
build/src/code/fault.o: CFLAGS += -trapuv
build/src/code/fault.o: OPTFLAGS := -O2 -g3
build/src/code/fault_drawer.o: CFLAGS += -trapuv
@ -172,6 +219,10 @@ build/src/code/%.o: CC := python3 tools/asm_processor/build.py $(CC) -- $(AS) $(
build/src/overlays/%.o: CC := python3 tools/asm_processor/build.py $(CC) -- $(AS) $(ASFLAGS) --
build/assets/%.o: CC := python3 tools/asm_processor/build.py $(CC) -- $(AS) $(ASFLAGS) --
else
build/src/libultra/libc/ll.o: OPTFLAGS := -Ofast
build/src/%.o: CC := $(CC) -fexec-charset=euc-jp
endif
#### Main Targets ###