144 lines
3.3 KiB
Bash
Executable File
144 lines
3.3 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
# augment path to help it find cmake installed in /usr/local/bin,
|
|
# e.g. via brew. Xcode's Run Script phase doesn't seem to honor
|
|
# ~/.MacOSX/environment.plist
|
|
if [[ `uname -m` == 'arm64' ]]; then
|
|
echo "** Running on a Apple Silicon M1"
|
|
PATH="/opt/homebrew/bin:$PATH"
|
|
else
|
|
echo "** Running on a Apple x86"
|
|
PATH="/usr/local/bin:$PATH"
|
|
fi
|
|
|
|
SCRIPT_DIR=$(dirname "$0")
|
|
source "${SCRIPT_DIR}/xcode_functions.sh"
|
|
|
|
function setup_build_environment ()
|
|
{
|
|
pushd "$SCRIPT_DIR/.." > /dev/null
|
|
ROOT_PATH="$PWD"
|
|
popd > /dev/null
|
|
|
|
CLANG="/usr/bin/xcrun clang"
|
|
CC="${CLANG}"
|
|
CPP="${CLANG} -E"
|
|
|
|
# We need to clear this so that cmake doesn't have a conniption
|
|
MACOSX_DEPLOYMENT_TARGET=""
|
|
|
|
XCODE_MAJOR_VERSION=$(xcode_major_version)
|
|
XCODE_MINOR_VERSION=$(xcode_minor_version)
|
|
|
|
CAN_BUILD_ARM="0"
|
|
|
|
# Determine if we can be building for ARM Macs
|
|
if [ "${XCODE_MAJOR_VERSION}" -ge "13" ]
|
|
then
|
|
CAN_BUILD_ARM="1"
|
|
elif [ "${XCODE_MAJOR_VERSION}" -eq "12" ] && [ "${XCODE_MINOR_VERSION}" -ge "2" ]
|
|
then
|
|
CAN_BUILD_ARM="1"
|
|
fi
|
|
|
|
ARCHS="x86_64"
|
|
if [ "${CAN_BUILD_ARM}" -eq "1" ]
|
|
then
|
|
ARCHS="${ARCHS} arm64 arm64e"
|
|
fi
|
|
}
|
|
|
|
function build_all_archs ()
|
|
{
|
|
setup_build_environment
|
|
|
|
local setup=$1
|
|
local build_arch=$2
|
|
local finish_build=$3
|
|
|
|
# run the prepare function
|
|
eval $setup
|
|
|
|
echo "Building for ${ARCHS}"
|
|
|
|
for ARCH in ${ARCHS}
|
|
do
|
|
PLATFORM="macosx"
|
|
SDKVERSION=$(macos_sdk_version)
|
|
|
|
SDKNAME="${PLATFORM}${SDKVERSION}"
|
|
SDKROOT="$(sdk_path ${SDKNAME})"
|
|
|
|
echo "Building ${LIBRARY_NAME} for ${SDKNAME} ${ARCH}"
|
|
echo "Please stand by..."
|
|
|
|
# run the per arch build command
|
|
eval $build_arch
|
|
done
|
|
|
|
# finish the build (usually lipo)
|
|
eval $finish_build
|
|
}
|
|
|
|
function setup ()
|
|
{
|
|
if [ "${ROOT_PATH}/External/libgit2-mac/libgit2-mac.a" -nt "${ROOT_PATH}/External/libgit2" ]
|
|
then
|
|
echo "No update needed."
|
|
exit 0
|
|
fi
|
|
|
|
LIBRARY_NAME="libgit2"
|
|
LIB_PATH="${ROOT_PATH}/External/libgit2-mac"
|
|
rm -rf "${LIB_PATH}"
|
|
|
|
pushd "${ROOT_PATH}/External/libgit2" > /dev/null
|
|
}
|
|
|
|
function build_libgit2 ()
|
|
{
|
|
rm -rf "build"
|
|
mkdir "build"
|
|
|
|
pushd "build" > /dev/null
|
|
|
|
# install the each built arch somewhere sane
|
|
INSTALL_PREFIX="${LIB_PATH}/${SDKNAME}-${ARCH}.sdk"
|
|
|
|
mkdir -p "${INSTALL_PREFIX}"
|
|
|
|
LOG="${INSTALL_PREFIX}/build-libgit2.log"
|
|
echo "$LOG"
|
|
|
|
MACOSX_DEPLOYMENT_TARGET="10.9" cmake \
|
|
-DBUILD_SHARED_LIBS:BOOL=OFF \
|
|
-DCMAKE_PREFIX_PATH:PATH="${ROOT_PATH}/External/libssh2-mac/bin/${SDKNAME}-${ARCH}.sdk" \
|
|
-DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PREFIX}/" \
|
|
-DBUILD_CLAR:BOOL=OFF \
|
|
-DTHREADSAFE:BOOL=ON \
|
|
-DCMAKE_OSX_ARCHITECTURES:STRING="${ARCH}" \
|
|
.. >> "${LOG}" 2>&1
|
|
cmake --build . --target install >> "${LOG}" 2>&1
|
|
|
|
# push the built library into the list
|
|
BUILT_LIB_PATHS+=("${INSTALL_PREFIX}/lib/libgit2.a")
|
|
popd > /dev/null
|
|
}
|
|
|
|
function fat_binary ()
|
|
{
|
|
echo "Building fat binary..."
|
|
|
|
lipo -create "${BUILT_LIB_PATHS[@]}" -output "${ROOT_PATH}/External/libgit2-mac/libgit2-mac.a"
|
|
|
|
echo "Building done."
|
|
|
|
popd > /dev/null
|
|
}
|
|
|
|
build_all_archs setup build_libgit2 fat_binary
|
|
|
|
echo "libgit2 has been updated."
|