#!/usr/bin/env bash set -e LANG=C LC_COLLATE=C LC_CTYPE=C LC_MESSAGES=C LC_MONETARY=C LC_NUMERIC=C LC_TIME=C LC_ALL=C export LANG LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LC_ALL # bash 3 does not work for this code if [ -z "$IN_DASH" ]; then if command -v dash >/dev/null; then export IN_DASH=1 exec dash "$0" "$@" else echo >&2 "Please install dash from Nix/Homebrew to run this script." exit 1 fi fi target_bits=64 target_build_arch=-m64 if [ "$(uname -m)" = arm64 ]; then export APPLE_SILICON=1 target_cpu=ARM64 else target_cpu=x86_64 fi case "$1" in -[Ii][Nn][Tt][Ee][Ll]) intel_target=1 shift ;; -[Ii][Nn][Tt][Ee][Ll]64) intel_target=1 shift ;; -[Xx]86_64) intel_target=1 shift ;; -64) shift ;; -[Aa][Rr][Mm]64) shift ;; -32) target_build_arch=-m32 target_cpu=i386 shift ;; esac if [ -n "$APPLE_SILICON" ]; then if [ -n "$intel_target" ]; then target_build_arch='-target x86_64-apple-macos10.15 -march=core2 -mtune=skylake' target_cpu=x86_64 export MACOSX_DEPLOYMENT_TARGET=10.15 # Catalina else export MACOSX_DEPLOYMENT_TARGET=11.0 # Big Sur fi elif [ "$target_cpu" = x86_64 ]; then target_build_arch='-m64 -march=core2 -mtune=skylake' fi # Need to use Xcode 9 for 32 bit builds on Mojave and newer. # Place it in /Applications/Xcode9.app . if [ "$target_cpu" = i386 ] && [ -d /Applications/Xcode9.app ]; then PREV_XCODE=$(xcode-select -p) printf "\nSetting Xcode9 as the default Xcode for 32 bit build...\n\n" sudo xcode-select -s /Applications/Xcode9.app/Contents/Developer fi if command -v brew >/dev/null; then export BREW_PREFIX=$(brew --prefix) elif [ -f /usr/local/bin/brew ]; then export BREW_PREFIX=$(/usr/local/bin/brew --prefix) elif [ -f /opt/homebrew/bin/brew ]; then export BREW_PREFIX=$(/opt/homebrew/bin/brew --prefix) fi export BUILD_ROOT="${BUILD_ROOT:-$HOME/vbam-build-mac-${target_cpu}}$BUILD_ROOT_SUFFIX" ver_file=$(mktemp) sw_vers -productVersion | sed 's/\./ /g' > "$ver_file" read -r macos_major macos_minor macos_patch < "$ver_file" rm -f "$ver_file" # Find the highest version clang and llvm in Nix or Homebrew. best_llvm=$( ( for nix_clang in $(find /nix/store -maxdepth 1 -type d -name '*-clang-[0-9]*[0-9]'); do llvm_ver=$(echo "$nix_clang" | sed -E 's/.*-([0-9][0-9.]*[0-9])$/\1/') nix_llvm=$(find /nix/store -maxdepth 1 -type d -name '*-llvm-'"$llvm_ver") if [ -x "$nix_clang/bin/clang++" ]; then echo "$nix_clang:$nix_llvm $($nix_clang/bin/clang++ --version | head -1 | awk '{ print $NF }')" fi done for brew_llvm in $(find "$BREW_PREFIX"/Cellar -maxdepth 1 -type l -name 'llvm*'); do if [ -x "$brew_llvm/bin/clang++" ]; then echo "$brew_llvm $($brew_llvm/bin/clang++ --version | head -1 | awk '{ print $NF }')" fi done ) | sort -k2,2 -V -r | head -1 | awk '{ print $1 }' ) BUILD_ENV=$(cat <