From 36d48a5bb8af6bcbd1547c9a651b4b5cd651cd03 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 13 Dec 2020 16:52:35 +0000 Subject: [PATCH] Tweaks in makefile and macOS script, in preparation for arm64/m1 --- data/macos/build-deps-new.sh | 57 ++++++++++++++++++++++++++++-------- data/macos/build.sh | 14 +++++++-- data/macos/common.env | 14 ++++++++- data/macos/env.sh | 16 ++++++++-- source/Makefile.mk | 57 ++++++++++++++++++++++++++++++++++-- 5 files changed, 137 insertions(+), 21 deletions(-) diff --git a/data/macos/build-deps-new.sh b/data/macos/build-deps-new.sh index 636922df0..5994141d2 100755 --- a/data/macos/build-deps-new.sh +++ b/data/macos/build-deps-new.sh @@ -69,12 +69,21 @@ export PREFIX=${TARGETDIR}/carla${ARCH} export PATH=${PREFIX}/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig -export CFLAGS="-O3 -mtune=generic -msse -msse2 -mfpmath=sse -fvisibility=hidden -fdata-sections -ffunction-sections" -export CFLAGS="${CFLAGS} -fPIC -DPIC -DNDEBUG -I${PREFIX}/include -m${ARCH} -mmacosx-version-min=10.12" -export CXXFLAGS="${CFLAGS} -fvisibility-inlines-hidden -std=gnu++11 -stdlib=libc++" +export CFLAGS="-O3 -mtune=generic -msse -msse2 -fvisibility=hidden -fdata-sections -ffunction-sections" +export CFLAGS="${CFLAGS} -fPIC -DPIC -DNDEBUG -I${PREFIX}/include -mmacosx-version-min=10.12" export LDFLAGS="-fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs" -export LDFLAGS="${LDFLAGS} -L${PREFIX}/lib -m${ARCH} -stdlib=libc++" +export LDFLAGS="${LDFLAGS} -L${PREFIX}/lib -stdlib=libc++" + +if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then + export CFLAGS="${CFLAGS} -arch x86_64 -arch arm64 -Wno-unused-command-line-argument" + export LDFLAGS="${LDFLAGS} -arch x86_64 -arch arm64" +else + export CFLAGS="${CFLAGS} -mfpmath=sse -m${ARCH}" + export LDFLAGS="${LDFLAGS} -m${ARCH}" +fi + +export CXXFLAGS="${CFLAGS} -fvisibility-inlines-hidden -std=gnu++11 -stdlib=libc++" # --------------------------------------------------------------------------------------------------------------------- # pkgconfig @@ -318,11 +327,17 @@ if [ ! -f fftw-${FFTW3_VERSION}/build-done ]; then export CFLAGS="${CFLAGS} -ffast-math" export CXXFLAGS="${CXXFLAGS} -ffast-math" cd fftw-${FFTW3_VERSION} - ./configure --enable-static --enable-sse2 --disable-shared --disable-debug --prefix=${PREFIX} + if [ "${MACOS_UNIVERSAL}" -eq 0 ]; then + FFTW_EXTRAFLAGS="--enable-sse2" + fi + ./configure --enable-static ${FFTW_EXTRAFLAGS} --disable-shared --disable-debug --prefix=${PREFIX} make make install make clean - ./configure --enable-static --enable-sse --enable-sse2 --enable-single --disable-shared --disable-debug --prefix=${PREFIX} + if [ "${MACOS_UNIVERSAL}" -eq 0 ]; then + FFTW_EXTRAFLAGS="${FFTW_EXTRAFLAGS} --enable-sse" + fi + ./configure --enable-static ${FFTW_EXTRAFLAGS} --enable-single --disable-shared --disable-debug --prefix=${PREFIX} make make install make clean @@ -353,9 +368,18 @@ export PATH=${PREFIX}/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig export PKG_CONFIG=${TARGETDIR}/carla64/bin/pkg-config -export CFLAGS="-O3 -mtune=generic -msse -msse2 -mfpmath=sse -fPIC -DPIC -DNDEBUG -I${PREFIX}/include -m64 -mmacosx-version-min=10.12" +export CFLAGS="-O3 -mtune=generic -msse -msse2 -fPIC -DPIC -DNDEBUG -I${PREFIX}/include -m64 -mmacosx-version-min=10.12" +export LDFLAGS="-L${PREFIX}/lib -stdlib=libc++" + +if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then + export CFLAGS="${CFLAGS} -arch x86_64 -arch arm64 -Wno-unused-command-line-argument" + export LDFLAGS="${LDFLAGS} -arch x86_64 -arch arm64" +else + export CFLAGS="${CFLAGS} -mfpmath=sse -m${ARCH}" + export LDFLAGS="${LDFLAGS} -m${ARCH}" +fi + export CXXFLAGS="${CFLAGS} -std=gnu++11 -stdlib=libc++" -export LDFLAGS="-L${PREFIX}/lib -m64 -stdlib=libc++" export MAKE=/usr/bin/make @@ -374,11 +398,18 @@ fi if [ ! -f qtbase-everywhere-src-${QT5_VERSION}/build-done ]; then cd qtbase-everywhere-src-${QT5_VERSION} if [ ! -f configured ]; then + sed -i -e "s/QT_MAC_SDK_VERSION_MIN = 10.13/QT_MAC_SDK_VERSION_MIN = 10.12/" mkspecs/common/macx.conf + if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then + sed -i -e "s/QMAKE_APPLE_DEVICE_ARCHS = x86_64/QMAKE_APPLE_DEVICE_ARCHS = arm64 x86_64/" mkspecs/common/macx.conf + QT5_EXTRAFLAGS="-no-sse2" + else + QT5_EXTRAFLAGS="-sse2" + fi chmod +x configure ./configure -release -shared -opensource -confirm-license -platform macx-clang -framework \ -prefix ${PREFIX} -plugindir ${PREFIX}/lib/qt5/plugins -headerdir ${PREFIX}/include/qt5 \ -pkg-config -force-pkg-config -strip \ - -sse2 -no-sse3 -no-ssse3 -no-sse4.1 -no-sse4.2 -no-avx -no-avx2 -no-avx512 \ + ${QT5_EXTRAFLAGS} -no-sse3 -no-ssse3 -no-sse4.1 -no-sse4.2 -no-avx -no-avx2 -no-avx512 \ -no-mips_dsp -no-mips_dspr2 \ -no-pch -pkg-config \ -make libs -make tools \ @@ -397,7 +428,7 @@ if [ ! -f qtbase-everywhere-src-${QT5_VERSION}/build-done ]; then touch configured fi make ${MAKE_ARGS} - make install + make install ln -s ${PREFIX}/lib/QtCore.framework/Headers ${PREFIX}/include/qt5/QtCore ln -s ${PREFIX}/lib/QtGui.framework/Headers ${PREFIX}/include/qt5/QtGui ln -s ${PREFIX}/lib/QtWidgets.framework/Headers ${PREFIX}/include/qt5/QtWidgets @@ -451,8 +482,10 @@ fi if [ ! -f Python-${PYTHON_VERSION}/build-done ]; then cd Python-${PYTHON_VERSION} - sed -i -e "s/#zlib zlibmodule.c/zlib zlibmodule.c/" Modules/Setup.dist - ./configure --prefix=${PREFIX} --enable-optimizations --enable-shared + if [ "${MACOS_UNIVERSAL}" -ne 1 ]; then + sed -i -e "s/#zlib zlibmodule.c/zlib zlibmodule.c/" Modules/Setup.dist + fi + ./configure --prefix=${PREFIX} ${PYTHON_EXTRAFLAGS} --enable-optimizations --enable-shared make make install touch build-done diff --git a/data/macos/build.sh b/data/macos/build.sh index 7a325433d..cdfb706ed 100755 --- a/data/macos/build.sh +++ b/data/macos/build.sh @@ -38,9 +38,19 @@ unset CPPFLAGS ############################################################################################## # Complete 64bit build -export CFLAGS="-I${TARGETDIR}/carla64/include -m64 -mmacosx-version-min=${MACOS_VERSION_MIN}" +export CFLAGS="-I${TARGETDIR}/carla64/include -mmacosx-version-min=${MACOS_VERSION_MIN}" +export CFLAGS="${CFLAGS} -mtune=generic -msse -msse2" +export LDFLAGS="-L${TARGETDIR}/carla64/lib -mmacosx-version-min=${MACOS_VERSION_MIN} -stdlib=libc++" + +if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then + export CFLAGS="${CFLAGS} -arch x86_64 -arch arm64" + export LDFLAGS="${LDFLAGS} -arch x86_64 -arch arm64" +else + export CFLAGS="${CFLAGS} -m${ARCH}" + export LDFLAGS="${LDFLAGS} -m${ARCH}" +fi + export CXXFLAGS="${CFLAGS} -stdlib=libc++ -Wno-unknown-pragmas -Wno-unused-private-field -Werror=auto-var-id" -export LDFLAGS="-L${TARGETDIR}/carla64/lib -m64 -mmacosx-version-min=${MACOS_VERSION_MIN} -stdlib=libc++" export PATH=${TARGETDIR}/carla/bin:${TARGETDIR}/carla64/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin export PKG_CONFIG_PATH=${TARGETDIR}/carla/lib/pkgconfig:${TARGETDIR}/carla64/lib/pkgconfig diff --git a/data/macos/common.env b/data/macos/common.env index 752f4878a..9cf44704b 100644 --- a/data/macos/common.env +++ b/data/macos/common.env @@ -1,5 +1,11 @@ #!/bin/bash +if [ "$(uname -m)" = "arm64" ]; then + MACOS_UNIVERSAL=1 +else + MACOS_UNIVERSAL=0 +fi + PKG_CONFIG_VERSION=0.28 LIBLO_VERSION=0.30 ZLIB_VERSION=1.2.11 @@ -17,7 +23,13 @@ PYTHON_VERSION=3.7.4 PYLIBLO_VERSION=0.9.2 CXFREEZE_VERSION=6.1 -if [ -n "$DEPS_NEW" ]; then +if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then + PYTHON_VERSION=3.9.1 +else + PYTHON_VERSION=3.7.4 +fi + +if [ -n "${DEPS_NEW}" ]; then QT5_VERSION=5.12.5 QT5_MVERSION=5.12 PYQT5_VERSION=5.13.1 diff --git a/data/macos/env.sh b/data/macos/env.sh index acfa6de87..1f5544fa4 100644 --- a/data/macos/env.sh +++ b/data/macos/env.sh @@ -13,11 +13,21 @@ fi export CC=clang export CXX=clang++ -export CFLAGS="-I${TARGETDIR}/carla64/include -m64 -mmacosx-version-min=${MACOS_VERSION_MIN}" -export CXXFLAGS="${CFLAGS} -stdlib=libc++" -export LDFLAGS="-L${TARGETDIR}/carla64/lib -m64 -stdlib=libc++" +export CFLAGS="-I${TARGETDIR}/carla64/include -mmacosx-version-min=${MACOS_VERSION_MIN}" +export CFLAGS="${CFLAGS} -mtune=generic -msse -msse2" +export LDFLAGS="-L${TARGETDIR}/carla64/lib -stdlib=libc++" unset CPPFLAGS +if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then + export CFLAGS="${CFLAGS} -arch x86_64 -arch arm64" + export LDFLAGS="${LDFLAGS} -arch x86_64 -arch arm64" +else + export CFLAGS="${CFLAGS} -m${ARCH}" + export LDFLAGS="${LDFLAGS} -m${ARCH}" +fi + +export CXXFLAGS="${CFLAGS} -stdlib=libc++ -Wno-unknown-pragmas -Wno-unused-private-field -Werror=auto-var-id" + export MACOS="true" export PATH=${TARGETDIR}/carla/bin:${TARGETDIR}/carla64/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin diff --git a/source/Makefile.mk b/source/Makefile.mk index 9c7f8f3b2..eca7c99b7 100644 --- a/source/Makefile.mk +++ b/source/Makefile.mk @@ -11,7 +11,6 @@ AR ?= ar CC ?= gcc CXX ?= g++ -PKG_CONFIG ?= pkg-config WINECC ?= winegcc # --------------------------------------------------------------------------------------------------------------------- @@ -63,6 +62,42 @@ endif # HURD endif # HAIKU endif # BSD +# --------------------------------------------------------------------------------------------------------------------- +# Auto-detect the processor + +TARGET_PROCESSOR := $(firstword $(subst -, ,$(TARGET_MACHINE))) + +ifneq (,$(filter i%86,$(TARGET_PROCESSOR))) +CPU_I386=true +CPU_I386_OR_X86_64=true +endif +ifneq (,$(filter x86_64,$(TARGET_PROCESSOR))) +CPU_X86_64=true +CPU_I386_OR_X86_64=true +endif +ifneq (,$(filter arm%,$(TARGET_PROCESSOR))) +CPU_ARM=true +CPU_ARM_OR_AARCH64=true +endif +ifneq (,$(filter arm64%,$(TARGET_PROCESSOR))) +CPU_ARM64=true +CPU_ARM_OR_AARCH64=true +endif +ifneq (,$(filter aarch64%,$(TARGET_PROCESSOR))) +CPU_AARCH64=true +CPU_ARM_OR_AARCH64=true +endif + +# --------------------------------------------------------------------------------------------------------------------- +# Set PKG_CONFIG (can be overridden by environment variable) + +ifeq ($(WIN32),true) +# Build statically on Windows by default +PKG_CONFIG ?= pkg-config --static +else +PKG_CONFIG ?= pkg-config +endif + # --------------------------------------------------------------------------------------------------------------------- # Set LINUX_OR_MACOS @@ -75,14 +110,20 @@ LINUX_OR_MACOS=true endif # --------------------------------------------------------------------------------------------------------------------- -# Set MACOS_OR_WIN32 +# Set MACOS_OR_WIN32 and HAIKU_OR_MACOS_OR_WINDOWS + +ifeq ($(HAIKU),true) +HAIKU_OR_MACOS_OR_WIN32=true +endif ifeq ($(MACOS),true) MACOS_OR_WIN32=true +HAIKU_OR_MACOS_OR_WIN32=true endif ifeq ($(WIN32),true) MACOS_OR_WIN32=true +HAIKU_OR_MACOS_OR_WIN32=true endif # --------------------------------------------------------------------------------------------------------------------- @@ -108,7 +149,17 @@ endif # Set build and link flags BASE_FLAGS = -Wall -Wextra -pipe -DBUILDING_CARLA -DREAL_BUILD -MD -MP -fno-common -BASE_OPTS = -O3 -ffast-math -mtune=generic -msse -msse2 -mfpmath=sse -fdata-sections -ffunction-sections +BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections + +ifeq ($(CPU_I386_OR_X86_64),true) +BASE_OPTS += -mtune=generic -msse -msse2 -mfpmath=sse +endif + +ifeq ($(CPU_ARM),true) +ifneq ($(CPU_ARM64),true) +BASE_OPTS += -mfpu=neon-vfpv4 -mfloat-abi=hard +endif +endif ifeq ($(MACOS),true) # MacOS linker flags