sm64ex macOS build changes and more

Fix macOS builds being broken (sm64pc/sm64ex#489)

Makefile: more robust macOS build support + improvements to build speed (sm64pc/sm64ex#445)
This commit is contained in:
AloXado320 2021-12-01 23:01:39 -05:00
parent 59cb6a6f7e
commit 27d5672f9c
5 changed files with 50 additions and 13 deletions

3
.gitignore vendored
View file

@ -85,3 +85,6 @@ sm64config.txt
platform/android/SDL/include
!platform/android/android/**/*.so
platform/android/android/lib/*/libc++_shared.so
# macOS autocreated directory settings file
.DS_Store

View file

@ -205,6 +205,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
@ -354,7 +380,7 @@ 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
@ -967,7 +993,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
OBJCOPY := i686-w64-mingw32-objcopy
OBJDUMP := i686-w64-mingw32-objdump
else ifeq ($(TARGET_ANDROID),1) # Termux has clang
@ -1018,7 +1043,7 @@ else ifeq ($(findstring SDL,$(WINDOW_API)),SDL)
else ifeq ($(TARGET_SWITCH),1)
BACKEND_LDFLAGS += -lGLESv2
else ifeq ($(OSX_BUILD),1)
BACKEND_LDFLAGS += -framework OpenGL `pkg-config --libs glew`
BACKEND_LDFLAGS += -framework OpenGL $(shell pkg-config --libs glew)
else
BACKEND_LDFLAGS += -lGL
endif
@ -1053,12 +1078,16 @@ endif
ifneq ($(SDL1_USED)$(SDL2_USED),00)
ifeq ($(TARGET_ANDROID),1)
BACKEND_LDFLAGS += -lhidapi -lSDL2
else ifeq ($(OSX_BUILD),1)
# on OSX at least the homebrew version of sdl-config gives include path as `.../include/SDL2` instead of `.../include`
OSX_PREFIX := $(shell $(SDLCONFIG) --prefix)
BACKEND_CFLAGS += -I$(OSX_PREFIX)/include $(shell $(SDLCONFIG) --cflags)
else
BACKEND_CFLAGS += `$(SDLCONFIG) --cflags`
BACKEND_CFLAGS += $(shell $(SDLCONFIG) --cflags)
ifeq ($(WINDOWS_BUILD),1)
BACKEND_LDFLAGS += `$(SDLCONFIG) --static-libs` -lsetupapi -luser32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion
BACKEND_LDFLAGS += $(shell $(SDLCONFIG) --static-libs) -lsetupapi -luser32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion
else
BACKEND_LDFLAGS += `$(SDLCONFIG) --libs`
BACKEND_LDFLAGS += $(shell $(SDLCONFIG) --libs)
endif
endif
endif
@ -1073,8 +1102,8 @@ else ifeq ($(TARGET_WEB),1)
# Linux / Other builds below
else
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(DEF_INC_CFLAGS) -Wall -Wextra -Wno-format-security
CFLAGS := $(OPT_FLAGS) $(BACKEND_CFLAGS) $(DEF_INC_CFLAGS) -fno-strict-aliasing -fwrapv
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(PLATFORM_CFLAGS) $(DEF_INC_CFLAGS) -Wall -Wextra -Wno-format-security
CFLAGS := $(OPT_FLAGS) $(PLATFORM_CFLAGS) $(BACKEND_CFLAGS) $(DEF_INC_CFLAGS) -fno-strict-aliasing -fwrapv
endif
@ -1155,7 +1184,7 @@ else ifeq ($(TARGET_ANDROID),1)
LDFLAGS := -L ./$(PLATFORM_DIR)/android/lib/$(ARCH_APK)/ -lm $(BACKEND_LDFLAGS) -shared
else ifeq ($(OSX_BUILD),1)
LDFLAGS := -lm $(BACKEND_LDFLAGS) -no-pie -lpthread
LDFLAGS := -lm $(PLATFORM_LDFLAGS) $(BACKEND_LDFLAGS) -lpthread
else ifeq ($(HOST_OS),Haiku)
LDFLAGS := $(BACKEND_LDFLAGS) -no-pie

View file

@ -3,8 +3,8 @@ include ../util.mk
HOST_ENV := $(shell uname 2>/dev/null || echo Unknown)
HOST_ENV := $(patsubst MINGW%,MinGW,$(HOST_ENV))
CC := gcc
CXX := g++
CC ?= gcc
CXX ?= g++
CFLAGS := -I . -Wall -Wextra -Wno-unused-parameter -pedantic -O2 -s
LDFLAGS := -lm
ALL_PROGRAMS := armips n64graphics n64graphics_ci mio0 n64cksum textconv patch_elf_32bit aifc_decode aiff_extract_codebook vadpcm_enc tabledesign extract_data_for_mio skyconv
@ -78,6 +78,6 @@ ido5.3_recomp:
$(foreach p,$(BUILD_PROGRAMS),$(eval $(call COMPILE,$(p))))
$(LIBAUDIOFILE):
@$(MAKE) -C audiofile
@CC=$(CC) CXX=$(CXX) @$(MAKE) -C audiofile
.PHONY: all all-except-recomp clean default ido5.3_recomp

View file

@ -25,6 +25,11 @@ typedef unsigned int u32;
#define NORETURN __attribute__((noreturn))
#define UNUSED __attribute__((unused))
#ifdef __APPLE__
// even with -std=gnu99 vsnprintf seems to not be defined in stdio.h, why?
extern int vsnprintf(char * __restrict, size_t, const char * __restrict, va_list);
#endif
typedef struct
{
u32 start;

View file

@ -1,4 +1,4 @@
CXX := g++
CXX ?= g++
libaudiofile.a: audiofile.o
$(AR) rcs $@ $^