Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewgrant/477c7037b1fc0dd7275109d3f2254ea9 to your computer and use it in GitHub Desktop.
Save andrewgrant/477c7037b1fc0dd7275109d3f2254ea9 to your computer and use it in GitHub Desktop.
Example changes for automake to support x86 & arm64 plus universal binaries
# configure.ac
# add an --enable-macos-universal-binary flag that when building for mac
# create a universal x86_64 / arm64 binary
AC_ARG_ENABLE([macos-universal-binary],
[AS_HELP_STRING([--enable-macos-universal-binary],
[Create an universal x86_64+arm64 binary when building for macos)])],,
[enable_macos_universal_binary=no])
# Determine if we're building for macos/darwin by checking for macos & darwin
# in the build triple.
AC_CANONICAL_HOST
case $host_os in
*macos*) macos="yes" ;;
*darwin*) macos="yes" ;;
*) macos="no" ;;
esac
# If building for Mac we will pass x86_64 or arm64 to the compiler based
# on user options or target type.
AS_IF([test "$macos" = "yes"],[
clang_arch_x86_64="no"
clang_arch_arm64="no"
# If building a universal binary ask clang for both
AS_IF([test "$enable_macos_universal_binary" = "yes"],[
clang_arch_x86_64="yes"
clang_arch_arm64="yes"
],[
# If building for x86_64 ask for that
AS_IF([test "$host_cpu" = "x86_64"],[
clang_arch_x86_64="yes"
])
# If building for arm64, ask for that
AS_IF([test "$host_cpu" = "aarch64"],[
clang_arch_arm64="yes"
])
])
# set the defines for our makefile
AM_CONDITIONAL([CLANG_ARCH_X86_64], [test "$clang_arch_x86_64" = "yes"])
AM_CONDITIONAL([CLANG_ARCH_ARM64], [test "$clang_arch_arm64" = "yes"])
], [
# Just set these to false. They need to be present in the else clause to keep
# automake happy.
AM_CONDITIONAL([CLANG_ARCH_X86_64], [false])
AM_CONDITIONAL([CLANG_ARCH_ARM64], [false])
])
# makefile.am
# Pass x86_64 in compiler and linker flags if asked
if CLANG_ARCH_X86_64
AM_CPPFLAGS += -arch x86_64
AM_CFLAGS += -arch x86_64
AM_CXXFLAGS += -arch x86_64
AM_LDFLAGS += -arch x86_64
endif
# Pass arm64 in compiler and linker flags if asked
# (Note - may be additive to the above)
if CLANG_ARCH_ARM64
AM_CPPFLAGS += -arch arm64
AM_CFLAGS += -arch arm64
AM_CXXFLAGS += -arch arm64
AM_LDFLAGS += -arch arm64
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment