Update makefile and README for macOS and depdencies (#436)

* Remove capstone from the requirements, and update the workflows to use the latest recomp binaries.

* Update makefile and README for macOS

- support make 4.4 syntax for C and asm file lists
- prefer clang for C preprocessing since gcc on macOS is a clang alias
- update macOS setup and build instructions

---------

Co-authored-by: Ryan Myers <ryan.p.myers@gmail.com>
This commit is contained in:
queueRAM
2023-11-20 11:55:41 -05:00
committed by GitHub
co-authored by Ryan Myers
parent 7225b49da0
commit 76af1da31f
4 changed files with 62 additions and 56 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ jobs:
- name: Install packages
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config git python3 libssl-dev wget libcapstone-dev binutils-mips-linux-gnu
sudo apt-get install -y build-essential pkg-config git python3 libssl-dev wget binutils-mips-linux-gnu
- name: Get ROM
run: wget -q -O baseroms/dkr.z64 ${{secrets.ROMURL}}
+2 -2
View File
@@ -20,7 +20,7 @@ jobs:
- name: Install packages
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config git python3 libssl-dev wget libcapstone-dev binutils-mips-linux-gnu
sudo apt-get install -y build-essential pkg-config git python3 libssl-dev wget binutils-mips-linux-gnu
- name: Get ROM
run: wget -q -O baseroms/dkr.z64 ${{secrets.ROMURL}}
@@ -30,7 +30,7 @@ jobs:
- name: Download Recomp
run: |
wget -q -O ido-static-recomp.tar.gz https://github.com/decompals/ido-static-recomp/releases/download/v0.1/ido-5.3-recomp-ubuntu-latest.tar.gz
wget -q -O ido-static-recomp.tar.gz https://github.com/decompals/ido-static-recomp/releases/download/v1.0/ido-5.3-recomp-linux.tar.gz
mkdir -p tools/ido-static-recomp/build5.3/out
tar -xvzf ido-static-recomp.tar.gz -C tools/ido-static-recomp/build5.3/out
+54 -45
View File
@@ -62,7 +62,7 @@ endif
########## Make tools ##########
DUMMY != make -s -C tools >&2 || echo FAIL
DUMMY != $(MAKE) -s -C tools >&2 || echo FAIL
ifeq ($(DUMMY),FAIL)
$(error Failed to build tools)
endif
@@ -132,16 +132,27 @@ endif
AS = $(CROSS)as
CC := tools/ido-static-recomp/build/5.3/out/cc
CPP := cpp -P -Wno-trigraphs -I include
LD = $(CROSS)ld
OBJDUMP = $(CROSS)objdump
# Pad to 12MB if matching, otherwise build to a necessary minimum of 1.04KB
# Pad to 12MB if matching, otherwise build to a necessary minimum of 1.004MB
ifeq ($(NON_MATCHING),0)
OBJCOPY = $(CROSS)objcopy --pad-to=0xC00000 --gap-fill=0xFF
else
OBJCOPY = $(CROSS)objcopy --pad-to=0x101000 --gap-fill=0xFF
endif
# Returns the path to the command $(1) if exists. Otherwise returns an empty string.
find-command = $(shell which $(1) 2>/dev/null)
# Prefer clang as C preprocessor if installed on the system
ifneq (,$(call find-command,clang))
CPP := clang
CPPFLAGS := -E -P -x c -Wno-trigraphs -I include
else
CPP := cpp
CPPFLAGS := -P -Wno-trigraphs -I include
endif
MIPSISET := -mips1
OPT_FLAGS := -O2 -Xfullwarn #include -Xfullwarn here since it's not supported with -O3
@@ -168,30 +179,28 @@ EMU_FLAGS = --noosd
LOADER = loader64
LOADER_FLAGS = -vwf
FixPath = $(subst /,,$1)
N64CRC = $(TOOLS_DIR)/n64crc
FIXCHECKSUMS = python3 $(TOOLS_DIR)/python/calc_func_checksums.py $(VERSION)
COMPRESS = $(TOOLS_DIR)/dkr_assets_tool -fc
BUILDER = $(TOOLS_DIR)/dkr_assets_tool -b $(VERSION) ./assets
LIB_DIRS := lib/
ASM_DIRS := asm/ asm/boot/ asm/assets/ lib/asm/ lib/asm/non_decompilable
SRC_DIRS := $(sort $(dir $(wildcard src/* src/**/*))) $(sort $(dir $(wildcard lib/src/* lib/src/**/* lib/src/**/**/*)))
LIB_DIRS := lib
ASM_DIRS := asm asm/boot asm/assets lib/asm lib/asm/non_decompilable
SRC_DIRS := $(sort $(patsubst %/,%,$(dir $(wildcard src/* src/**/* lib/src/* lib/src/**/* lib/src/**/**/*))))
GLOBAL_ASM_C_FILES != grep -rl 'GLOBAL_ASM(' $(SRC_DIRS)
GLOBAL_ASM_O_FILES = $(foreach file,$(GLOBAL_ASM_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)*.s))
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)*.c))
S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
# Object files
O_FILES := $(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
$(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o))
O_FILES := $(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
$(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o))
# Automatic dependency files
DEP_FILES := $(O_FILES:.o=.d) $(BUILD_DIR)/$(LD_SCRIPT).d
# Check code syntax with host compiler
CC_CHECK := gcc
ifeq ($(shell getconf LONG_BIT), 64)
@@ -302,47 +311,47 @@ LD_SCRIPT = $(TARGET).ld
all: $(BUILD_DIR)/$(TARGET).z64
reset:
ifneq ($(wildcard ./build/.*),)
reset:
ifneq ($(wildcard ./build/.*),)
rm -r build
endif
ifneq ($(wildcard ./assets/.*),)
rm -r assets
endif
ifneq ($(wildcard ./ucode/.*),)
rm -r ucode
endif
@echo "Done."
clean:
ifneq ($(wildcard ./build/.*),)
rm -r build
rm -r dkr.ld
else
@echo "/build/ directory has already been deleted."
endif
ifneq ($(wildcard ./assets/.*),)
rm -r assets
endif
ifneq ($(wildcard ./ucode/.*),)
rm -r ucode
endif
@echo "Done."
clean:
ifneq ($(wildcard ./build/.*),)
rm -r build
else
@echo "/build/ directory has already been deleted."
endif
rm -f dkr.ld
distclean:
rm -rf build
rm -rf assets
rm -rf ucode
rm -rf dkr.ld
rm -f dkr.ld
$(MAKE) -C tools distclean
clean_lib:
ifneq ($(wildcard $(BUILD_DIR)/lib/.*),)
rm -r $(BUILD_DIR)/lib/src/*/*.o
else
@echo "build lib directory has already been deleted."
endif
else
@echo "build lib directory has already been deleted."
endif
clean_src: clean_lib
ifneq ($(wildcard $(BUILD_DIR)/src/.*),)
rm -r $(BUILD_DIR)/src/*.o
rm -rf dkr.ld
else
@echo "/build/lib directory has already been deleted."
endif
rm -f dkr.ld
else
@echo "/build/lib directory has already been deleted."
endif
# Helps fix an issue with parallel jobs.
$(ALL_ASSETS_BUILT): | $(BUILD_DIR)
@@ -370,13 +379,13 @@ $(foreach FILE,$(JSON_FILES),$(eval $(call DEFINE_ASSET_TARGET,$(FILE),$(call JS
$(UCODE_OUT_DIR)/%.bin: $(UCODE_IN_DIR)/%.bin
$(call print,Copying:,$<,$@)
$(V)$(ASSETS_COPY) $^ $@
###############################
$(BUILD_DIR)/%.o: %.s | $(ALL_ASSETS_BUILT)
$(call print,Assembling:,$<,$@)
$(V)$(AS) $(ASFLAGS) -MD $(BUILD_DIR)/$*.d -o $@ $<
$(BUILD_DIR)/%.o: %.c | $(ALL_ASSETS_BUILT)
$(call print,Compiling:,$<,$@)
@$(CC_CHECK) $(CC_CHECK_CFLAGS) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
@@ -391,7 +400,7 @@ $(BUILD_DIR)/lib/src/libc/ll.o: lib/src/libc/ll.c | $(ALL_ASSETS_BUILT)
$(call print,Compiling mips3:,$<,$@)
$(V)$(CC) $(CFLAGS) -o $@ $<
$(V)python3 tools/python/patchmips3.py $@ || rm $@
$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c | $(ALL_ASSETS_BUILT)
$(call print,Compiling:,$<,$@)
@$(CC_CHECK) $(CC_CHECK_CFLAGS) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
@@ -399,7 +408,7 @@ $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c | $(ALL_ASSETS_BUILT)
$(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT) | $(ALL_ASSETS_BUILT)
$(call print,Preprocessing linker script:,$<,$@)
$(V)$(CPP) $(VERSION_CFLAGS) -DBUILD_DIR=$(BUILD_DIR) -MMD -MP -MT $@ -MF $@.d -o $@ $<
$(V)$(CPP) $(CPPFLAGS) $(VERSION_CFLAGS) -DBUILD_DIR=$(BUILD_DIR) -MMD -MP -MT $@ -MF $@.d -o $@ $<
$(BUILD_DIR)/$(TARGET).elf: $(O_FILES) $(BUILD_DIR)/$(LD_SCRIPT) | $(ALL_ASSETS_BUILT)
@$(PRINT) "$(GREEN)Linking ELF file: $(BLUE)$@ $(NO_COL)\n"
@@ -428,7 +437,7 @@ $(BUILD_DIR)/$(TARGET).hex: $(BUILD_DIR)/$(TARGET).z64
$(BUILD_DIR)/$(TARGET).objdump: $(BUILD_DIR)/$(TARGET).elf
$(OBJDUMP) -D $< > $@
$(GLOBAL_ASM_O_FILES): CC := python3 tools/asm_processor/build.py $(CC) -- $(AS) $(ASFLAGS) --
test: $(BUILD_DIR)/$(TARGET).z64
+5 -8
View File
@@ -16,13 +16,12 @@ As of November 18, 2023, this is our current score:
## Dependencies
* `libcapstone-dev`
* `gcc`, Version 8.0 or higher
* `make`, Version 4.2 or higher
* `python3`
* `wget`
`sudo apt install build-essential pkg-config git python3 wget libcapstone-dev`
`sudo apt install build-essential pkg-config git python3 wget`
### binutils
@@ -38,12 +37,10 @@ You are not required to install a binutils package, but it does speed up the ini
3. Run `make` in the main directory.
**a.** Use the `-jN` argument to use `N` number of threads to speed up building. For example, if you have a system with 4 cores / 4 threads, you should do `make -j4`.
### Building on MacOS
1. `brew install gcc capstone coreutils`
2. Put GNU-coreutils `bin` on path using by adding `PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"` to your shell rcfile (or update any GNU-util usage in `Makefile` and `tools/Makefile` to use the `g`-prefixed versions).
3. Download latest `macos` build of `ido-static-recomp` from [here](https://github.com/decompals/ido-static-recomp/releases/), and add `cp` the binaries to `tools/ido-static-recomp/build5.3/out`.
4. Take a look at [this gist](https://gist.github.com/tonyspumoni/fc1b4c9217c5f2821a9fc4cbf69b51ef) to see what other updates are needed to get the build to pass, and apply them if they are relevant to your environment. You may need to add specific `-I` and `-L` flags to get things like `openssl` and `gcc-12` includes/libs included.
5. `make` from repository root should work now.
### Building on macOS
1. Use homebrew to install dependencies: `brew install make`
2. Place the ROM file within the `baseroms` directory. See [Setup](#setup--building) above for more info.
3. Run `gmake` from the main directory. Note that macOS built-in `make` will not work since it does not meet the version requirements.
## Modding
If you are modifying the code in the repo, then you should add `NON_MATCHING=1` to the make command.