From be95183d4986c5cf5e6a9be7229ff8e16f69a9ba 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 8d15526c2..f54ebe8d2 100644 --- a/Makefile +++ b/Makefile @@ -317,6 +317,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 @@ -348,15 +353,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