From ac34b941ff564a456e8201c58e7cf902de1268d4 Mon Sep 17 00:00:00 2001 From: GammaTendonNine Date: Mon, 23 Nov 2020 02:50:35 -0600 Subject: [PATCH] Makefile: macOS Package Manager & Compiler detection --- Makefile | 44 +++++++++++++++++++++++++++++----------- tools/Makefile | 8 ++++---- tools/audiofile/Makefile | 2 +- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 8599190c..ee053d2c 100644 --- a/Makefile +++ b/Makefile @@ -97,6 +97,32 @@ ifeq ($(WINDOWS_BUILD),1) endif endif +# macOS overrides +ifeq ($(HOST_OS),Darwin) + OSX_BUILD := 1 + # Using MacPorts? + ifeq ($(shell test -d /opt/local/lib && echo y),y) + OSX_GCC_VER = $(shell find /opt/local/bin/gcc* | grep -oE '[[:digit:]]+' | sort -n | uniq | tail -1) + CC := gcc-mp-$(OSX_GCC_VER) + CXX := g++-mp-$(OSX_GCC_VER) + CPP := cpp-mp-$(OSX_GCC_VER) -P + PLATFORM_CFLAGS := -I /opt/local/include + PLATFORM_LDFLAGS := -L /opt/local/lib + else + # Using Homebrew? + ifeq ($(shell which brew >/dev/null 2>&1 && echo y),y) + OSX_GCC_VER = $(shell find `brew --prefix`/bin/gcc* | grep -oE '[[:digit:]]+' | sort -n | uniq | tail -1) + CC := gcc-$(OSX_GCC_VER) + CXX := g++-$(OSX_GCC_VER) + CPP := cpp-$(OSX_GCC_VER) -P + PLATFORM_CFLAGS := -I /usr/local/include + PLATFORM_LDFLAGS := -L /usr/local/lib + else + $(error No suitable macOS toolchain found, have you installed Homebrew?) + endif + endif +endif + ifneq ($(TARGET_BITS),0) BITS := -m$(TARGET_BITS) endif @@ -164,6 +190,7 @@ endif # in the makefile that we want should cover assets.) ifneq ($(MAKECMDGOALS),clean) +ifneq ($(MAKECMDGOALS),cleantools) ifneq ($(MAKECMDGOALS),distclean) # Make sure assets exist @@ -176,11 +203,12 @@ endif endif # Make tools if out of date -DUMMY != make -C tools >&2 || echo FAIL +DUMMY != CC=$(CC) CXX=$(CXX) $(MAKE) -C tools >&2 || echo FAIL ifeq ($(DUMMY),FAIL) $(error Failed to build tools) endif +endif endif endif @@ -352,7 +380,7 @@ DEP_FILES := $(O_FILES:.o=.d) $(ULTRA_O_FILES:.o=.d) $(GODDARD_O_FILES:.o=.d) $( SEG_FILES := $(SEGMENT_ELF_FILES) $(ACTOR_ELF_FILES) $(LEVEL_ELF_FILES) ##################### Compiler Options ####################### -INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I . +INCLUDE_CFLAGS := $(PLATFORM_CFLAGS) -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I . ENDIAN_BITWIDTH := $(BUILD_DIR)/endian-and-bitwidth # Huge deleted N64 section was here @@ -390,7 +418,6 @@ ifeq ($(WINDOWS_BUILD),1) # fixes compilation in MXE on Linux and WSL OBJCOPY := objcopy OBJDUMP := $(CROSS)objdump else ifeq ($(OSX_BUILD),1) - CPP := cpp-9 -P OBJDUMP := i686-w64-mingw32-objdump OBJCOPY := i686-w64-mingw32-objcopy else # Linux & other builds @@ -541,7 +568,7 @@ else ifeq ($(TARGET_RPI),1) LDFLAGS := $(OPT_FLAGS) -lm $(BACKEND_LDFLAGS) -no-pie else ifeq ($(OSX_BUILD),1) - LDFLAGS := -lm $(BACKEND_LDFLAGS) -no-pie -lpthread + LDFLAGS := -lm $(PLATFORM_LDFLAGS) $(BACKEND_LDFLAGS) -lpthread else LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -lm $(BACKEND_LDFLAGS) -no-pie -lpthread @@ -571,13 +598,6 @@ ZEROTERM = $(PYTHON) $(TOOLS_DIR)/zeroterm.py all: $(EXE) -# thank you apple very cool -ifeq ($(HOST_OS),Darwin) - CP := gcp -else - CP := cp -endif - BASEPACK_PATH := $(BUILD_DIR)/$(BASEDIR)/ BASEPACK_LST := $(BUILD_DIR)/basepack.lst @@ -590,7 +610,7 @@ res: $(BASEPACK_PATH) # prepares the basepack.lst $(BASEPACK_LST): $(EXE) @mkdir -p $(BUILD_DIR)/$(BASEDIR) - @echo -n > $(BASEPACK_LST) + @touch $(BASEPACK_LST) @echo "$(BUILD_DIR)/sound/bank_sets sound/bank_sets" >> $(BASEPACK_LST) @echo "$(BUILD_DIR)/sound/sequences.bin sound/sequences.bin" >> $(BASEPACK_LST) @echo "$(BUILD_DIR)/sound/sound_data.ctl sound/sound_data.ctl" >> $(BASEPACK_LST) diff --git a/tools/Makefile b/tools/Makefile index b6b7babf..efc9cba8 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,5 +1,5 @@ -CC := gcc -CXX := g++ +CC ?= gcc +CXX ?= g++ CFLAGS := -I../include -I. -Wall -Wextra -Wno-unused-parameter -pedantic -std=c99 -O2 -s LDFLAGS := -lm PROGRAMS := n64graphics aifc_decode aiff_extract_codebook mio0 vadpcm_enc tabledesign skyconv @@ -31,7 +31,7 @@ vadpcm_enc_CFLAGS := -Wno-unused-result -Wno-uninitialized -Wno-sign-compare -Wn LIBAUDIOFILE := audiofile/libaudiofile.a $(LIBAUDIOFILE): - @$(MAKE) -C audiofile + @CC=$(CC) CXX=$(CXX) $(MAKE) -C audiofile all: $(LIBAUDIOFILE) $(PROGRAMS) $(CXX_PROGRAMS) @@ -46,4 +46,4 @@ endef $(foreach p,$(PROGRAMS),$(eval $(call COMPILE,$(p)))) -.PHONY: all clean default \ No newline at end of file +.PHONY: all clean default diff --git a/tools/audiofile/Makefile b/tools/audiofile/Makefile index 5f3f3e1d..f1c36d79 100644 --- a/tools/audiofile/Makefile +++ b/tools/audiofile/Makefile @@ -1,4 +1,4 @@ -CXX := g++ +CXX ?= g++ libaudiofile.a: audiofile.o ar rcs libaudiofile.a audiofile.o