Skip to content

Commit

Permalink
Makefile Improvements (#81)
Browse files Browse the repository at this point in the history
* Include WORKING_DIR in CC so can call compiler with just CC not WORKING_DIR/CC

* Move makefiles (except the main one) to a makefiles folder to keep root cleaner

* Set compiler based on target, and use that to set proper makefile

* .mk file extension

* Use AS for assembly files instead of CC
  • Loading branch information
hensldm authored Jul 7, 2024
1 parent c618e55 commit 0c679b2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
28 changes: 18 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ TARGET ?= libgultra_rom
VERSION ?= L
CROSS ?= mips-linux-gnu-

ifeq ($(findstring libgultra,$(TARGET)),libgultra)
COMPILER := gcc
else ifeq ($(findstring libultra,$(TARGET)),libultra)
COMPILER := ido
else
$(error Invalid Target)
endif

BASE_DIR := extracted/$(VERSION)/$(TARGET)
BASE_AR := base/$(VERSION)/$(TARGET).a
BUILD_ROOT := build
Expand Down Expand Up @@ -41,15 +49,15 @@ else
DEBUGFLAG := -DNDEBUG
endif

ifeq ($(findstring libgultra,$(TARGET)),libgultra)
-include Makefile.gcc
else ifeq ($(findstring libultra,$(TARGET)),libultra)
-include Makefile.ido
ifeq ($(COMPILER),gcc)
-include makefiles/gcc.mk
else ifeq ($(COMPILER),ido)
-include makefiles/ido.mk
else
$(error Invalid Target)
$(error Invalid Compiler)
endif

export COMPILER_PATH := $(WORKING_DIR)/$(COMPILER_DIR)
export COMPILER_PATH := $(COMPILER_DIR)

ifeq ($(findstring _rom,$(TARGET)),_rom)
CPPFLAGS += -D_FINALROM
Expand Down Expand Up @@ -168,10 +176,10 @@ $(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 := tools/compile_sjis.py -D__CC=$(WORKING_DIR)/$(CC) -D__BUILD_DIR=$(BUILD_DIR)
$(BUILD_DIR)/src/voice/%.marker: CC := $(WORKING_DIR)/tools/compile_sjis.py -D__CC=$(CC) -D__BUILD_DIR=$(BUILD_DIR)

$(C_MARKER_FILES): $(BUILD_DIR)/%.marker: %.c
cd $(<D) && $(WORKING_DIR)/$(CC) $(CFLAGS) $(MIPS_VERSION) $(CPPFLAGS) $(OPTFLAGS) $(<F) $(IINC) -o $(WORKING_DIR)/$(@:.marker=.o)
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)), \
Expand All @@ -190,7 +198,7 @@ endif
@touch $@

$(S_MARKER_FILES): $(BUILD_DIR)/%.marker: %.s
cd $(<D) && $(WORKING_DIR)/$(CC) $(ASFLAGS) $(MIPS_VERSION) $(CPPFLAGS) $(ASOPTFLAGS) $(<F) $(IINC) -o $(WORKING_DIR)/$(@:.marker=.o)
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)), \
Expand All @@ -212,7 +220,7 @@ endif
$(MDEBUG_FILES): $(BUILD_DIR)/src/%.marker: src/%.s
cp $(<:.marker=.s) $(dir $@)
mkdir -p $(@:.marker=)
export USR_INCLUDE=$(WORKING_DIR)/include && cd $(@:.marker=) && $(WORKING_DIR)/$(CC) $(ASFLAGS) $(CPPFLAGS) ../$(<F) -I/usr/include -o $(notdir $(<:.s=.o))
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
Expand Down
17 changes: 8 additions & 9 deletions Makefile.gcc → makefiles/gcc.mk
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
COMPILER := gcc
COMPILER_DIR := tools/gcc/
AS := $(COMPILER_DIR)as
CC := $(COMPILER_DIR)gcc
AR_OLD := $(COMPILER_DIR)ar
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 -x assembler-with-cpp
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/gcc -I $(WORKING_DIR)/include/PR
MIPS_VERSION := -mips3
Expand Down Expand Up @@ -45,7 +44,7 @@ endif
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/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
Expand All @@ -62,6 +61,6 @@ $(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 := tools/ido/
$(MDEBUG_FILES): CC := $(MDEBUG_COMPILER_DIR)cc
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
9 changes: 4 additions & 5 deletions Makefile.ido → makefiles/ido.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
COMPILER := ido
COMPILER_DIR := tools/ido/
AS := $(COMPILER_DIR)cc
CC := $(COMPILER_DIR)cc
AR_OLD := tools/ar.py
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 =

Expand Down

0 comments on commit 0c679b2

Please sign in to comment.