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