首页 > 其他分享 >魔改的vcpkg编译脚本

魔改的vcpkg编译脚本

时间:2023-10-04 18:34:18浏览次数:51  
标签:elif 魔改 echo 编译 vcpkg vcpkgRootDir fi VCPKG

`bash

!/bin/sh

Find .vcpkg-root.

vcpkgRootDir=$(X= cd -- "$(dirname -- "$0")" && pwd -P)
while [ "$vcpkgRootDir" != "/" ] && ! [ -e "$vcpkgRootDir/.vcpkg-root" ]; do
vcpkgRootDir="$(dirname "$vcpkgRootDir")"
done

Parse arguments.

vcpkgDisableMetrics="OFF"
vcpkgUseSystem=false
vcpkgUseMuslC="OFF"
for var in "$@"
do
if [ "$var" = "-disableMetrics" -o "$var" = "--disableMetrics" ]; then
vcpkgDisableMetrics="ON"
elif [ "$var" = "-useSystemBinaries" -o "$var" = "--useSystemBinaries" ]; then
echo "Warning: -useSystemBinaries no longer has any effect; ignored. Note that the VCPKG_USE_SYSTEM_BINARIES environment variable behavior is not changed."
elif [ "$var" = "-allowAppleClang" -o "$var" = "--allowAppleClang" ]; then
echo "Warning: -allowAppleClang no longer has any effect; ignored."
elif [ "$var" = "-buildTests" ]; then
echo "Warning: -buildTests no longer has any effect; ignored."
elif [ "$var" = "-musl" ]; then
vcpkgUseMuslC="ON"
elif [ "$var" = "-help" -o "$var" = "--help" ]; then
echo "Usage: ./bootstrap-vcpkg.sh [options]"
echo
echo "Options:"
echo " -help Display usage help"
echo " -disableMetrics Mark this vcpkg root to disable metrics."
echo " -musl Use the musl binary rather than the glibc binary on Linux."
exit 1
else
echo "Unknown argument $var. Use '-help' for help."
exit 1
fi
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
if [ "$vcpkgDisableMetrics" = "ON" ]; then
args="-disableMetrics"
else
args=""
fi

vcpkgRootDir=$(cygpath -aw "$vcpkgRootDir")
cmd "/C $vcpkgRootDir\\bootstrap-vcpkg.bat $args" || exit 1
exit 0

fi

Determine the downloads directory.

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

Check for minimal prerequisites.

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 "On Debian and Ubuntu derivatives:"
echo " sudo apt-get install curl zip unzip tar"
echo "On recent Red Hat and Fedora derivatives:"
echo " sudo dnf install curl zip unzip tar"
echo "On older Red Hat and Fedora derivatives:"
echo " sudo yum install curl zip unzip tar"
echo "On SUSE Linux and derivatives:"
echo " sudo zypper install curl zip unzip tar"
echo "On Arch Linux and derivatives:"
echo " sudo pacman -S curl zip unzip tar cmake ninja"
echo "On Alpine:"
echo " apk add build-base cmake ninja zip unzip curl git"
echo " (and export VCPKG_FORCE_SYSTEM_BINARIES=1)"
exit 1
fi
}

vcpkgCheckRepoTool curl
vcpkgCheckRepoTool zip
vcpkgCheckRepoTool unzip
vcpkgCheckRepoTool tar

UNAME="$(uname)"
ARCH="$(uname -m)"

if [ -e /etc/alpine-release ]; then
vcpkgUseSystem="ON"
if [ "$ARCH" = "x86_64" ]; then
vcpkgUseMuslC="ON"
fi
fi

if [ "$UNAME" = "OpenBSD" ]; then
vcpkgUseSystem="ON"

if [ -z "$CXX" ]; then
    CXX=/usr/bin/clang++
fi
if [ -z "$CC" ]; then
    CC=/usr/bin/clang
fi

fi

if [ "$vcpkgUseSystem" = "ON" ]; then
vcpkgCheckRepoTool cmake
vcpkgCheckRepoTool ninja
vcpkgCheckRepoTool git
vcpkgCheckRepoTool gcc
fi

vcpkgCheckEqualFileHash()
{
url=$1; filePath=$2; expectedHash=$3

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")
fi

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 ]"
    exit 1
fi

}

vcpkgDownloadFile()
{
url=$1; downloadPath=$2 sha512=$3
rm -rf "$downloadPath.part"
curl -L $url --tlsv1.2 --create-dirs --retry 3 --output "$downloadPath.part" --silent --show-error --fail || exit 1

vcpkgCheckEqualFileHash $url "$downloadPath.part" $sha512
chmod +x "$downloadPath.part"
mv "$downloadPath.part" "$downloadPath"

}

vcpkgExtractTar()
{
archive=$1; toPath=$2
rm -rf "$toPath" "$toPath.partial"
mkdir -p "$toPath.partial"
$(cd "$toPath.partial" && tar xzf "$archive")
mv "$toPath.partial" "$toPath"
}

Determine what we are going to do to bootstrap:

MacOS -> Download vcpkg-macos

Linux

useMuslC -> download vcpkg-muslc

amd64 -> download vcpkg-glibc

Otherwise

Download and build from source

Read the vcpkg-tool config file to determine what release to download

. "$vcpkgRootDir/scripts/vcpkg-tool-metadata.txt"

vcpkgDownloadTool="OFF"
if [ "$UNAME" = "Darwin" ]; then
echo "Downloading vcpkg-macos..."
vcpkgToolReleaseSha=$VCPKG_MACOS_SHA
vcpkgToolName="vcpkg-macos"
elif [ "$vcpkgUseMuslC" = "ON" ]; then
echo "Downloading vcpkg-muslc..."
vcpkgToolReleaseSha=$VCPKG_MUSLC_SHA
vcpkgToolName="vcpkg-muslc"
elif [ "$ARCH" = "x86_64" ]; then
echo "Downloading vcpkg-glibc..."
vcpkgToolReleaseSha=$VCPKG_GLIBC_SHA
vcpkgToolName="vcpkg-glibc"
else
echo "Unable to determine a binary release of vcpkg; attempting to build from source."
vcpkgDownloadTool="OFF"
vcpkgToolReleaseSha=$VCPKG_TOOL_SOURCE_SHA
fi

Do the download or build.

if [ "$vcpkgDownloadTool" = "ON" ]; then
vcpkgDownloadFile "https://github.com/microsoft/vcpkg-tool/releases/download/$VCPKG_TOOL_RELEASE_TAG/$vcpkgToolName" "$vcpkgRootDir/vcpkg" $vcpkgToolReleaseSha
else
if [ "x$CXX" = "x" ]; then
if which g++-12 >/dev/null 2>&1; then
CXX=g++-12
elif which g++-11 >/dev/null 2>&1; then
CXX=g++-11
elif which g++-10 >/dev/null 2>&1; then
CXX=g++-10
elif which g++-9 >/dev/null 2>&1; then
CXX=g++-9
elif which g++-8 >/dev/null 2>&1; then
CXX=g++-8
elif which g++-7 >/dev/null 2>&1; then
CXX=g++-7
elif which g++-6 >/dev/null 2>&1; then
CXX=g++-6
elif which g++ >/dev/null 2>&1; then
CXX=g++
fi
# If we can't find g++, allow CMake to do the look-up
fi

vcpkgToolReleaseTarball="vcpkg-tool-2023-08-09.tar.gz"
vcpkgToolUrl="https://github.com/microsoft/vcpkg-tool/archive/$vcpkgToolReleaseTarball"
baseBuildDir="$vcpkgRootDir/buildtrees/_vcpkg"
buildDir="$baseBuildDir/build"
tarballPath="$downloadsDir/$vcpkgToolReleaseTarball"
srcBaseDir="$baseBuildDir/src"
srcDir="$srcBaseDir/vcpkg-tool-$VCPKG_TOOL_RELEASE_TAG"

echo "Building vcpkg-tool..."
rm -rf "$baseBuildDir"
mkdir -p "$buildDir"
vcpkgExtractTar "$tarballPath" "$srcBaseDir"
cmakeConfigOptions="-DCMAKE_BUILD_TYPE=Release -G 'Ninja' -DVCPKG_DEVELOPMENT_WARNINGS=OFF"

if [ "${VCPKG_MAX_CONCURRENCY}" != "" ] ; then
    cmakeConfigOptions=" $cmakeConfigOptions '-DCMAKE_JOB_POOL_COMPILE:STRING=compile' '-DCMAKE_JOB_POOL_LINK:STRING=link' '-DCMAKE_JOB_POOLS:STRING=compile=$VCPKG_MAX_CONCURRENCY;link=$VCPKG_MAX_CONCURRENCY' "
fi

(cd "$buildDir" && CXX="$CXX" eval cmake "$srcDir" $cmakeConfigOptions) || exit 1
(cd "$buildDir" && cmake --build .) || exit 1

rm -rf "$vcpkgRootDir/vcpkg"
cp "$buildDir/vcpkg" "$vcpkgRootDir/"

fi

"$vcpkgRootDir/vcpkg" version

Apply the disable-metrics marker file.

if [ "$vcpkgDisableMetrics" = "ON" ]; then
touch "$vcpkgRootDir/vcpkg.disable-metrics"
elif ! [ -f "$vcpkgRootDir/vcpkg.disable-metrics" ]; then
# Note that we intentionally leave any existing vcpkg.disable-metrics; once a user has
# opted out they should stay opted out.
cat <<EOF
Telemetry

vcpkg collects usage data in order to help us improve your experience.
The data collected by Microsoft is anonymous.
You can opt-out of telemetry by re-running the bootstrap-vcpkg script with -disableMetrics,
passing --disable-metrics to vcpkg on the command line,
or by setting the VCPKG_DISABLE_METRICS environment variable.

Read more about vcpkg telemetry at docs/about/privacy.md
EOF
fi

`

标签:elif,魔改,echo,编译,vcpkg,vcpkgRootDir,fi,VCPKG
From: https://www.cnblogs.com/huangshiyi/p/17742550.html

相关文章

  • [CPP] CPP的编译链接过程
    手写的源代码本质上只是一串文本,但是在编译器里点一下编译就可以直接看到程序的输出,从文本到执行输出之间发生了什么 源代码到可执行程序大致经历以下几个过程         1、预编译(Preprocessing)预编译阶段主要做四件事:头文件展开,宏替换,执行预编译......
  • 解决交叉编译产生的程序放到目标板上运行时出现Segmentation fault (core dumped)
    原文:https://blog.csdn.net/qq_36219010/article/details/100163134在PC机上编译一段程序:arm-linux-gnueabihf-gcc-ohellohello.c这里产生hello文件用FTP传输到目标板上(树莓派3B+),运行时出现:报告段错误。后来我又试了不输出指定的文件名:arm-linux-gnueabihf-gcchello.c......
  • dpdk 编译
     引用: https://zhuanlan.zhihu.com/p/56670068720.11版本 DPDK(DataPlaneDevelopmentKit)是数据平面开发工具包,由用于加速在各种CPU架构上运行的数据包处理的库组成。DPDK需要一定的网卡硬件支持,以Intel为例,支持以下网卡: 下面带大家过一遍编译流程,扫清后续应用的......
  • CSS预编译:提升样式开发效率与可维护性的关键工具
    ......
  • 【TypeScript学习】—编译选项(三)
    【TypeScript学习】—编译选项(三)一、自动编译文件tscxxx.ts-w二、自动编译整个项目三、编译器选项......
  • Android 编译和使用libpng
    libpnglibpngistheofficialPNGreferencelibrary.ItsupportsalmostallPNGfeatures,isextensible,andhasbeenextensivelytestedforover28years.Thehomesitefordevelopmentversions(i.e.,maybebuggyorsubjecttochangeorincludeexperimen......
  • lapce源码学习-编译调试
    master分支调试1、报错:`#![feature]`maynotbeusedonthestablereleasechannel2、Channel切换到nightly,报错:thetraitbound`file_type::FileType:std::sealed::Sealed`isnotsatisfied3、Channel切换到beta,编译ok,但提示不能调试rustupinstallbeta4、编译成功后,......
  • 点播模块编译nginx
    VOD模块NGINX编译部署主要解决我那破电视的观影需求、软件装不了又不想掏钱看线上广告;U盘也没法播、没几个兼容的解码软件,五六年前的电视买的是真坑爹,我又不会刷机,那索性用废笔记本装linux整个nginx-vod模块整个音视频链接,电视上用短小精悍的VLC观影。下包mkdir/usr/local/n......
  • 【rk356x】Linux Cmake如何进行交叉编译
    compiler.arm.cmakeSET(GCC_PATH/work/xxx/buildroot/output/rockchip/host/bin)SET(toolpathprefix${GCC_PATH}/aarch64-buildroot-linux-gnu-)set(libusb_path/work/xxx/libusb/install/lib/pkgconfig/libusb-1.0.pc)SET(CMAKE_C_COMPILER${toolpathprefix}gcc)SET......
  • 【X3m】opencv和opencv_contrib交叉编译
    opencv和contrib版本必须要一直,否则可以编译不匹配opencv4-4.5.4.tar.gzopencv4-contrib-4.5.5.tar.gzopencv交叉编译命令,主要eigen3的地址cmake\-DCMAKE_BUILD_TYPE=Release\-DCMAKE_INSTALL_PREFIX=../install\-DBUILD_PNG=ON\-DBUILD_TIFF=ON\......