[vlc-devel] [PATCH] extras: fix arch handling in macOS build script

Felix Paul Kühne fkuehne at videolan.org
Wed Dec 9 17:33:48 CET 2020


From: Felix Paul Kühne <felix at feepk.net>

---
 extras/package/macosx/build.sh     | 27 +++++++-----
 extras/package/macosx/env.build.sh | 71 +++++++++++++++++++++++-------
 2 files changed, 73 insertions(+), 25 deletions(-)

diff --git a/extras/package/macosx/build.sh b/extras/package/macosx/build.sh
index 69395ef5d0..554069f97c 100755
--- a/extras/package/macosx/build.sh
+++ b/extras/package/macosx/build.sh
@@ -115,9 +115,13 @@ if [ "$QUIET" = "yes" ]; then
     out="/dev/null"
 fi
 
-info "Building VLC for the Mac OS X"
+ACTUAL_ARCH=`get_actual_arch $ARCH`
+BUILD_ARCH=`get_buildsystem_arch $BUILD_ARCH`
 
-TRIPLET=$(vlcGetTriplet)
+info "Building VLC for macOS for architecture ${ACTUAL_ARCH} on a ${BUILD_ARCH} device"
+
+BUILD_TRIPLET=$(vlcGetBuildTriplet)
+HOST_TRIPLET=$(vlcGetHostTriplet)
 export SDKROOT
 vlcSetBaseEnvironment
 vlcroot="$(vlcGetRootDir)"
@@ -157,11 +161,11 @@ info "Building contribs"
 spushd "${vlcroot}/contrib"
 
 if [ "$REBUILD" = "yes" ]; then
-    rm -rf contrib-$TRIPLET
-    rm -rf $TRIPLET
+    rm -rf contrib-$HOST_TRIPLET
+    rm -rf $HOST_TRIPLET
 fi
-mkdir -p contrib-$TRIPLET && cd contrib-$TRIPLET
-../bootstrap --build=$TRIPLET --host=$TRIPLET > $out
+mkdir -p contrib-$HOST_TRIPLET && cd contrib-$HOST_TRIPLET
+../bootstrap --build=$BUILD_TRIPLET --host=$HOST_TRIPLET > $out
 
 if [ "$CONTRIBFROMSOURCE" = "yes" ]; then
     make list
@@ -182,6 +186,7 @@ spopd
 
 
 vlcUnsetContribEnvironment
+vlcSetLibVLCEnvironment
 
 #
 # vlc/bootstrap
@@ -214,8 +219,8 @@ fi
 if [ "${vlcroot}/configure" -nt Makefile ]; then
 
   ${vlcroot}/extras/package/macosx/configure.sh \
-      --build=$TRIPLET \
-      --host=$TRIPLET \
+      --build=$BUILD_TRIPLET \
+      --host=$HOST_TRIPLET \
       --with-macosx-version-min=$MINIMAL_OSX_VERSION \
       --with-macosx-sdk=$SDKROOT \
       $CONFIGFLAGS \
@@ -237,7 +242,6 @@ make -j$JOBS
 info "Preparing VLC.app"
 make VLC.app
 
-
 if [ "$PACKAGETYPE" = "u" ]; then
     info "Copying app with debug symbols into VLC-debug.app and stripping"
     rm -rf VLC-debug.app
@@ -248,14 +252,15 @@ if [ "$PACKAGETYPE" = "u" ]; then
     (cd VLC-debug.app/Contents/MacOS/lib/ && rm libvlccore.dylib && mv libvlccore.*.dylib libvlccore.dylib)
     (cd VLC-debug.app/Contents/MacOS/lib/ && rm libvlc.dylib && mv libvlc.*.dylib libvlc.dylib)
 
-
     find VLC.app/ -name "*.dylib" -exec strip -x {} \;
     find VLC.app/ -type f -name "VLC" -exec strip -x {} \;
     find VLC.app/ -type f -name "Sparkle" -exec strip -x {} \;
     find VLC.app/ -type f -name "Growl" -exec strip -x {} \;
     find VLC.app/ -type f -name "Breakpad" -exec strip -x {} \;
 
+if [ "$BUILD_TRIPLET" = "$HOST_TRIPLET" ]; then
     bin/vlc-cache-gen VLC.app/Contents/MacOS/plugins
+fi
 
     info "Building VLC release archive"
     make package-macosx-release
@@ -273,3 +278,5 @@ fi
 if [ ! -z "$VLCBUILDDIR" ]; then
     popd
 fi
+
+vlcUnsetLibVLCEnvironment
diff --git a/extras/package/macosx/env.build.sh b/extras/package/macosx/env.build.sh
index 755722fb9b..894a6f9fd2 100755
--- a/extras/package/macosx/env.build.sh
+++ b/extras/package/macosx/env.build.sh
@@ -1,16 +1,40 @@
 #!/bin/bash
 
 ARCH="x86_64"
+BUILD_ARCH=`uname -m | cut -d. -f1`
 MINIMAL_OSX_VERSION="10.11"
 
+get_actual_arch() {
+    if [ "$1" = "aarch64" ]; then
+        echo "arm64"
+    else
+        echo "$1"
+    fi
+}
+
+get_buildsystem_arch() {
+    if [ "$1" = "arm64" ]; then
+        echo "aarch64"
+    else
+        echo "$1"
+    fi
+}
 
-vlcGetTriplet() {
+vlcGetOSXKernelVersion() {
     local OSX_KERNELVERSION=$(uname -r | cut -d. -f1)
     if [ ! -z "$VLC_FORCE_KERNELVERSION" ]; then
         OSX_KERNELVERSION="$VLC_FORCE_KERNELVERSION"
     fi
 
-    echo "$ARCH-apple-darwin$OSX_KERNELVERSION"
+    echo "$OSX_KERNELVERSION"
+}
+
+vlcGetBuildTriplet() {
+    echo "$BUILD_ARCH-apple-darwin$(vlcGetOSXKernelVersion)"
+}
+
+vlcGetHostTriplet() {
+    echo "$ARCH-apple-darwin$(vlcGetOSXKernelVersion)"
 }
 
 # Gets VLCs root dir based on location of this file, also follow symlinks
@@ -25,30 +49,32 @@ vlcGetRootDir() {
 }
 
 vlcSetBaseEnvironment() {
-    local LOCAL_TRIPLET="$TRIPLET"
-    if [ -z "$LOCAL_TRIPLET" ]; then
-        LOCAL_TRIPLET="$(vlcGetTriplet)"
+    local LOCAL_BUILD_TRIPLET="$BUILD_TRIPLET"
+    if [ -z "$LOCAL_BUILD_TRIPLET" ]; then
+        LOCAL_BUILD_TRIPLET="$(vlcGetBuildTriplet)"
     fi
 
     local VLC_ROOT_DIR="$(vlcGetRootDir)"
 
     echo "Setting base environment"
-    echo "Using VLC root dir $VLC_ROOT_DIR and triplet $LOCAL_TRIPLET"
+    echo "Using VLC root dir $VLC_ROOT_DIR, build triplet $LOCAL_BUILD_TRIPLET and host triplet $(vlcGetHostTriplet)"
 
+    export AR="$(xcrun --find ar)"
     export CC="$(xcrun --find clang)"
     export CXX="$(xcrun --find clang++)"
+    export NM="$(xcrun --find nm)"
     export OBJC="$(xcrun --find clang)"
     export OBJCXX="$(xcrun --find clang++)"
-    export AR="$(xcrun --find ar)"
     export RANLIB="$(xcrun --find ranlib)"
-    export NM="$(xcrun --find nm)"
+    export STRINGS="`xcrun --find strings`"
+    export STRIP="`xcrun --find strip`"
 
     python3Path=$(echo /Library/Frameworks/Python.framework/Versions/3.*/bin | awk '{print $1;}')
     if [ ! -d "$python3Path" ]; then
         python3Path=""
     fi
 
-    export PATH="${VLC_ROOT_DIR}/extras/tools/build/bin:${VLC_ROOT_DIR}/contrib/${LOCAL_TRIPLET}/bin:$python3Path:${VLC_PATH}:/bin:/sbin:/usr/bin:/usr/sbin"
+    export PATH="${VLC_ROOT_DIR}/extras/tools/build/bin:${VLC_ROOT_DIR}/contrib/${LOCAL_BUILD_TRIPLET}/bin:$python3Path:${VLC_PATH}:/bin:/sbin:/usr/bin:/usr/sbin"
 }
 
 vlcSetSymbolEnvironment() {
@@ -110,13 +136,13 @@ vlcSetContribEnvironment() {
     export CXXFLAGS="-Werror=partial-availability"
     export OBJCFLAGS="-Werror=partial-availability"
 
-    export EXTRA_CFLAGS="-isysroot $SDKROOT -mmacosx-version-min=$MINIMAL_OSX_VERSION -DMACOSX_DEPLOYMENT_TARGET=$MINIMAL_OSX_VERSION"
-    export EXTRA_LDFLAGS="-isysroot $SDKROOT -mmacosx-version-min=$MINIMAL_OSX_VERSION -DMACOSX_DEPLOYMENT_TARGET=$MINIMAL_OSX_VERSION"
+    export EXTRA_CFLAGS="-isysroot $SDKROOT -mmacosx-version-min=$MINIMAL_OSX_VERSION -DMACOSX_DEPLOYMENT_TARGET=$MINIMAL_OSX_VERSION -arch $ACTUAL_ARCH"
+    export EXTRA_LDFLAGS="-isysroot $SDKROOT -mmacosx-version-min=$MINIMAL_OSX_VERSION -DMACOSX_DEPLOYMENT_TARGET=$MINIMAL_OSX_VERSION -arch $ACTUAL_ARCH"
     export XCODE_FLAGS="MACOSX_DEPLOYMENT_TARGET=$MINIMAL_OSX_VERSION -sdk $SDKROOT WARNING_CFLAGS=-Werror=partial-availability"
 }
 
 vlcUnsetContribEnvironment() {
-    echo "Unsetting contrib flags, prepare VLC flags"
+    echo "Unsetting contrib flags"
 
     unset CFLAGS
     unset CXXFLAGS
@@ -125,13 +151,26 @@ vlcUnsetContribEnvironment() {
     unset EXTRA_CFLAGS
     unset EXTRA_LDFLAGS
     unset XCODE_FLAGS
+}
+
+vlcSetLibVLCEnvironment() {
+    echo "Setting libVLC flags"
 
     # Enable debug symbols by default
-    export CFLAGS="-g"
-    export CXXFLAGS="-g"
-    export OBJCFLAGS="-g"
+    export CFLAGS="-g -arch $ACTUAL_ARCH"
+    export CXXFLAGS="-g -arch $ACTUAL_ARCH"
+    export OBJCFLAGS="-g -arch $ACTUAL_ARCH"
+    export LDFLAGS="-arch $ACTUAL_ARCH"
 }
 
+vlcUnsetLibVLCEnvironment() {
+    echo "Unsetting libVLC flags"
+
+    unset CFLAGS
+    unset CXXFLAGS
+    unset OBJCFLAGS
+    unset LDFLAGS
+}
 
 # Parameter handling
 
@@ -151,9 +190,11 @@ fi
 if [ "$VLC_ENV_MODE" = "contrib" ]; then
     vlcSetBaseEnvironment
     vlcSetSymbolEnvironment
+    vlcUnsetLibVLCEnvironment
     vlcSetContribEnvironment "$MINIMAL_OSX_VERSION"
 elif [ "$VLC_ENV_MODE" = "vlc" ]; then
     vlcSetBaseEnvironment
     vlcSetSymbolEnvironment
     vlcUnsetContribEnvironment
+    vlcSetLibVLCEnvironment
 fi
-- 
2.24.3 (Apple Git-128)



More information about the vlc-devel mailing list