From 68ac81316dc4e07819ea2cfce33077dd430c79a3 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sat, 6 Nov 2021 23:37:36 -0400 Subject: [PATCH] Fix error when cross-compiling for macOS arm64 using Makefile Fix "Architecture arm64 is not supported when cross compiling" and also be more be more flexible for manually specifying CC or the osxcross darwin version (which corresponds with a macOS SDK version to build against). --- Makefile | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index ec1fe746..6a88946f 100644 --- a/Makefile +++ b/Makefile @@ -467,6 +467,11 @@ ifeq ($(PLATFORM),darwin) BASE_CFLAGS += -mmacosx-version-min=$(MACOSX_VERSION_MIN) \ -DMAC_OS_X_VERSION_MIN_REQUIRED=$(MAC_OS_X_VERSION_MIN_REQUIRED) + MACOSX_ARCH=$(ARCH) + ifeq ($(ARCH),x86) + MACOSX_ARCH=i386 + endif + ifeq ($(ARCH),ppc) BASE_CFLAGS += -arch ppc ALTIVEC_CFLAGS = -faltivec @@ -498,15 +503,31 @@ ifeq ($(PLATFORM),darwin) endif ifeq ($(CROSS_COMPILING),1) - ifeq ($(ARCH),x86_64) - CC=x86_64-apple-darwin13-cc - RANLIB=x86_64-apple-darwin13-ranlib - else - ifeq ($(ARCH),x86) - CC=i386-apple-darwin13-cc - RANLIB=i386-apple-darwin13-ranlib - else - $(error Architecture $(ARCH) is not supported when cross compiling) + # If CC is already set to something generic, we probably want to use + # something more specific + ifneq ($(findstring $(strip $(CC)),cc gcc),) + CC= + endif + + ifndef CC + ifndef DARWIN + # macOS 10.9 SDK + DARWIN=13 + ifneq ($(findstring $(ARCH),ppc ppc64),) + # macOS 10.5 SDK, though as of writing osxcross doesn't support ppc/ppc64 + DARWIN=9 + endif + ifeq ($(ARCH),arm64) + # macOS 11.3 SDK + DARWIN=20.4 + endif + endif + + CC=$(MACOSX_ARCH)-apple-darwin$(DARWIN)-cc + RANLIB=$(MACOSX_ARCH)-apple-darwin$(DARWIN)-ranlib + + ifeq ($(call bin_path, $(CC)),) + $(error Unable to find osxcross $(CC)) endif endif endif