Skip to content

Commit

Permalink
Libultra 2 (#44)
Browse files Browse the repository at this point in the history
* Use proper compiler

* Remove pif syms

* unused_syms.ld

* Remove ultralib

* git subrepo clone [email protected]:decompals/ultralib.git lib/ultralib

subrepo:
  subdir:   "lib/ultralib"
  merged:   "299d7fa"
upstream:
  origin:   "[email protected]:decompals/ultralib.git"
  branch:   "main"
  commit:   "299d7fa"
git-subrepo:
  version:  "0.4.6"
  origin:   "[email protected]:ingydotnet/git-subrepo.git"
  commit:   "110b9eb"

* ultralib fixes
  • Loading branch information
hensldm authored Feb 25, 2024
1 parent f70a7bc commit 818f3c6
Show file tree
Hide file tree
Showing 47 changed files with 10,720 additions and 169 deletions.
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ venv:
setup:
$(MAKE) -C tools

lib:
$(MAKE) -C lib/ultralib VERSION=$(ULTRALIB_VERSION) TARGET=$(ULTRALIB_TARGET) COMPARE=0 CROSS=$(CROSS) CC=../../$(CC)
lib: $(ULTRALIB_LIB)

extract:
$(RM) -r asm/$(VERSION) assets/$(VERSION)
Expand Down Expand Up @@ -293,9 +292,9 @@ $(ROM): $(ELF)
# TODO: update rom header checksum

# TODO: avoid using auto/undefined
$(ELF): $(O_FILES) $(LIBULTRA_LIB) $(LDSCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/pif_syms.ld
$(ELF): $(O_FILES) $(LIBULTRA_LIB) $(LDSCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/unused_syms.ld
$(LD) $(LDFLAGS) -T $(LDSCRIPT) \
-T $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/pif_syms.ld \
-T $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/unused_syms.ld \
-Map $(MAP) $(LIBULTRA_LIB) -o $@

$(LDSCRIPT): linker_scripts/$(VERSION)/yoshisstory.ld
Expand All @@ -306,7 +305,7 @@ $(LIBULTRA_LIB): $(ULTRALIB_LIB)
$(LIBDUMP_CMD)

$(ULTRALIB_LIB):
$(MAKE) lib
$(MAKE) -C lib/ultralib VERSION=$(ULTRALIB_VERSION) TARGET=$(ULTRALIB_TARGET) FIXUPS=1 CROSS=$(CROSS) CC=../../$(CC_OLD)

$(BUILD_DIR)/%.ld: %.ld
$(CPP) $(CPPFLAGS) $(BUILD_DEFINES) $(IINC) $< > $@
Expand Down
1 change: 1 addition & 0 deletions lib/ultralib/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ __pycache__/
CMakeLists.txt
cmake-build-debug
venv/
.venv

# Project-specific ignores
base_*/
Expand Down
4 changes: 2 additions & 2 deletions lib/ultralib/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = [email protected]:decompals/ultralib.git
branch = main
commit = 6c1f3067a1ae4466338bf2aba0e1110d10f5291b
parent = 12e706521a72a8d197cd38937a2282d675997e50
commit = 299d7faf8798cbe75e3247ccdf4e65c09f5270dd
parent = a3476fcc3a0fc47aa0c31f3ef04d08181daf3050
method = merge
cmdver = 0.4.6
32 changes: 21 additions & 11 deletions lib/ultralib/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
COMPARE ?= 1
FIXUPS ?= 0

ifneq ($(FIXUPS),0)
COMPARE := 0
endif

# One of:
# libgultra_rom, libgultra_d, libgultra
Expand Down Expand Up @@ -49,9 +54,8 @@ CPPFLAGS += -D_FINALROM
endif

SRC_DIRS := $(shell find src -type d)
ASM_DIRS := $(shell find asm -type d)
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
S_FILES := $(foreach dir,$(SRC_DIRS) $(ASM_DIRS),$(wildcard $(dir)/*.s))
S_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s))

# Versions J and below used the C matrix math implementations
MGU_MATRIX_FILES := mtxcatf normalize scale translate
Expand Down Expand Up @@ -104,15 +108,15 @@ AR_OBJECTS := $(shell ar t $(BASE_AR))
endif


# Try to find a file corresponding to an archive file in any of src/ asm/ or the base directory, prioritizing src then asm then the original file
AR_ORDER = $(foreach f,$(AR_OBJECTS),$(shell find $(BUILD_DIR)/src $(BUILD_DIR)/asm $(BASE_DIR) -iname $f -type f -print -quit))
# 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 asm $(BASE_DIR) src $(foreach dir,$(ASM_DIRS) $(SRC_DIRS),$(BUILD_DIR)/$(dir)))
$(shell mkdir -p $(BASE_DIR) src $(foreach dir,$(SRC_DIRS),$(BUILD_DIR)/$(dir)))

.PHONY: all clean distclean setup
all: $(BUILD_AR)
Expand Down Expand Up @@ -174,11 +178,13 @@ ifneq ($(COMPARE),0)
touch -r $(BASE_DIR)/$(@F:.marker=.o) $(@:.marker=.o), \
echo "Object file $(@F:.marker=.o) is not in the current archive" \
)
# create or update the marker file
else
endif
ifneq ($(FIXUPS),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 $@

$(S_MARKER_FILES): $(BUILD_DIR)/%.marker: %.s
Expand All @@ -191,11 +197,13 @@ ifneq ($(COMPARE),0)
touch -r $(BASE_DIR)/$(@F:.marker=.o) $(@:.marker=.o), \
echo "Object file $(@F:.marker=.o) is not in the current archive" \
)
# create or update the marker file
else
endif
ifneq ($(FIXUPS),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
Expand All @@ -212,11 +220,13 @@ ifneq ($(COMPARE),0)
touch -r $(BASE_DIR)/$(@F:.marker=.o) $(@:.marker=.o), \
echo "Object file $(@F:.marker=.o) is not in the current archive" \
)
# create or update the marker file
else
endif
ifneq ($(FIXUPS),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 $@

# Disable built-in rules
Expand Down
7 changes: 7 additions & 0 deletions lib/ultralib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,10 @@ If building without an target archive, than you can use `COMPARE=0` like the the

note that running setup without `COMPARE=0` and no archive will result in an error,
and only needs to be run once instead of per target flag combination

If building for use with modern linkers, than you can use `FIXUPS=1` like the the following:

- `make VERSION=L TARGET=libgultra_rom FIXUPS=1 setup`
- `make VERSION=L TARGET=libgultra_rom FIXUPS=1`

note that running with `FIXUPS=1` will automatically set `COMPARE=0`.
Loading

0 comments on commit 818f3c6

Please sign in to comment.