2022-03-03 16:14:14 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
# Copyright (c) 2022 by The qTox Project Contributors
|
|
|
|
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2022-03-07 10:54:59 +08:00
|
|
|
MACOS_MINIMUM_SUPPORTED_VERSION=10.15
|
|
|
|
|
2022-03-03 16:14:14 +08:00
|
|
|
usage()
|
|
|
|
{
|
|
|
|
# note: this is the usage from the build script's context, so the usage
|
|
|
|
# doesn't include --dep argument, since that comes from the build script
|
|
|
|
# itself.
|
|
|
|
echo "Download and build $DEP_NAME for the Windows cross compiling environment"
|
2022-03-07 17:28:13 +08:00
|
|
|
echo "Usage: $0 --arch {$1}"
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_supported()
|
|
|
|
{
|
|
|
|
for supported in $2; do
|
|
|
|
if [ "$1" == "$supported" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
usage "$2"
|
|
|
|
exit 1
|
2022-03-03 16:14:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
parse_arch()
|
|
|
|
{
|
|
|
|
while (( $# > 0 )); do
|
|
|
|
case $1 in
|
|
|
|
--arch) SCRIPT_ARCH=$2; shift 2 ;;
|
|
|
|
--dep) DEP_NAME=$2; shift 2 ;;
|
2022-03-07 17:28:13 +08:00
|
|
|
--supported) SUPPORTED=$2; shift 2 ;;
|
2022-03-03 16:14:14 +08:00
|
|
|
-h|--help) usage; exit 1 ;;
|
|
|
|
*) echo "Unexpected argument $1"; usage; exit 1;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2022-03-07 17:28:13 +08:00
|
|
|
assert_supported "${SCRIPT_ARCH}" "${SUPPORTED}"
|
|
|
|
|
2022-03-03 16:14:14 +08:00
|
|
|
if [ "${SCRIPT_ARCH}" == "win32" ] || [ "${SCRIPT_ARCH}" == "win64" ]; then
|
|
|
|
if [ "${SCRIPT_ARCH}" == "win32" ]; then
|
2022-03-07 10:54:59 +08:00
|
|
|
MINGW_ARCH="i686"
|
2022-03-03 16:14:14 +08:00
|
|
|
elif [ "${SCRIPT_ARCH}" == "win64" ]; then
|
2022-03-07 10:54:59 +08:00
|
|
|
MINGW_ARCH="x86_64"
|
2022-03-03 16:14:14 +08:00
|
|
|
fi
|
|
|
|
DEP_PREFIX='/windows/'
|
|
|
|
HOST_OPTION="--host=${MINGW_ARCH}-w64-mingw32"
|
2022-03-07 10:54:59 +08:00
|
|
|
CROSS_LDFLAG=""
|
|
|
|
CROSS_CFLAG=""
|
|
|
|
CROSS_CPPFLAG=""
|
2022-03-03 16:14:14 +08:00
|
|
|
MAKE_JOBS="$(nproc)"
|
|
|
|
CMAKE_TOOLCHAIN_FILE="-DCMAKE_TOOLCHAIN_FILE=/build/windows-toolchain.cmake"
|
2022-03-07 10:54:59 +08:00
|
|
|
elif [ "${SCRIPT_ARCH}" == "macos" ]; then
|
|
|
|
DEP_PREFIX="$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../local-deps)"
|
|
|
|
mkdir -p $DEP_PREFIX
|
|
|
|
HOST_OPTION=''
|
|
|
|
CROSS_LDFLAG="-mmacosx-version-min=$MACOS_MINIMUM_SUPPORTED_VERSION"
|
|
|
|
CROSS_CFLAG="-mmacosx-version-min=$MACOS_MINIMUM_SUPPORTED_VERSION"
|
|
|
|
CROSS_CPPFLAG="-mmacosx-version-min=$MACOS_MINIMUM_SUPPORTED_VERSION"
|
|
|
|
MAKE_JOBS="$(sysctl -n hw.ncpu)"
|
|
|
|
CMAKE_TOOLCHAIN_FILE=""
|
2022-03-03 16:14:14 +08:00
|
|
|
else
|
|
|
|
echo "Unexpected arch ${SCRIPT_ARCH}"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
export PKG_CONFIG_PATH="${DEP_PREFIX}/lib/pkgconfig"
|
|
|
|
}
|