#!/usr/local/bin/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 homebrew or macports to run this script" # exit 1 # fi #fi target_bits=64 target_cpu=x86_64 case "$1" in -64) shift ;; -32) target_bits=32 target_cpu=i386 shift ;; -arm64) target_bits=arm64 target_cpu=arm64 shift ;; esac # Need to use Xcode 9 for 32 bit builds on Mojave and newer. # Place it in /Applications/Xcode9.app . if [ "$target_bits" -eq 32 ] && [ -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 export BUILD_ROOT="${BUILD_ROOT:-$HOME/vbam-build-mac-${target_bits}bit}$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 /usr/local/opt -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 <