2018-03-27 18:03:26 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
2019-04-20 08:24:05 +08:00
|
|
|
# Find .vcpkg-root, which indicates the root of this repo
|
|
|
|
vcpkgRootDir=$(X= cd -- "$(dirname -- "$0")" && pwd -P)
|
|
|
|
while [ "$vcpkgRootDir" != "/" ] && ! [ -e "$vcpkgRootDir/.vcpkg-root" ]; do
|
|
|
|
vcpkgRootDir="$(dirname "$vcpkgRootDir")"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Enable using this entry point on windows from git bash by redirecting to the .bat file.
|
|
|
|
unixName=$(uname -s | sed 's/MINGW.*_NT.*/MINGW_NT/')
|
|
|
|
if [ "$unixName" = "MINGW_NT" ]; then
|
|
|
|
vcpkgRootDir=$(cygpath -aw "$vcpkgRootDir")
|
|
|
|
cmd "/C $vcpkgRootDir\\bootstrap-vcpkg.bat" || exit 1
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Argument parsing
|
2018-06-12 08:01:13 +08:00
|
|
|
vcpkgDisableMetrics="OFF"
|
2018-12-12 02:15:44 +08:00
|
|
|
vcpkgUseSystem=false
|
2019-04-11 15:32:03 +08:00
|
|
|
vcpkgAllowAppleClang=OFF
|
2018-06-09 09:01:35 +08:00
|
|
|
for var in "$@"
|
|
|
|
do
|
2018-12-12 02:15:44 +08:00
|
|
|
if [ "$var" = "-disableMetrics" -o "$var" = "--disableMetrics" ]; then
|
2018-06-12 08:01:13 +08:00
|
|
|
vcpkgDisableMetrics="ON"
|
2018-12-12 02:15:44 +08:00
|
|
|
elif [ "$var" = "-useSystemBinaries" -o "$var" = "--useSystemBinaries" ]; then
|
|
|
|
vcpkgUseSystem=true
|
2019-04-11 15:32:03 +08:00
|
|
|
elif [ "$var" = "-allowAppleClang" -o "$var" = "--allowAppleClang" ]; then
|
|
|
|
vcpkgAllowAppleClang=ON
|
2018-12-12 02:15:44 +08:00
|
|
|
elif [ "$var" = "-help" -o "$var" = "--help" ]; then
|
|
|
|
echo "Usage: ./bootstrap-vcpkg.sh [options]"
|
|
|
|
echo
|
|
|
|
echo "Options:"
|
|
|
|
echo " -help Display usage help"
|
|
|
|
echo " -disableMetrics Do not build metrics reporting into the executable"
|
|
|
|
echo " -useSystemBinaries Force use of the system utilities for building vcpkg"
|
2019-04-11 15:32:03 +08:00
|
|
|
echo " -allowAppleClang Set VCPKG_ALLOW_APPLE_CLANG to build vcpkg in apple with clang anyway"
|
2018-12-12 02:15:44 +08:00
|
|
|
exit 1
|
2018-06-09 09:01:35 +08:00
|
|
|
else
|
2018-12-12 02:15:44 +08:00
|
|
|
echo "Unknown argument $var. Use '-help' for help."
|
2018-06-09 09:01:35 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2018-12-12 03:48:41 +08:00
|
|
|
if [ -z ${VCPKG_DOWNLOADS+x} ]; then
|
|
|
|
downloadsDir="$vcpkgRootDir/downloads"
|
|
|
|
else
|
|
|
|
downloadsDir="$VCPKG_DOWNLOADS"
|
|
|
|
if [ ! -d "$VCPKG_DOWNLOADS" ]; then
|
|
|
|
echo "VCPKG_DOWNLOADS was set to '$VCPKG_DOWNLOADS', but that was not a directory."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
2018-03-27 18:03:26 +08:00
|
|
|
|
|
|
|
extractStringBetweenDelimiters()
|
|
|
|
{
|
|
|
|
input=$1;leftDelim=$2;rightDelim=$3
|
|
|
|
output="${input##*$leftDelim}"
|
|
|
|
output="${output%%$rightDelim*}"
|
|
|
|
echo "$output"
|
|
|
|
}
|
|
|
|
|
|
|
|
vcpkgCheckRepoTool()
|
|
|
|
{
|
|
|
|
__tool=$1
|
|
|
|
if ! command -v "$__tool" >/dev/null 2>&1 ; then
|
|
|
|
echo "Could not find $__tool. Please install it (and other dependencies) with:"
|
|
|
|
echo "sudo apt-get install curl unzip tar"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
vcpkgCheckEqualFileHash()
|
|
|
|
{
|
|
|
|
url=$1; filePath=$2; expectedHash=$3
|
|
|
|
|
2018-04-26 13:23:45 +08:00
|
|
|
if command -v "sha512sum" >/dev/null 2>&1 ; then
|
|
|
|
actualHash=$(sha512sum "$filePath")
|
|
|
|
else
|
|
|
|
# sha512sum is not available by default on osx
|
|
|
|
# shasum is not available by default on Fedora
|
|
|
|
actualHash=$(shasum -a 512 "$filePath")
|
2018-04-26 08:38:45 +08:00
|
|
|
fi
|
|
|
|
|
2018-03-27 18:03:26 +08:00
|
|
|
actualHash="${actualHash%% *}" # shasum returns [hash filename], so get the first word
|
|
|
|
|
|
|
|
if ! [ "$expectedHash" = "$actualHash" ]; then
|
|
|
|
echo ""
|
|
|
|
echo "File does not have expected hash:"
|
|
|
|
echo " url: [ $url ]"
|
|
|
|
echo " File path: [ $downloadPath ]"
|
|
|
|
echo " Expected hash: [ $sha512 ]"
|
|
|
|
echo " Actual hash: [ $actualHash ]"
|
2019-03-20 07:32:24 +08:00
|
|
|
exit 1
|
2018-03-27 18:03:26 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
vcpkgDownloadFile()
|
|
|
|
{
|
|
|
|
url=$1; downloadPath=$2 sha512=$3
|
|
|
|
vcpkgCheckRepoTool "curl"
|
|
|
|
rm -rf "$downloadPath.part"
|
|
|
|
curl -L $url --create-dirs --output "$downloadPath.part" || exit 1
|
|
|
|
|
|
|
|
vcpkgCheckEqualFileHash $url "$downloadPath.part" $sha512
|
|
|
|
mv "$downloadPath.part" "$downloadPath"
|
|
|
|
}
|
|
|
|
|
|
|
|
vcpkgExtractArchive()
|
|
|
|
{
|
|
|
|
archive=$1; toPath=$2
|
|
|
|
rm -rf "$toPath" "$toPath.partial"
|
|
|
|
mkdir -p "$toPath.partial"
|
|
|
|
|
|
|
|
archiveType="${archive##*.}"
|
|
|
|
if [ "$archiveType" = "zip" ]; then
|
|
|
|
vcpkgCheckRepoTool "unzip"
|
|
|
|
$(cd "$toPath.partial" && unzip -qqo "$archive")
|
|
|
|
else
|
|
|
|
vcpkgCheckRepoTool "tar"
|
|
|
|
$(cd "$toPath.partial" && tar xzf "$archive")
|
|
|
|
fi
|
|
|
|
mv "$toPath.partial" "$toPath"
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchTool()
|
|
|
|
{
|
|
|
|
tool=$1; UNAME=$2; __output=$3
|
|
|
|
|
|
|
|
if [ "$tool" = "" ]; then
|
|
|
|
echo "No tool name provided"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$UNAME" = "Linux" ]; then
|
|
|
|
os="linux"
|
|
|
|
elif [ "$UNAME" = "Darwin" ]; then
|
|
|
|
os="osx"
|
2019-01-08 08:03:35 +08:00
|
|
|
elif [ "$UNAME" = "FreeBSD" ]; then
|
|
|
|
os="freebsd"
|
2018-03-27 18:03:26 +08:00
|
|
|
else
|
|
|
|
echo "Unknown uname: $UNAME"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2018-05-16 12:48:26 +08:00
|
|
|
xmlFileAsString=`cat "$vcpkgRootDir/scripts/vcpkgTools.xml"`
|
2018-03-27 18:03:26 +08:00
|
|
|
toolRegexStart="<tool name=\"$tool\" os=\"$os\">"
|
|
|
|
toolData="$(extractStringBetweenDelimiters "$xmlFileAsString" "$toolRegexStart" "</tool>")"
|
|
|
|
if [ "$toolData" = "" ]; then
|
|
|
|
echo "Unknown tool: $tool"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
version="$(extractStringBetweenDelimiters "$toolData" "<version>" "</version>")"
|
|
|
|
|
|
|
|
toolPath="$downloadsDir/tools/$tool-$version-$os"
|
|
|
|
|
|
|
|
exeRelativePath="$(extractStringBetweenDelimiters "$toolData" "<exeRelativePath>" "</exeRelativePath>")"
|
|
|
|
exePath="$toolPath/$exeRelativePath"
|
|
|
|
|
|
|
|
if [ -e "$exePath" ]; then
|
|
|
|
eval $__output="'$exePath'"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
isArchive=true
|
|
|
|
if [ $isArchive = true ]; then
|
|
|
|
archiveName="$(extractStringBetweenDelimiters "$toolData" "<archiveName>" "</archiveName>")"
|
|
|
|
downloadPath="$downloadsDir/$archiveName"
|
|
|
|
else
|
|
|
|
echo "Non-archives not supported yet"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
url="$(extractStringBetweenDelimiters "$toolData" "<url>" "</url>")"
|
|
|
|
sha512="$(extractStringBetweenDelimiters "$toolData" "<sha512>" "</sha512>")"
|
|
|
|
if ! [ -e "$downloadPath" ]; then
|
|
|
|
echo "Downloading $tool..."
|
|
|
|
vcpkgDownloadFile $url "$downloadPath" $sha512
|
|
|
|
echo "Downloading $tool... done."
|
|
|
|
else
|
|
|
|
vcpkgCheckEqualFileHash $url "$downloadPath" $sha512
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $isArchive = true ]; then
|
|
|
|
echo "Extracting $tool..."
|
|
|
|
vcpkgExtractArchive "$downloadPath" "$toolPath"
|
|
|
|
echo "Extracting $tool... done."
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -e "$exePath" ]; then
|
|
|
|
echo "Could not detect or download $tool"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
eval $__output="'$exePath'"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
selectCXX()
|
|
|
|
{
|
|
|
|
__output=$1
|
|
|
|
|
|
|
|
if [ "x$CXX" = "x" ]; then
|
|
|
|
CXX=g++
|
2018-05-16 11:57:10 +08:00
|
|
|
if which g++-8 >/dev/null 2>&1; then
|
|
|
|
CXX=g++-8
|
|
|
|
elif which g++-7 >/dev/null 2>&1; then
|
2018-03-27 18:03:26 +08:00
|
|
|
CXX=g++-7
|
|
|
|
elif which g++-6 >/dev/null 2>&1; then
|
|
|
|
CXX=g++-6
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
gccversion="$("$CXX" -v 2>&1)"
|
|
|
|
gccversion="$(extractStringBetweenDelimiters "$gccversion" "gcc version " ".")"
|
2018-04-27 23:14:47 +08:00
|
|
|
if [ "$gccversion" -lt "6" ]; then
|
2018-03-27 18:03:26 +08:00
|
|
|
echo "CXX ($CXX) is too old; please install a newer compiler such as g++-7."
|
2018-12-11 18:12:21 +08:00
|
|
|
echo "On Ubuntu try the following:"
|
2018-12-12 02:15:44 +08:00
|
|
|
echo " sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y"
|
|
|
|
echo " sudo apt-get update -y"
|
|
|
|
echo " sudo apt-get install g++-7 -y"
|
2018-12-11 15:30:37 +08:00
|
|
|
echo "On CentOS try the following:"
|
2018-12-12 02:15:44 +08:00
|
|
|
echo " sudo yum install centos-release-scl"
|
|
|
|
echo " sudo yum install devtoolset-7"
|
|
|
|
echo " scl enable devtoolset-7 bash"
|
2018-03-27 18:03:26 +08:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
eval $__output="'$CXX'"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Preparation
|
|
|
|
UNAME="$(uname)"
|
2018-12-12 02:15:44 +08:00
|
|
|
|
|
|
|
if $vcpkgUseSystem; then
|
|
|
|
cmakeExe="cmake"
|
|
|
|
ninjaExe="ninja"
|
|
|
|
else
|
|
|
|
fetchTool "cmake" "$UNAME" cmakeExe || exit 1
|
|
|
|
fetchTool "ninja" "$UNAME" ninjaExe || exit 1
|
|
|
|
fi
|
2018-03-27 18:03:26 +08:00
|
|
|
selectCXX CXX || exit 1
|
|
|
|
|
|
|
|
# Do the build
|
|
|
|
buildDir="$vcpkgRootDir/toolsrc/build.rel"
|
|
|
|
rm -rf "$buildDir"
|
|
|
|
mkdir -p "$buildDir"
|
|
|
|
|
2019-04-11 15:32:03 +08:00
|
|
|
(cd "$buildDir" && CXX=$CXX "$cmakeExe" .. -DCMAKE_BUILD_TYPE=Release -G "Ninja" "-DCMAKE_MAKE_PROGRAM=$ninjaExe" "-DDEFINE_DISABLE_METRICS=$vcpkgDisableMetrics" "-DVCPKG_ALLOW_APPLE_CLANG=$vcpkgAllowAppleClang") || exit 1
|
2019-03-20 07:32:24 +08:00
|
|
|
(cd "$buildDir" && "$cmakeExe" --build .) || exit 1
|
2018-03-27 18:03:26 +08:00
|
|
|
|
|
|
|
rm -rf "$vcpkgRootDir/vcpkg"
|
2018-04-26 10:11:04 +08:00
|
|
|
cp "$buildDir/vcpkg" "$vcpkgRootDir/"
|