Path: blob/main/contrib/jemalloc/scripts/windows/before_install.sh
39535 views
#!/bin/bash12set -e34# The purpose of this script is to install build dependencies and set5# $build_env to a function that sets appropriate environment variables,6# to enable (mingw32|mingw64) environment if we want to compile with gcc, or7# (mingw32|mingw64) + vcvarsall.bat if we want to compile with cl.exe89if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then10echo "Incorrect \$TRAVIS_OS_NAME: expected windows, got $TRAVIS_OS_NAME"11exit 112fi1314[[ ! -f C:/tools/msys64/msys2_shell.cmd ]] && rm -rf C:/tools/msys6415choco uninstall -y mingw16choco upgrade --no-progress -y msys21718msys_shell_cmd="cmd //C RefreshEnv.cmd && set MSYS=winsymlinks:nativestrict && C:\\tools\\msys64\\msys2_shell.cmd"1920msys2() { $msys_shell_cmd -defterm -no-start -msys2 -c "$*"; }21mingw32() { $msys_shell_cmd -defterm -no-start -mingw32 -c "$*"; }22mingw64() { $msys_shell_cmd -defterm -no-start -mingw64 -c "$*"; }2324if [[ "$CROSS_COMPILE_32BIT" == "yes" ]]; then25mingw=mingw3226mingw_gcc_package_arch=i68627else28mingw=mingw6429mingw_gcc_package_arch=x86_6430fi3132if [[ "$CC" == *"gcc"* ]]; then33$mingw pacman -S --noconfirm --needed \34autotools \35git \36mingw-w64-${mingw_gcc_package_arch}-make \37mingw-w64-${mingw_gcc_package_arch}-gcc \38mingw-w64-${mingw_gcc_package_arch}-binutils39build_env=$mingw40elif [[ "$CC" == *"cl"* ]]; then41$mingw pacman -S --noconfirm --needed \42autotools \43git \44mingw-w64-${mingw_gcc_package_arch}-make \45mingw-w64-${mingw_gcc_package_arch}-binutils4647# In order to use MSVC compiler (cl.exe), we need to correctly set some environment48# variables, namely PATH, INCLUDE, LIB and LIBPATH. The correct values of these49# variables are set by a batch script "vcvarsall.bat". The code below generates50# a batch script that calls "vcvarsall.bat" and prints the environment variables.51#52# Then, those environment variables are transformed from cmd to bash format and put53# into a script $apply_vsenv. If cl.exe needs to be used from bash, one can54# 'source $apply_vsenv' and it will apply the environment variables needed for cl.exe55# to be located and function correctly.56#57# At last, a function "mingw_with_msvc_vars" is generated which forwards user input58# into a correct mingw (32 or 64) subshell that automatically performs 'source $apply_vsenv',59# making it possible for autotools to discover and use cl.exe.60vcvarsall="vcvarsall.tmp.bat"61echo "@echo off" > $vcvarsall62echo "call \"c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\\\vcvarsall.bat\" $USE_MSVC" >> $vcvarsall63echo "set" >> $vcvarsall6465apply_vsenv="./apply_vsenv.sh"66cmd //C $vcvarsall | grep -E "^PATH=" | sed -n -e 's/\(.*\)=\(.*\)/export \1=$PATH:"\2"/g' \67-e 's/\([a-zA-Z]\):[\\\/]/\/\1\//g' \68-e 's/\\/\//g' \69-e 's/;\//:\//gp' > $apply_vsenv70cmd //C $vcvarsall | grep -E "^(INCLUDE|LIB|LIBPATH)=" | sed -n -e 's/\(.*\)=\(.*\)/export \1="\2"/gp' >> $apply_vsenv7172cat $apply_vsenv73mingw_with_msvc_vars() { $msys_shell_cmd -defterm -no-start -$mingw -c "source $apply_vsenv && ""$*"; }74build_env=mingw_with_msvc_vars7576rm -f $vcvarsall77else78echo "Unknown C compiler: $CC"79exit 180fi8182echo "Build environment function: $build_env"838485