Skip to content

Commit

Permalink
Fix error when cross-compiling for macOS arm64 using Makefile
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
zturtleman committed Dec 18, 2024
1 parent a15f677 commit be95183
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit be95183

Please sign in to comment.