Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .github/workflows/ci_gcc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CI file for GCC builds

name: Build GCC libgultra
name: Build GCC libultra

# Build on every branch push, tag push, and pull request change:
on: [push, pull_request_target]
Expand All @@ -13,8 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: [L] # [H, I, I_patch, J, K, L]
suffix: [~, _d, _rom]
version: [libultra, libultra_d, libultra_rom]

steps:
- name: Checkout repository
Expand All @@ -28,11 +27,8 @@ jobs:
- name: Verify formatting on all files
run: python3 tools/check_format.py --verbose

- name: Setup
run: make setup -j $(nproc) TARGET=libgultra${{ matrix.suffix }} VERSION=${{ matrix.version }}

- name: Build libgultra${{ matrix.suffix }} ${{ matrix.version }}
run: make -j $(nproc) TARGET=libgultra${{ matrix.suffix }} VERSION=${{ matrix.version }}
- name: Build ${{ matrix.version }}
run: make -j $(nproc) VERSION=${{ matrix.version }}

- name: 'Upload Artifact'
uses: actions/upload-artifact@v4
Expand Down
222 changes: 148 additions & 74 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
# One of:
# libgultra_rom, libgultra_d, libgultra
TARGET ?= libgultra_rom
VERSION ?= L
VERBOSE ?= 0

# Use handwritten ASM implementations of select `gu` functions
MGU_ASM ?= 1
# Makefile to build libultra

include util.mk

ifeq ($(VERBOSE), 0)
V=@
else
V=
# Preprocessor definitions

WORKING_DIR := $(shell pwd)

DEFINES :=

SRC_DIRS :=

# Whether to hide commands or not
VERBOSE ?= 0
ifeq ($(VERBOSE),0)
V := @
endif

# Whether to colorize build messages
COLOR ?= 1

# TARGET - selects the version of the library to build
# libultra - standard library
# libultra_d - debug library
# libultra_rom - final ROM library
TARGET ?= libultra_rom
$(eval $(call validate-option,TARGET,libultra libultra_d libultra_rom))

ifeq ($(TARGET),libultra)
OPT_FLAGS := -Os -ggdb3 -ffast-math -fno-unsafe-math-optimizations
DEFINES += NDEBUG=1
else ifeq ($(TARGET),libultra_d)
OPT_FLAGS := -Og -ggdb3 -ffast-math -fno-unsafe-math-optimizations
DEFINES += _DEBUG=1
else ifeq ($(TARGET),libultra_rom)
OPT_FLAGS := -Os -ggdb3 -ffast-math -fno-unsafe-math-optimizations
DEFINES += NDEBUG=1
DEFINES += _FINALROM=1
endif

# detect prefix for MIPS toolchain
Expand All @@ -36,98 +59,149 @@ else
$(error Unable to detect a suitable MIPS toolchain installed)
endif

BUILD_ROOT := build
BUILD_DIR := $(BUILD_ROOT)/
BUILD_AR := $(BUILD_DIR)/$(TARGET).a
ifeq ($(filter clean,$(MAKECMDGOALS)),)
$(info ==== Build Options ====)
$(info Version: $(TARGET))
$(info =======================)
endif

WORKING_DIR := $(shell pwd)
#==============================================================================#
# Target Executable and Sources #
#==============================================================================#
BUILD_DIR_BASE := build
# BUILD_DIR is the location where all build artifacts are placed
BUILD_DIR := $(BUILD_DIR_BASE)/$(TARGET)
LIB := $(BUILD_DIR)/$(TARGET).a

CPP := cpp -P
AR := $(CROSS)ar
# Directories containing source files
SRC_DIRS += $(shell find src -type d)

VERSION_DEFINE := -DBUILD_VERSION_STRING=\"2.0$(VERSION)\"
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
S_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s))

ifeq ($(findstring _d,$(TARGET)),_d)
DEBUGFLAG := -D_DEBUG
else
DEBUGFLAG := -DNDEBUG
endif
# Object files
O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o))

# Automatic dependency files
DEP_FILES := $(O_FILES:.o=.d)

#==============================================================================#
# Compiler Options #
#==============================================================================#

AS := $(CROSS)as
CC := $(CROSS)gcc
CPP := $(CROSS)cpp
LD := $(CROSS)ld
AR := $(CROSS)ar

AS := $(CROSS)gcc -x assembler-with-cpp
CC := $(CROSS)gcc
# Do NOT depend on system-installed headers! If you need to make a header change,
# test it in your source first!
INCLUDE_DIRS += $(WORKING_DIR)/include $(WORKING_DIR)/include/PR $(WORKING_DIR)/include/compiler/modern_gcc $(BUILD_DIR) $(BUILD_DIR)/include $(WORKING_DIR)/src $(WORKING_DIR)

GBIDEFINE := -DF3DEX_GBI_2

C_DEFINES = $(foreach d,$(DEFINES),-D$(d))
DEF_INC_CFLAGS = $(foreach i,$(INCLUDE_DIRS),-I$(i)) $(C_DEFINES)

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 := -G 0 -c -nostdinc -march=vr4300 -mfix4300 -mabi=32 -mips3 -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
CFLAGS += -D_MIPS_SZLONG=32 -D__USE_ISOC99 $(C_DEFINES) $(DEF_INC_CFLAGS)

ifeq ($(findstring _rom,$(TARGET)),_rom)
CPPFLAGS += -D_FINALROM
endif
# C preprocessor flags
CPPFLAGS := -P -Wno-trigraphs $(DEF_INC_CFLAGS)

SRC_DIRS := $(shell find src -type d)
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
S_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s))
# tools
PRINT = printf

# Versions J and below used the C matrix math implementations
MGU_MATRIX_FILES := mtxcatf normalize scale translate
ifeq ($(MGU_ASM), 1)
C_FILES := $(filter-out $(addprefix src/gu/,$(MGU_MATRIX_FILES:=.c)),$(C_FILES))
else
S_FILES := $(filter-out $(addprefix src/mgu/,$(MGU_MATRIX_FILES:=.s)),$(S_FILES))
ifeq ($(COLOR),1)
NO_COL := \033[0m
RED := \033[0;31m
GREEN := \033[0;32m
BLUE := \033[0;34m
YELLOW := \033[0;33m
BLINK := \033[33;5m
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)

$(shell mkdir -p src $(foreach dir,$(SRC_DIRS),$(BUILD_DIR)/$(dir)))
# Common build print status function
define print
@$(PRINT) "$(GREEN)$(1) $(YELLOW)$(2)$(GREEN) -> $(BLUE)$(3)$(NO_COL)\n"
endef

.PHONY: all clean distclean setup
all: $(BUILD_AR)
#==============================================================================#
# Main Targets #
#==============================================================================#

$(BUILD_AR): $(O_FILES)
@printf " [AR] $@\n"
$(V)$(AR) rcs $@ $^
# Default target
default: $(LIB)

clean:
$(RM) -rf $(BUILD_DIR)
$(RM) -r $(BUILD_DIR_BASE)

distclean:
$(RM) -rf extracted/ $(BUILD_ROOT)
ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS))

GBIDEFINE := -DF3DEX_GBI
# Make sure build directory exists before compiling anything
$(shell mkdir -p $(ALL_DIRS))

$(BUILD_DIR)/src/voice/%.o: CFLAGS += -I$(WORKING_DIR)/src/voice
$(BUILD_DIR)/src/voice/%.o: DEFINES += LANG_JAPANESE=1
$(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)

#==============================================================================#
# Compilation Recipes #
#==============================================================================#

# Compile C code
$(BUILD_DIR)/src/voice/%.o: src/voice/%.c
$(call print,Compiling:,$<,$@)
$(V)tools/compile_sjis.py -D__CC=$(CC) -D__BUILD_DIR=$(BUILD_DIR) -c $(CFLAGS) -MMD -MP -o $@ $<

$(BUILD_DIR)/%.o: %.c
@printf " [CC] $<\n"
$(V)$(CC) $(CFLAGS) $(MIPS_VERSION) $(CPPFLAGS) $(OPTFLAGS) $< $(IINC) -o $@
$(V)tools/set_o32abi_bit.py $@
$(call print,Compiling:,$<,$@)
$(V)$(CC) -c $(CFLAGS) $(GBIDEFINE) -MMD -MP -o $@ $<
$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c
$(call print,Compiling:,$<,$@)
$(V)$(CC) -c $(CFLAGS) $(GBIDEFINE) -MMD -MP -o $@ $<

# Assemble assembly code
$(BUILD_DIR)/%.o: %.s
@printf " [AS] $<\n"
$(V)$(AS) $(ASFLAGS) $(MIPS_VERSION) $(CPPFLAGS) $(ASOPTFLAGS) $< $(IINC) -o $@
$(V)tools/set_o32abi_bit.py $@
$(call print,Assembling:,$<,$@)
$(V)$(CC) -c $(CFLAGS) $(foreach i,$(INCLUDE_DIRS),-Wa,-I$(i)) -x assembler-with-cpp -DMIPSEB -D_LANGUAGE_ASSEMBLY -D_ULTRA64 -MMD -MP -o $@ $<

# Creating final library file
$(LIB): $(O_FILES)
@$(PRINT) "$(GREEN)Creating $(TARGET): $(BLUE)$@ $(NO_COL)\n"
$(V)$(AR) rcs -o $@ $(O_FILES)

all: $(BUILD_DIR_BASE)/libultra.a $(BUILD_DIR_BASE)/libultra_d.a $(BUILD_DIR_BASE)/libultra_rom.a

$(BUILD_DIR_BASE)/libultra.a:
$(V)$(MAKE) TARGET=libultra
$(V)cp $(BUILD_DIR_BASE)/libultra/libultra.a $(BUILD_DIR_BASE)

$(BUILD_DIR_BASE)/libultra_d.a:
$(V)$(MAKE) TARGET=libultra_d
$(V)cp $(BUILD_DIR_BASE)/libultra_d/libultra_d.a $(BUILD_DIR_BASE)

$(BUILD_DIR_BASE)/libultra_rom.a:
$(V)$(MAKE) TARGET=libultra_rom
$(V)cp $(BUILD_DIR_BASE)/libultra_rom/libultra_rom.a $(BUILD_DIR_BASE)

.PHONY: clean default all install pkginstall
# with no prerequisites, .SECONDARY causes no intermediate target to be removed
.SECONDARY:

# Remove built-in rules, to improve performance
MAKEFLAGS += --no-builtin-rules

-include $(DEP_FILES)

# Disable built-in rules
.SUFFIXES:
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
12 changes: 12 additions & 0 deletions include/PR/gtoff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* GENERATED FILE, DO NOT EDIT! */

/* gtState_t structure offsets for assembly language: */
#define GT_STATE_SIZE 88
#define GT_STATE_OFF_RENDSTATE 0x00
#define GT_STATE_OFF_TEXSTATE 0x04
#define GT_STATE_OFF_VTXCOUNT 0x08
#define GT_STATE_OFF_VTXV0 0x09
#define GT_STATE_OFF_TRICOUNT 0x0a
#define GT_STATE_OFF_RDPCMDS 0x0c
#define GT_STATE_OFF_OTHERMODE 0x10
#define GT_STATE_OFF_TRANSFORM 0x18
6 changes: 0 additions & 6 deletions include/PR/os_libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,9 @@ extern "C" {

/* byte string operations */

#ifndef MODERN_CC
extern void bcopy(const void*, void*, int);
extern int bcmp(const void*, const void*, int);
extern void bzero(void*, int);
#else
extern void bcopy(const void*, void*, size_t);
extern int bcmp(const void*, const void*, size_t);
extern void bzero(void*, size_t);
#endif

/* Printf */

Expand Down
1 change: 0 additions & 1 deletion include/PR/rmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extern "C" {
#define RMON_DBG_BUF_SIZE 2048
#define RMON_STACKSIZE 0x1000

extern void rmonMain(void*);
extern void rmonPrintf(const char*, ...);

#ifdef _LANGUAGE_C_PLUS_PLUS
Expand Down
17 changes: 17 additions & 0 deletions include/PR/sptaskoff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#define OS_TASK_SIZE 64
#define OS_TASK_OFF_TYPE 0
#define OS_TASK_OFF_FLAGS 4
#define OS_TASK_OFF_UBOOT 8
#define OS_TASK_OFF_UBOOT_SZ 12
#define OS_TASK_OFF_UCODE 16
#define OS_TASK_OFF_UCODE_SZ 20
#define OS_TASK_OFF_UDATA 24
#define OS_TASK_OFF_UDATA_SZ 28
#define OS_TASK_OFF_STACK 32
#define OS_TASK_OFF_STACK_SZ 36
#define OS_TASK_OFF_OUTBUFF 40
#define OS_TASK_OFF_OUTBUFF_SZ 44
#define OS_TASK_OFF_DATA 48
#define OS_TASK_OFF_DATA_SZ 52
#define OS_TASK_OFF_YIELD 56
#define OS_TASK_OFF_YIELD_SZ 60
Loading
Loading