1 #
   2 # Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 ################################################################################
  27 # The order of these defines the priority by which we try to find them.
  28 VALID_VS_VERSIONS="2019 2017"
  29 
  30 VS_DESCRIPTION_2017="Microsoft Visual Studio 2017"
  31 VS_VERSION_INTERNAL_2017=141
  32 VS_MSVCR_2017=vcruntime140.dll
  33 VS_MSVCP_2017=msvcp140.dll
  34 VS_ENVVAR_2017="VS150COMNTOOLS"
  35 VS_USE_UCRT_2017="true"
  36 VS_VS_INSTALLDIR_2017="Microsoft Visual Studio/2017"
  37 VS_EDITIONS_2017="BuildTools Community Professional Enterprise"
  38 VS_SDK_INSTALLDIR_2017=
  39 VS_VS_PLATFORM_NAME_2017="v141"
  40 VS_SDK_PLATFORM_NAME_2017=
  41 VS_SUPPORTED_2017=true
  42 VS_TOOLSET_SUPPORTED_2017=true
  43 
  44 VS_DESCRIPTION_2019="Microsoft Visual Studio 2019"
  45 VS_VERSION_INTERNAL_2019=142
  46 VS_MSVCR_2019=vcruntime140.dll
  47 VS_VCRUNTIME_1_2019=vcruntime140_1.dll
  48 VS_MSVCP_2019=msvcp140.dll
  49 VS_ENVVAR_2019="VS160COMNTOOLS"
  50 VS_USE_UCRT_2019="true"
  51 VS_VS_INSTALLDIR_2019="Microsoft Visual Studio/2019"
  52 VS_EDITIONS_2019="BuildTools Community Professional Enterprise"
  53 VS_SDK_INSTALLDIR_2019=
  54 VS_VS_PLATFORM_NAME_2019="v142"
  55 VS_SDK_PLATFORM_NAME_2019=
  56 VS_SUPPORTED_2019=true
  57 VS_TOOLSET_SUPPORTED_2019=true
  58 
  59 ################################################################################
  60 
  61 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT],
  62 [
  63   if test "x$VS_ENV_CMD" = x; then
  64     VS_VERSION="$1"
  65     VS_BASE="$2"
  66     METHOD="$3"
  67 
  68     UTIL_REWRITE_AS_UNIX_PATH(VS_BASE)
  69     # In VS 2017 and VS 2019, the default installation is in a subdir named after the edition.
  70     # Find the first one present and use that.
  71     if test "x$VS_EDITIONS" != x; then
  72       for edition in $VS_EDITIONS; do
  73         if test -d "$VS_BASE/$edition"; then
  74           VS_BASE="$VS_BASE/$edition"
  75           break
  76         fi
  77       done
  78     fi
  79 
  80     if test -d "$VS_BASE"; then
  81       AC_MSG_NOTICE([Found Visual Studio installation at $VS_BASE using $METHOD])
  82       if test "x$OPENJDK_TARGET_CPU" = xx86; then
  83         VCVARSFILES="vc/bin/vcvars32.bat vc/auxiliary/build/vcvars32.bat"
  84       elif test "x$OPENJDK_TARGET_CPU" = xx86_64; then
  85         VCVARSFILES="vc/bin/amd64/vcvars64.bat vc/bin/x86_amd64/vcvarsx86_amd64.bat \
  86             VC/Auxiliary/Build/vcvarsx86_amd64.bat VC/Auxiliary/Build/vcvars64.bat"
  87       elif test "x$OPENJDK_TARGET_CPU" = xaarch64; then
  88         # for host x86-64, target aarch64
  89         VCVARSFILES="vc/auxiliary/build/vcvarsamd64_arm64.bat \
  90             vc/auxiliary/build/vcvarsx86_arm64.bat"
  91       fi
  92 
  93       for VCVARSFILE in $VCVARSFILES; do
  94         if test -f "$VS_BASE/$VCVARSFILE"; then
  95           VS_ENV_CMD="$VS_BASE/$VCVARSFILE"
  96           break
  97         fi
  98       done
  99 
 100       if test "x$VS_ENV_CMD" = x; then
 101         AC_MSG_NOTICE([Warning: None of $VCVARSFILES were found, Visual Studio installation not recognized. Ignoring])
 102       else
 103         # PLATFORM_TOOLSET is used during the compilation of the freetype sources
 104         # (see 'LIB_BUILD_FREETYPE' in libraries.m4) and must be one of 'v100',
 105         # 'v110' or 'v120' for VS 2010, 2012 or VS2013
 106         eval PLATFORM_TOOLSET="\${VS_VS_PLATFORM_NAME_${VS_VERSION}}"
 107       fi
 108     fi
 109   fi
 110 ])
 111 
 112 ################################################################################
 113 
 114 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT],
 115 [
 116   if test "x$VS_ENV_CMD" = x; then
 117     VS_VERSION="$1"
 118     WIN_SDK_BASE="$2"
 119     METHOD="$3"
 120     UTIL_REWRITE_AS_UNIX_PATH(WIN_SDK_BASE)
 121     if test -d "$WIN_SDK_BASE"; then
 122       # There have been cases of partial or broken SDK installations. A missing
 123       # lib dir is not going to work.
 124       if test ! -d "$WIN_SDK_BASE/lib"; then
 125         AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
 126         AC_MSG_NOTICE([Warning: Installation is broken, lib dir is missing. Ignoring])
 127       elif test -f "$WIN_SDK_BASE/Bin/SetEnv.Cmd"; then
 128         AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
 129         VS_ENV_CMD="$WIN_SDK_BASE/Bin/SetEnv.Cmd"
 130         if test "x$OPENJDK_TARGET_CPU" = xx86; then
 131           VS_ENV_ARGS="/x86"
 132         elif test "x$OPENJDK_TARGET_CPU" = xx86_64; then
 133           VS_ENV_ARGS="/x64"
 134         elif test "x$OPENJDK_TARGET_CPU" = xaarch64; then
 135           VS_ENV_ARGS="/arm64"
 136         fi
 137         # PLATFORM_TOOLSET is used during the compilation of the freetype sources (see
 138         # 'LIB_BUILD_FREETYPE' in libraries.m4) and must be 'Windows7.1SDK' for Windows7.1SDK
 139         # TODO: improve detection for other versions of SDK
 140         eval PLATFORM_TOOLSET="\${VS_SDK_PLATFORM_NAME_${VS_VERSION}}"
 141       else
 142         AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
 143         AC_MSG_NOTICE([Warning: Installation is broken, SetEnv.Cmd is missing. Ignoring])
 144       fi
 145     fi
 146   fi
 147 ])
 148 
 149 ################################################################################
 150 # Finds the bat or cmd file in Visual Studio or the SDK that sets up a proper
 151 # build environment and assigns it to VS_ENV_CMD
 152 AC_DEFUN([TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE],
 153 [
 154   # VS2017 provides the option to install previous minor versions of the MSVC
 155   # toolsets. It is not possible to directly download earlier minor versions of
 156   # VS2017 and in order to build with a previous minor compiler toolset version,
 157   # it is now possible to compile with earlier minor versions by passing
 158   # -vcvars_ver=<toolset_version> argument to vcvarsall.bat.
 159   AC_ARG_WITH(msvc-toolset-version, [AS_HELP_STRING([--with-msvc-toolset-version],
 160       [specific MSVC toolset version to use, passed as -vcvars_ver argument to
 161        pass to vcvarsall.bat (Windows only)])])
 162 
 163   VS_VERSION="$1"
 164   eval VS_COMNTOOLS_VAR="\${VS_ENVVAR_${VS_VERSION}}"
 165   eval VS_COMNTOOLS="\$${VS_COMNTOOLS_VAR}"
 166   eval VS_INSTALL_DIR="\${VS_VS_INSTALLDIR_${VS_VERSION}}"
 167   eval VS_EDITIONS="\${VS_EDITIONS_${VS_VERSION}}"
 168   eval SDK_INSTALL_DIR="\${VS_SDK_INSTALLDIR_${VS_VERSION}}"
 169   eval VS_ENV_ARGS="\${VS_ENV_ARGS_${VS_VERSION}}"
 170   eval VS_TOOLSET_SUPPORTED="\${VS_TOOLSET_SUPPORTED_${VS_VERSION}}"
 171 
 172   VS_ENV_CMD=""
 173 
 174   # When using --with-tools-dir, assume it points to the correct and default
 175   # version of Visual Studio or that --with-toolchain-version was also set.
 176   if test "x$with_tools_dir" != x; then
 177     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 178         [$with_tools_dir/../..], [--with-tools-dir])
 179     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 180         [$with_tools_dir/../../..], [--with-tools-dir])
 181     if test "x$VS_ENV_CMD" = x; then
 182       # Having specified an argument which is incorrect will produce an instant failure;
 183       # we should not go on looking
 184       AC_MSG_NOTICE([The path given by --with-tools-dir does not contain a valid])
 185       AC_MSG_NOTICE([Visual Studio installation. Please point to the VC/bin or VC/bin/amd64])
 186       AC_MSG_NOTICE([directory within the Visual Studio installation])
 187       AC_MSG_ERROR([Cannot locate a valid Visual Studio installation])
 188     fi
 189   fi
 190 
 191   if test "x$VS_COMNTOOLS" != x; then
 192     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 193         [$VS_COMNTOOLS/../..], [$VS_COMNTOOLS_VAR variable])
 194   fi
 195   if test "x$PROGRAMFILES" != x; then
 196     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 197         [$PROGRAMFILES/$VS_INSTALL_DIR], [well-known name])
 198   fi
 199   # Work around the insanely named ProgramFiles(x86) env variable
 200   PROGRAMFILES_X86="`env | $SED -n 's/^ProgramFiles(x86)=//p'`"
 201   if test "x$PROGRAMFILES_X86" != x; then
 202     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 203         [$PROGRAMFILES_X86/$VS_INSTALL_DIR], [well-known name])
 204   fi
 205   TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 206       [C:/Program Files/$VS_INSTALL_DIR], [well-known name])
 207   TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 208       [C:/Program Files (x86)/$VS_INSTALL_DIR], [well-known name])
 209   if test "x$SDK_INSTALL_DIR" != x; then
 210     if test "x$ProgramW6432" != x; then
 211       TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 212           [$ProgramW6432/$SDK_INSTALL_DIR], [well-known name])
 213     fi
 214     if test "x$PROGRAMW6432" != x; then
 215       TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 216           [$PROGRAMW6432/$SDK_INSTALL_DIR], [well-known name])
 217     fi
 218     if test "x$PROGRAMFILES" != x; then
 219       TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 220           [$PROGRAMFILES/$SDK_INSTALL_DIR], [well-known name])
 221     fi
 222     TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 223         [C:/Program Files/$SDK_INSTALL_DIR], [well-known name])
 224     TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 225         [C:/Program Files (x86)/$SDK_INSTALL_DIR], [well-known name])
 226   fi
 227 
 228   if test "x$VS_TOOLSET_SUPPORTED" != x; then
 229     if test "x$with_msvc_toolset_version" != x; then
 230       VS_ENV_ARGS="$VS_ENV_ARGS -vcvars_ver=$with_msvc_toolset_version"
 231     fi
 232   fi
 233 ])
 234 
 235 ################################################################################
 236 
 237 AC_DEFUN([TOOLCHAIN_FIND_VISUAL_STUDIO],
 238 [
 239   AC_ARG_WITH(toolchain-version, [AS_HELP_STRING([--with-toolchain-version],
 240       [the version of the toolchain to look for, use '--help' to show possible values @<:@platform dependent@:>@])])
 241 
 242   if test "x$with_toolchain_version" = xlist; then
 243     # List all toolchains
 244     AC_MSG_NOTICE([The following toolchain versions are valid on this platform:])
 245     for version in $VALID_VS_VERSIONS; do
 246       eval VS_DESCRIPTION=\${VS_DESCRIPTION_$version}
 247       $PRINTF "  %-10s  %s\n" $version "$VS_DESCRIPTION"
 248     done
 249 
 250     exit 0
 251   elif test "x$DEVKIT_VS_VERSION" != x; then
 252     VS_VERSION=$DEVKIT_VS_VERSION
 253     TOOLCHAIN_VERSION=$VS_VERSION
 254     # If the devkit has a name, use that as description
 255     VS_DESCRIPTION="$DEVKIT_NAME"
 256     if test "x$VS_DESCRIPTION" = x; then
 257       eval VS_DESCRIPTION="\${VS_DESCRIPTION_${VS_VERSION}}"
 258     fi
 259     eval VS_VERSION_INTERNAL="\${VS_VERSION_INTERNAL_${VS_VERSION}}"
 260     eval MSVCR_NAME="\${VS_MSVCR_${VS_VERSION}}"
 261     eval VCRUNTIME_1_NAME="\${VS_VCRUNTIME_1_${VS_VERSION}}"
 262     eval MSVCP_NAME="\${VS_MSVCP_${VS_VERSION}}"
 263     eval USE_UCRT="\${VS_USE_UCRT_${VS_VERSION}}"
 264     eval VS_SUPPORTED="\${VS_SUPPORTED_${VS_VERSION}}"
 265     eval PLATFORM_TOOLSET="\${VS_VS_PLATFORM_NAME_${VS_VERSION}}"
 266 
 267     # The TOOLCHAIN_PATH from a devkit is in Unix format. In WSL we need a
 268     # windows version of the complete VS_PATH as VS_PATH_WINDOWS
 269     if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
 270       # Convert the toolchain path
 271       OLDIFS="$IFS"
 272       IFS=":"
 273       VS_PATH_WINDOWS=""
 274       for i in $TOOLCHAIN_PATH; do
 275         path=$i
 276         UTIL_REWRITE_AS_WINDOWS_MIXED_PATH([path])
 277         VS_PATH_WINDOWS="$VS_PATH_WINDOWS;$path"
 278       done
 279       IFS="$OLDIFS"
 280       # Append the current path from Windows env
 281       WINDOWS_PATH="`$CMD /c echo %PATH%`"
 282       VS_PATH_WINDOWS="$VS_PATH_WINDOWS;$WINDOWS_PATH"
 283     else
 284       VS_PATH="$TOOLCHAIN_PATH:$PATH"
 285     fi
 286 
 287     # Convert DEVKIT_VS_INCLUDE into windows style VS_INCLUDE so that it
 288     # can still be exported as INCLUDE for compiler invocations without
 289     # SYSROOT_CFLAGS
 290     OLDIFS="$IFS"
 291     IFS=";"
 292     for i in $DEVKIT_VS_INCLUDE; do
 293       ipath=$i
 294       UTIL_REWRITE_AS_WINDOWS_MIXED_PATH([ipath])
 295       VS_INCLUDE="$VS_INCLUDE;$ipath"
 296     done
 297     # Convert DEVKIT_VS_LIB into VS_LIB so that it can still be exported
 298     # as LIB for compiler invocations without SYSROOT_LDFLAGS
 299     for i in $DEVKIT_VS_LIB; do
 300       libpath=$i
 301       UTIL_REWRITE_AS_WINDOWS_MIXED_PATH([libpath])
 302       VS_LIB="$VS_LIB;$libpath"
 303     done
 304     IFS="$OLDIFS"
 305 
 306     AC_MSG_NOTICE([Found devkit $VS_DESCRIPTION])
 307 
 308   elif test "x$with_toolchain_version" != x; then
 309     # User override; check that it is valid
 310     if test "x${VALID_VS_VERSIONS/$with_toolchain_version/}" = "x${VALID_VS_VERSIONS}"; then
 311       AC_MSG_NOTICE([Visual Studio version $with_toolchain_version is not valid.])
 312       AC_MSG_NOTICE([Valid Visual Studio versions: $VALID_VS_VERSIONS.])
 313       AC_MSG_ERROR([Cannot continue.])
 314     fi
 315     VS_VERSIONS_PROBE_LIST="$with_toolchain_version"
 316   else
 317     # No flag given, use default
 318     VS_VERSIONS_PROBE_LIST="$VALID_VS_VERSIONS"
 319   fi
 320 
 321   for VS_VERSION in $VS_VERSIONS_PROBE_LIST; do
 322     TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE([$VS_VERSION])
 323     if test "x$VS_ENV_CMD" != x; then
 324       TOOLCHAIN_VERSION=$VS_VERSION
 325       eval VS_DESCRIPTION="\${VS_DESCRIPTION_${VS_VERSION}}"
 326       eval VS_VERSION_INTERNAL="\${VS_VERSION_INTERNAL_${VS_VERSION}}"
 327       eval MSVCR_NAME="\${VS_MSVCR_${VS_VERSION}}"
 328       eval VCRUNTIME_1_NAME="\${VS_VCRUNTIME_1_${VS_VERSION}}"
 329       eval MSVCP_NAME="\${VS_MSVCP_${VS_VERSION}}"
 330       eval USE_UCRT="\${VS_USE_UCRT_${VS_VERSION}}"
 331       eval VS_SUPPORTED="\${VS_SUPPORTED_${VS_VERSION}}"
 332       # The rest of the variables are already evaled while probing
 333       AC_MSG_NOTICE([Found $VS_DESCRIPTION])
 334       break
 335     fi
 336   done
 337 
 338   TOOLCHAIN_DESCRIPTION="$VS_DESCRIPTION"
 339   if test "x$VS_SUPPORTED" = "xfalse"; then
 340     UNSUPPORTED_TOOLCHAIN_VERSION=yes
 341   fi
 342 ])
 343 
 344 ################################################################################
 345 # Check if the VS env variables were setup prior to running configure.
 346 # If not, then find vcvarsall.bat and run it automatically, and integrate
 347 # the set env variables into the spec file.
 348 AC_DEFUN([TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV],
 349 [
 350   # Store path to cygwin link.exe to help excluding it when searching for
 351   # VS linker. This must be done before changing the PATH when looking for VS.
 352   AC_PATH_PROG(CYGWIN_LINK, link.exe)
 353   if test "x$CYGWIN_LINK" != x; then
 354     AC_MSG_CHECKING([if the first found link.exe is actually the Cygwin link tool])
 355     "$CYGWIN_LINK" --version > /dev/null
 356     if test $? -eq 0 ; then
 357       AC_MSG_RESULT([yes])
 358     else
 359       AC_MSG_RESULT([no])
 360       # This might be the VS linker. Don't exclude it later on.
 361       CYGWIN_LINK=""
 362     fi
 363   fi
 364 
 365   # First-hand choice is to locate and run the vsvars bat file.
 366   TOOLCHAIN_FIND_VISUAL_STUDIO
 367 
 368   # If we have a devkit, skip all of the below.
 369   if test "x$DEVKIT_VS_VERSION" = x; then
 370     if test "x$VS_ENV_CMD" != x; then
 371       # We have found a Visual Studio environment on disk, let's extract variables from the vsvars bat file.
 372       UTIL_FIXUP_EXECUTABLE(VS_ENV_CMD)
 373 
 374       # Lets extract the variables that are set by vcvarsall.bat/vsvars32.bat/vsvars64.bat
 375       AC_MSG_NOTICE([Trying to extract Visual Studio environment variables])
 376 
 377       # We need to create a couple of temporary files.
 378       VS_ENV_TMP_DIR="$CONFIGURESUPPORT_OUTPUTDIR/vs-env"
 379       $MKDIR -p $VS_ENV_TMP_DIR
 380 
 381       # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment).
 382       # Instead create a shell script which will set the relevant variables when run.
 383       WINPATH_VS_ENV_CMD="$VS_ENV_CMD"
 384       UTIL_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_VS_ENV_CMD])
 385 
 386       if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
 387         WINPATH_BASH="bash"
 388       else
 389         WINPATH_BASH="$BASH"
 390         UTIL_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_BASH])
 391       fi
 392 
 393       # Generate a DOS batch file which runs $VS_ENV_CMD, and then creates a shell
 394       # script (executable by bash) that will setup the important variables.
 395       EXTRACT_VC_ENV_BAT_FILE="$VS_ENV_TMP_DIR/extract-vs-env.bat"
 396       $ECHO "@echo off" >  $EXTRACT_VC_ENV_BAT_FILE
 397       # This will end up something like:
 398       # call C:/progra~2/micros~2.0/vc/bin/amd64/vcvars64.bat
 399       $ECHO "call \"$WINPATH_VS_ENV_CMD\" $VS_ENV_ARGS" >> $EXTRACT_VC_ENV_BAT_FILE
 400       # In some cases, the VS_ENV_CMD will change directory, change back so
 401       # the set-vs-env.sh ends up in the right place.
 402       $ECHO 'cd %~dp0' >> $EXTRACT_VC_ENV_BAT_FILE
 403       if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
 404         # These will end up something like:
 405         # echo VS_PATH=\"$PATH\" > set-vs-env.sh
 406         # The trailing space for everyone except PATH is no typo, but is needed due
 407         # to trailing \ in the Windows paths. These will be stripped later.
 408         # Trying pure CMD extract. This results in windows paths that need to
 409         # be converted post extraction, but a simpler script.
 410         $ECHO 'echo VS_PATH="%PATH%" > set-vs-env.sh' \
 411             >> $EXTRACT_VC_ENV_BAT_FILE
 412         $ECHO 'echo VS_INCLUDE="%INCLUDE% " >> set-vs-env.sh' \
 413             >> $EXTRACT_VC_ENV_BAT_FILE
 414         $ECHO 'echo VS_LIB="%LIB% " >> set-vs-env.sh' \
 415             >> $EXTRACT_VC_ENV_BAT_FILE
 416         $ECHO 'echo VCINSTALLDIR="%VCINSTALLDIR% " >> set-vs-env.sh' \
 417             >> $EXTRACT_VC_ENV_BAT_FILE
 418         $ECHO 'echo VCToolsRedistDir="%VCToolsRedistDir% " >> set-vs-env.sh' \
 419             >> $EXTRACT_VC_ENV_BAT_FILE
 420         $ECHO 'echo WindowsSdkDir="%WindowsSdkDir% " >> set-vs-env.sh' \
 421             >> $EXTRACT_VC_ENV_BAT_FILE
 422         $ECHO 'echo WINDOWSSDKDIR="%WINDOWSSDKDIR% " >> set-vs-env.sh' \
 423             >> $EXTRACT_VC_ENV_BAT_FILE
 424       else
 425         # These will end up something like:
 426         # C:/CygWin/bin/bash -c 'echo VS_PATH=\"$PATH\" > localdevenv.sh
 427         # The trailing space for everyone except PATH is no typo, but is needed due
 428         # to trailing \ in the Windows paths. These will be stripped later.
 429         $ECHO "$WINPATH_BASH -c 'echo VS_PATH="'\"$PATH\" > set-vs-env.sh' \
 430             >> $EXTRACT_VC_ENV_BAT_FILE
 431         $ECHO "$WINPATH_BASH -c 'echo VS_INCLUDE="'\"$INCLUDE\;$include \" >> set-vs-env.sh' \
 432             >> $EXTRACT_VC_ENV_BAT_FILE
 433         $ECHO "$WINPATH_BASH -c 'echo VS_LIB="'\"$LIB\;$lib \" >> set-vs-env.sh' \
 434             >> $EXTRACT_VC_ENV_BAT_FILE
 435         $ECHO "$WINPATH_BASH -c 'echo VCINSTALLDIR="'\"$VCINSTALLDIR \" >> set-vs-env.sh' \
 436             >> $EXTRACT_VC_ENV_BAT_FILE
 437         $ECHO "$WINPATH_BASH -c 'echo VCToolsRedistDir="'\"$VCToolsRedistDir \" >> set-vs-env.sh' \
 438             >> $EXTRACT_VC_ENV_BAT_FILE
 439         $ECHO "$WINPATH_BASH -c 'echo WindowsSdkDir="'\"$WindowsSdkDir \" >> set-vs-env.sh' \
 440             >> $EXTRACT_VC_ENV_BAT_FILE
 441         $ECHO "$WINPATH_BASH -c 'echo WINDOWSSDKDIR="'\"$WINDOWSSDKDIR \" >> set-vs-env.sh' \
 442             >> $EXTRACT_VC_ENV_BAT_FILE
 443       fi
 444 
 445       # Now execute the newly created bat file.
 446       # Change directory so we don't need to mess with Windows paths in redirects.
 447       cd $VS_ENV_TMP_DIR
 448       $CMD /c extract-vs-env.bat > extract-vs-env.log 2>&1
 449       cd $CONFIGURE_START_DIR
 450 
 451       if test ! -s $VS_ENV_TMP_DIR/set-vs-env.sh; then
 452         AC_MSG_NOTICE([Could not succesfully extract the environment variables needed for the VS setup.])
 453         AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
 454         AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
 455         AC_MSG_ERROR([Cannot continue])
 456       fi
 457 
 458       # Remove windows line endings
 459       $SED -i -e 's|\r||g' $VS_ENV_TMP_DIR/set-vs-env.sh
 460 
 461       # Now set all paths and other env variables. This will allow the rest of
 462       # the configure script to find and run the compiler in the proper way.
 463       AC_MSG_NOTICE([Setting extracted environment variables])
 464       . $VS_ENV_TMP_DIR/set-vs-env.sh
 465       # Now we have VS_PATH, VS_INCLUDE, VS_LIB. For further checking, we
 466       # also define VCINSTALLDIR, WindowsSdkDir and WINDOWSSDKDIR.
 467 
 468       # In WSL, the extracted VS_PATH is Windows style. This needs to be
 469       # rewritten as Unix style and the Windows style version is saved
 470       # in VS_PATH_WINDOWS.
 471       if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
 472         OLDIFS="$IFS"
 473         IFS=";"
 474         # Convert VS_PATH to unix style
 475         VS_PATH_WINDOWS="$VS_PATH"
 476         VS_PATH=""
 477         for i in $VS_PATH_WINDOWS; do
 478           path=$i
 479           # Only process non-empty elements
 480           if test "x$path" != x; then
 481             IFS="$OLDIFS"
 482             # Check that directory exists before calling fixup_path
 483             testpath=$path
 484             UTIL_REWRITE_AS_UNIX_PATH([testpath])
 485             if test -d "$testpath"; then
 486               UTIL_FIXUP_PATH([path])
 487               UTIL_APPEND_TO_PATH(VS_PATH, $path)
 488             fi
 489             IFS=";"
 490           fi
 491         done
 492         IFS="$OLDIFS"
 493       fi
 494 
 495     else
 496       # We did not find a vsvars bat file, let's hope we are run from a VS command prompt.
 497       AC_MSG_NOTICE([Cannot locate a valid Visual Studio installation, checking current environment])
 498     fi
 499   fi
 500 
 501   # At this point, we should have correct variables in the environment, or we can't continue.
 502   AC_MSG_CHECKING([for Visual Studio variables])
 503 
 504   if test "x$VCINSTALLDIR" != x || test "x$WindowsSDKDir" != x \
 505       || test "x$WINDOWSSDKDIR" != x || test "x$DEVKIT_NAME" != x; then
 506     if test "x$VS_INCLUDE" = x || test "x$VS_LIB" = x; then
 507       AC_MSG_RESULT([present but broken])
 508       AC_MSG_ERROR([Your VC command prompt seems broken, INCLUDE and/or LIB is missing.])
 509     else
 510       AC_MSG_RESULT([ok])
 511       # Remove any trailing "\" ";" and " " from the variables.
 512       VS_INCLUDE=`$ECHO "$VS_INCLUDE" | $SED -e 's/\\\\*;* *$//'`
 513       VS_LIB=`$ECHO "$VS_LIB" | $SED 's/\\\\*;* *$//'`
 514       VCINSTALLDIR=`$ECHO "$VCINSTALLDIR" | $SED 's/\\\\* *$//'`
 515       VCToolsRedistDir=`$ECHO "$VCToolsRedistDir" | $SED 's/\\\\* *$//'`
 516       WindowsSdkDir=`$ECHO "$WindowsSdkDir" | $SED 's/\\\\* *$//'`
 517       WINDOWSSDKDIR=`$ECHO "$WINDOWSSDKDIR" | $SED 's/\\\\* *$//'`
 518       if test -z "$WINDOWSSDKDIR"; then
 519         WINDOWSSDKDIR="$WindowsSdkDir"
 520       fi
 521       # Remove any paths containing # (typically F#) as that messes up make. This
 522       # is needed if visual studio was installed with F# support.
 523       VS_PATH=`$ECHO "$VS_PATH" | $SED 's/[[^:#]]*#[^:]*://g'`
 524 
 525       AC_SUBST(VS_PATH)
 526       AC_SUBST(VS_INCLUDE)
 527       AC_SUBST(VS_LIB)
 528 
 529       TOOLCHAIN_SETUP_VISUAL_STUDIO_SYSROOT_FLAGS
 530 
 531       AC_SUBST(VS_PATH_WINDOWS)
 532     fi
 533   else
 534     AC_MSG_RESULT([not found])
 535 
 536     if test "x$VS_ENV_CMD" = x; then
 537       AC_MSG_NOTICE([Cannot locate a valid Visual Studio or Windows SDK installation on disk,])
 538       AC_MSG_NOTICE([nor is this script run from a Visual Studio command prompt.])
 539     else
 540       AC_MSG_NOTICE([Running the extraction script failed.])
 541     fi
 542     AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
 543     AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
 544     AC_MSG_ERROR([Cannot continue])
 545   fi
 546 ])
 547 
 548 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL],
 549 [
 550   DLL_NAME="$1"
 551   POSSIBLE_MSVC_DLL="$2"
 552   METHOD="$3"
 553   if test -n "$POSSIBLE_MSVC_DLL" -a -e "$POSSIBLE_MSVC_DLL"; then
 554     AC_MSG_NOTICE([Found $DLL_NAME at $POSSIBLE_MSVC_DLL using $METHOD])
 555 
 556     # Need to check if the found msvcr is correct architecture
 557     AC_MSG_CHECKING([found $DLL_NAME architecture])
 558     MSVC_DLL_FILETYPE=`$FILE -b "$POSSIBLE_MSVC_DLL"`
 559     if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
 560       # The MSYS 'file' command returns "PE32 executable for MS Windows (DLL) (GUI) Intel 80386 32-bit"
 561       # on x32 and "PE32+ executable for MS Windows (DLL) (GUI) Mono/.Net assembly" on x64 systems.
 562       if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
 563         CORRECT_MSVCR_ARCH="PE32 executable"
 564       else
 565         CORRECT_MSVCR_ARCH="PE32+ executable"
 566       fi
 567     else
 568       if test "x$OPENJDK_TARGET_CPU" = xx86; then
 569         CORRECT_MSVCR_ARCH=386
 570       elif test "x$OPENJDK_TARGET_CPU" = xx86_64; then
 571         CORRECT_MSVCR_ARCH=x86-64
 572       elif test "x$OPENJDK_TARGET_CPU" = xaarch64; then
 573         # The cygwin 'file' command only returns "PE32+ executable (DLL) (console), for MS Windows",
 574         # without specifying which architecture it is for specifically. This has been fixed upstream.
 575         # https://github.com/file/file/commit/b849b1af098ddd530094bf779b58431395db2e10#diff-ff2eced09e6860de75057dd731d092aeR142
 576         CORRECT_MSVCR_ARCH="PE32+ executable"
 577       fi
 578     fi
 579     if $ECHO "$MSVC_DLL_FILETYPE" | $GREP "$CORRECT_MSVCR_ARCH" 2>&1 > /dev/null; then
 580       AC_MSG_RESULT([ok])
 581       MSVC_DLL="$POSSIBLE_MSVC_DLL"
 582       AC_MSG_CHECKING([for $DLL_NAME])
 583       AC_MSG_RESULT([$MSVC_DLL])
 584     else
 585       AC_MSG_RESULT([incorrect, ignoring])
 586       AC_MSG_NOTICE([The file type of the located $DLL_NAME is $MSVC_DLL_FILETYPE])
 587     fi
 588   fi
 589 ])
 590 
 591 AC_DEFUN([TOOLCHAIN_SETUP_MSVC_DLL],
 592 [
 593   DLL_NAME="$1"
 594   MSVC_DLL=
 595 
 596   if test "x$OPENJDK_TARGET_CPU" = xx86; then
 597     vs_target_cpu=x86
 598   elif test "x$OPENJDK_TARGET_CPU" = xx86_64; then
 599     vs_target_cpu=x64
 600   elif test "x$OPENJDK_TARGET_CPU" = xaarch64; then
 601     vs_target_cpu=arm64
 602   fi
 603 
 604   if test "x$MSVC_DLL" = x; then
 605     if test "x$VCINSTALLDIR" != x; then
 606       CYGWIN_VC_INSTALL_DIR="$VCINSTALLDIR"
 607       UTIL_FIXUP_PATH(CYGWIN_VC_INSTALL_DIR)
 608       if test "$VS_VERSION" -lt 2017; then
 609         # Probe: Using well-known location from Visual Studio 12.0 and older
 610         POSSIBLE_MSVC_DLL="$CYGWIN_VC_INSTALL_DIR/redist/$vs_target_cpu/Microsoft.VC${VS_VERSION_INTERNAL}.CRT/$DLL_NAME"
 611       else
 612         CYGWIN_VC_TOOLS_REDIST_DIR="$VCToolsRedistDir"
 613         UTIL_FIXUP_PATH(CYGWIN_VC_TOOLS_REDIST_DIR)
 614         # Probe: Using well-known location from VS 2017 and VS 2019
 615         POSSIBLE_MSVC_DLL="`ls $CYGWIN_VC_TOOLS_REDIST_DIR/$vs_target_cpu/Microsoft.VC${VS_VERSION_INTERNAL}.CRT/$DLL_NAME`"
 616       fi
 617       # In case any of the above finds more than one file, loop over them.
 618       for possible_msvc_dll in $POSSIBLE_MSVC_DLL; do
 619         $ECHO "POSSIBLE_MSVC_DLL $possible_msvc_dll"
 620         TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$possible_msvc_dll],
 621             [well-known location in VCINSTALLDIR])
 622       done
 623     fi
 624   fi
 625 
 626   if test "x$MSVC_DLL" = x; then
 627     # Probe: Check in the Boot JDK directory.
 628     POSSIBLE_MSVC_DLL="$BOOT_JDK/bin/$DLL_NAME"
 629     TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 630         [well-known location in Boot JDK])
 631   fi
 632 
 633   if test "x$MSVC_DLL" = x; then
 634     # Probe: Look in the Windows system32 directory
 635     CYGWIN_SYSTEMROOT="$SYSTEMROOT"
 636     UTIL_REWRITE_AS_UNIX_PATH(CYGWIN_SYSTEMROOT)
 637     POSSIBLE_MSVC_DLL="$CYGWIN_SYSTEMROOT/system32/$DLL_NAME"
 638     TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 639         [well-known location in SYSTEMROOT])
 640   fi
 641 
 642   if test "x$MSVC_DLL" = x; then
 643     # Probe: If Visual Studio Express is installed, there is usually one with the debugger
 644     if test "x$VS100COMNTOOLS" != x; then
 645       CYGWIN_VS_TOOLS_DIR="$VS100COMNTOOLS/.."
 646       UTIL_REWRITE_AS_UNIX_PATH(CYGWIN_VS_TOOLS_DIR)
 647       POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name $DLL_NAME \
 648         | $GREP -i /$vs_target_cpu/ | $HEAD --lines 1`
 649       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 650           [search of VS100COMNTOOLS])
 651     fi
 652   fi
 653 
 654   if test "x$MSVC_DLL" = x; then
 655     # Probe: Search wildly in the VCINSTALLDIR. We've probably lost by now.
 656     # (This was the original behaviour; kept since it might turn something up)
 657     if test "x$CYGWIN_VC_INSTALL_DIR" != x; then
 658       if test "x$OPENJDK_TARGET_CPU" = xx86; then
 659         POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name $DLL_NAME \
 660         | $GREP x86 | $GREP -v ia64 | $GREP -v x64 | $GREP -v arm64 | $HEAD --lines 1`
 661         if test "x$POSSIBLE_MSVC_DLL" = x; then
 662           # We're grasping at straws now...
 663           POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name $DLL_NAME \
 664           | $HEAD --lines 1`
 665         fi
 666       else
 667         POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name $DLL_NAME \
 668           | $GREP $vs_target_cpu | $HEAD --lines 1`
 669       fi
 670 
 671       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 672           [search of VCINSTALLDIR])
 673     fi
 674   fi
 675 
 676   if test "x$MSVC_DLL" = x; then
 677     AC_MSG_CHECKING([for $DLL_NAME])
 678     AC_MSG_RESULT([no])
 679     AC_MSG_ERROR([Could not find $DLL_NAME. Please specify using --with-msvcr-dll.])
 680   fi
 681 ])
 682 
 683 AC_DEFUN([TOOLCHAIN_SETUP_VS_RUNTIME_DLLS],
 684 [
 685   AC_ARG_WITH(msvcr-dll, [AS_HELP_STRING([--with-msvcr-dll],
 686       [path to microsoft C runtime dll (msvcr*.dll) (Windows only) @<:@probed@:>@])])
 687 
 688   if test "x$with_msvcr_dll" != x; then
 689     # If given explicitly by user, do not probe. If not present, fail directly.
 690     TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCR_NAME, [$with_msvcr_dll], [--with-msvcr-dll])
 691     if test "x$MSVC_DLL" = x; then
 692       AC_MSG_ERROR([Could not find a proper $MSVCR_NAME as specified by --with-msvcr-dll])
 693     fi
 694     MSVCR_DLL="$MSVC_DLL"
 695   elif test "x$DEVKIT_MSVCR_DLL" != x; then
 696     TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCR_NAME, [$DEVKIT_MSVCR_DLL], [devkit])
 697     if test "x$MSVC_DLL" = x; then
 698       AC_MSG_ERROR([Could not find a proper $MSVCR_NAME as specified by devkit])
 699     fi
 700     MSVCR_DLL="$MSVC_DLL"
 701   else
 702     TOOLCHAIN_SETUP_MSVC_DLL([${MSVCR_NAME}])
 703     MSVCR_DLL="$MSVC_DLL"
 704   fi
 705   AC_SUBST(MSVCR_DLL)
 706 
 707   AC_ARG_WITH(msvcp-dll, [AS_HELP_STRING([--with-msvcp-dll],
 708       [path to microsoft C++ runtime dll (msvcp*.dll) (Windows only) @<:@probed@:>@])])
 709 
 710   if test "x$MSVCP_NAME" != "x"; then
 711     if test "x$with_msvcp_dll" != x; then
 712       # If given explicitly by user, do not probe. If not present, fail directly.
 713       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCP_NAME, [$with_msvcp_dll], [--with-msvcp-dll])
 714       if test "x$MSVC_DLL" = x; then
 715         AC_MSG_ERROR([Could not find a proper $MSVCP_NAME as specified by --with-msvcp-dll])
 716       fi
 717       MSVCP_DLL="$MSVC_DLL"
 718     elif test "x$DEVKIT_MSVCP_DLL" != x; then
 719       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCP_NAME, [$DEVKIT_MSVCP_DLL], [devkit])
 720       if test "x$MSVC_DLL" = x; then
 721         AC_MSG_ERROR([Could not find a proper $MSVCP_NAME as specified by devkit])
 722       fi
 723       MSVCP_DLL="$MSVC_DLL"
 724     else
 725       TOOLCHAIN_SETUP_MSVC_DLL([${MSVCP_NAME}])
 726       MSVCP_DLL="$MSVC_DLL"
 727     fi
 728     AC_SUBST(MSVCP_DLL)
 729   fi
 730 
 731   AC_ARG_WITH(vcruntime-1-dll, [AS_HELP_STRING([--with-vcruntime-1-dll],
 732       [path to microsoft C++ runtime dll (vcruntime*_1.dll) (Windows 64-bits only) @<:@probed@:>@])])
 733 
 734   if test "x$VCRUNTIME_1_NAME" != "x" -a "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 735     if test "x$with_vcruntime_1_dll" != x; then
 736       # If given explicitly by user, do not probe. If not present, fail directly.
 737       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($VCRUNTIME_1_NAME, [$with_vcruntime_1_dll],
 738           [--with-vcruntime-1-dll])
 739       if test "x$MSVC_DLL" = x; then
 740         AC_MSG_ERROR([Could not find a proper $VCRUNTIME_1_NAME as specified by --with-vcruntime-1-dll])
 741       fi
 742       VCRUNTIME_1_DLL="$MSVC_DLL"
 743     elif test "x$DEVKIT_VCRUNTIME_1_DLL" != x; then
 744       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($VCRUNTIME_1_NAME, [$DEVKIT_VCRUNTIME_1_DLL], [devkit])
 745       if test "x$MSVC_DLL" = x; then
 746         AC_MSG_ERROR([Could not find a proper $VCRUNTIME_1_NAME as specified by devkit])
 747       fi
 748       VCRUNTIME_1_DLL="$MSVC_DLL"
 749     else
 750       TOOLCHAIN_SETUP_MSVC_DLL([${VCRUNTIME_1_NAME}])
 751       VCRUNTIME_1_DLL="$MSVC_DLL"
 752     fi
 753     AC_SUBST(VCRUNTIME_1_DLL)
 754   fi
 755 
 756   AC_ARG_WITH(ucrt-dll-dir, [AS_HELP_STRING([--with-ucrt-dll-dir],
 757       [path to Microsoft Windows Kit UCRT DLL dir (Windows only) @<:@probed@:>@])])
 758 
 759   if test "x$USE_UCRT" = "xtrue"; then
 760     AC_MSG_CHECKING([for UCRT DLL dir])
 761     if test "x$with_ucrt_dll_dir" != x; then
 762       if test -z "$(ls -d "$with_ucrt_dll_dir/"*.dll 2> /dev/null)"; then
 763         AC_MSG_RESULT([no])
 764         AC_MSG_ERROR([Could not find any dlls in $with_ucrt_dll_dir])
 765       else
 766         AC_MSG_RESULT([$with_ucrt_dll_dir])
 767         UCRT_DLL_DIR="$with_ucrt_dll_dir"
 768         UTIL_FIXUP_PATH([UCRT_DLL_DIR])
 769       fi
 770     elif test "x$DEVKIT_UCRT_DLL_DIR" != "x"; then
 771       UCRT_DLL_DIR="$DEVKIT_UCRT_DLL_DIR"
 772       AC_MSG_RESULT($UCRT_DLL_DIR)
 773     else
 774       CYGWIN_WINDOWSSDKDIR="${WINDOWSSDKDIR}"
 775       UTIL_FIXUP_PATH([CYGWIN_WINDOWSSDKDIR])
 776       if test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
 777         dll_subdir="arm64"
 778       elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
 779         dll_subdir="x64"
 780       elif test "x$OPENJDK_TARGET_CPU" = "xx86"; then
 781         dll_subdir="x86"
 782       fi
 783       UCRT_DLL_DIR="$CYGWIN_WINDOWSSDKDIR/Redist/ucrt/DLLs/$dll_subdir"
 784       if test -z "$(ls -d "$UCRT_DLL_DIR/"*.dll 2> /dev/null)"; then
 785         # Try with version subdir
 786         UCRT_DLL_DIR="`ls -d $CYGWIN_WINDOWSSDKDIR/Redist/*/ucrt/DLLs/$dll_subdir \
 787             2> /dev/null | $SORT -d | $HEAD -n1`"
 788         if test -z "$UCRT_DLL_DIR" \
 789             || test -z "$(ls -d "$UCRT_DLL_DIR/"*.dll 2> /dev/null)"; then
 790           AC_MSG_RESULT([no])
 791           AC_MSG_ERROR([Could not find any dlls in $UCRT_DLL_DIR])
 792         else
 793           AC_MSG_RESULT($UCRT_DLL_DIR)
 794         fi
 795       else
 796         AC_MSG_RESULT($UCRT_DLL_DIR)
 797       fi
 798     fi
 799   else
 800     UCRT_DLL_DIR=
 801   fi
 802   AC_SUBST(UCRT_DLL_DIR)
 803 ])
 804 
 805 # Setup the sysroot flags and add them to global CFLAGS and LDFLAGS so
 806 # that configure can use them while detecting compilers.
 807 # TOOLCHAIN_TYPE is available here.
 808 # Param 1 - Optional prefix to all variables. (e.g BUILD_)
 809 AC_DEFUN([TOOLCHAIN_SETUP_VISUAL_STUDIO_SYSROOT_FLAGS],
 810 [
 811   OLDIFS="$IFS"
 812   IFS=";"
 813   # Convert $1VS_INCLUDE into $1SYSROOT_CFLAGS
 814   for i in [$]$1VS_INCLUDE; do
 815     ipath=$i
 816     # Only process non-empty elements
 817     if test "x$ipath" != x; then
 818       IFS="$OLDIFS"
 819       # Check that directory exists before calling fixup_path
 820       testpath=$ipath
 821       UTIL_REWRITE_AS_UNIX_PATH([testpath])
 822       if test -d "$testpath"; then
 823         UTIL_FIXUP_PATH([ipath])
 824         $1SYSROOT_CFLAGS="[$]$1SYSROOT_CFLAGS -I$ipath"
 825       fi
 826       IFS=";"
 827     fi
 828   done
 829   # Convert $1VS_LIB into $1SYSROOT_LDFLAGS
 830   for i in [$]$1VS_LIB; do
 831     libpath=$i
 832     # Only process non-empty elements
 833     if test "x$libpath" != x; then
 834       IFS="$OLDIFS"
 835       # Check that directory exists before calling fixup_path
 836       testpath=$libpath
 837       UTIL_REWRITE_AS_UNIX_PATH([testpath])
 838       if test -d "$testpath"; then
 839         UTIL_FIXUP_PATH([libpath])
 840         $1SYSROOT_LDFLAGS="[$]$1SYSROOT_LDFLAGS -libpath:$libpath"
 841       fi
 842       IFS=";"
 843     fi
 844   done
 845   IFS="$OLDIFS"
 846 
 847   AC_SUBST($1SYSROOT_CFLAGS)
 848   AC_SUBST($1SYSROOT_LDFLAGS)
 849 ])