1 #
   2 # Copyright (c) 2011, 2012, 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="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 
  91 ################################################################################
  92 
  93 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT],
  94 [
  95   if test "x$VS_ENV_CMD" = x; then
  96     VS_VERSION="$1"
  97     VS_BASE="$2"
  98     METHOD="$3"
  99 
 100     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(VS_BASE)
 101     # In VS 2017, the default installation is in a subdir named after the edition.
 102     # Find the first one present and use that.
 103     if test "x$VS_EDITIONS" != x; then
 104       for edition in $VS_EDITIONS; do
 105         if test -d "$VS_BASE/$edition"; then
 106           VS_BASE="$VS_BASE/$edition"
 107           break
 108         fi
 109       done
 110     fi
 111 
 112     if test -d "$VS_BASE"; then
 113       AC_MSG_NOTICE([Found Visual Studio installation at $VS_BASE using $METHOD])
 114       if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
 115         VCVARSFILES="vc/bin/vcvars32.bat vc/auxiliary/build/vcvars32.bat"
 116       else
 117         VCVARSFILES="vc/bin/amd64/vcvars64.bat vc/bin/x86_amd64/vcvarsx86_amd64.bat \
 118             VC/Auxiliary/Build/vcvarsx86_amd64.bat VC/Auxiliary/Build/vcvars64.bat"
 119       fi
 120 
 121       for VCVARSFILE in $VCVARSFILES; do
 122         if test -f "$VS_BASE/$VCVARSFILE"; then
 123           VS_ENV_CMD="$VS_BASE/$VCVARSFILE"
 124           break
 125         fi
 126       done
 127 
 128       if test "x$VS_ENV_CMD" = x; then
 129         AC_MSG_NOTICE([Warning: None of $VCVARSFILES were found, Visual Studio installation not recognized. Ignoring])
 130       else
 131         # PLATFORM_TOOLSET is used during the compilation of the freetype sources
 132         # (see 'LIB_BUILD_FREETYPE' in libraries.m4) and must be one of 'v100',
 133         # 'v110' or 'v120' for VS 2010, 2012 or VS2013
 134         eval PLATFORM_TOOLSET="\${VS_VS_PLATFORM_NAME_${VS_VERSION}}"
 135       fi
 136     fi
 137   fi
 138 ])
 139 
 140 ################################################################################
 141 
 142 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT],
 143 [
 144   if test "x$VS_ENV_CMD" = x; then
 145     VS_VERSION="$1"
 146     WIN_SDK_BASE="$2"
 147     METHOD="$3"
 148     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(WIN_SDK_BASE)
 149     if test -d "$WIN_SDK_BASE"; then
 150       # There have been cases of partial or broken SDK installations. A missing
 151       # lib dir is not going to work.
 152       if test ! -d "$WIN_SDK_BASE/lib"; then
 153         AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
 154         AC_MSG_NOTICE([Warning: Installation is broken, lib dir is missing. Ignoring])
 155       elif test -f "$WIN_SDK_BASE/Bin/SetEnv.Cmd"; then
 156         AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
 157         VS_ENV_CMD="$WIN_SDK_BASE/Bin/SetEnv.Cmd"
 158         if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
 159           VS_ENV_ARGS="/x86"
 160         else
 161           VS_ENV_ARGS="/x64"
 162         fi
 163         # PLATFORM_TOOLSET is used during the compilation of the freetype sources (see
 164         # 'LIB_BUILD_FREETYPE' in libraries.m4) and must be 'Windows7.1SDK' for Windows7.1SDK
 165         # TODO: improve detection for other versions of SDK
 166         eval PLATFORM_TOOLSET="\${VS_SDK_PLATFORM_NAME_${VS_VERSION}}"
 167       else
 168         AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
 169         AC_MSG_NOTICE([Warning: Installation is broken, SetEnv.Cmd is missing. Ignoring])
 170       fi
 171     fi
 172   fi
 173 ])
 174 
 175 ################################################################################
 176 # Finds the bat or cmd file in Visual Studio or the SDK that sets up a proper
 177 # build environment and assigns it to VS_ENV_CMD
 178 AC_DEFUN([TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE],
 179 [
 180   VS_VERSION="$1"
 181   eval VS_COMNTOOLS_VAR="\${VS_ENVVAR_${VS_VERSION}}"
 182   eval VS_COMNTOOLS="\$${VS_COMNTOOLS_VAR}"
 183   eval VS_INSTALL_DIR="\${VS_VS_INSTALLDIR_${VS_VERSION}}"
 184   eval VS_EDITIONS="\${VS_EDITIONS_${VS_VERSION}}"
 185   eval SDK_INSTALL_DIR="\${VS_SDK_INSTALLDIR_${VS_VERSION}}"
 186   eval VS_ENV_ARGS="\${VS_ENV_ARGS_${VS_VERSION}}"
 187 
 188   # When using --with-tools-dir, assume it points to the correct and default
 189   # version of Visual Studio or that --with-toolchain-version was also set.
 190   if test "x$with_tools_dir" != x; then
 191     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 192         [$with_tools_dir/../..], [--with-tools-dir])
 193     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 194         [$with_tools_dir/../../..], [--with-tools-dir])
 195     if test "x$VS_ENV_CMD" = x; then
 196       # Having specified an argument which is incorrect will produce an instant failure;
 197       # we should not go on looking
 198       AC_MSG_NOTICE([The path given by --with-tools-dir does not contain a valid])
 199       AC_MSG_NOTICE([Visual Studio installation. Please point to the VC/bin or VC/bin/amd64])
 200       AC_MSG_NOTICE([directory within the Visual Studio installation])
 201       AC_MSG_ERROR([Cannot locate a valid Visual Studio installation])
 202     fi
 203   fi
 204 
 205   VS_ENV_CMD=""
 206 
 207   if test "x$VS_COMNTOOLS" != x; then
 208     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 209         [$VS_COMNTOOLS/../..], [$VS_COMNTOOLS_VAR variable])
 210   fi
 211   if test "x$PROGRAMFILES" != x; then
 212     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 213         [$PROGRAMFILES/$VS_INSTALL_DIR], [well-known name])
 214   fi
 215   # Work around the insanely named ProgramFiles(x86) env variable
 216   PROGRAMFILES_X86="`env | $SED -n 's/^ProgramFiles(x86)=//p'`"
 217   if test "x$PROGRAMFILES_X86" != x; then
 218     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 219         [$PROGRAMFILES_X86/$VS_INSTALL_DIR], [well-known name])
 220   fi
 221   TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 222       [C:/Program Files/$VS_INSTALL_DIR], [well-known name])
 223   TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 224       [C:/Program Files (x86)/$VS_INSTALL_DIR], [well-known name])
 225   if test "x$SDK_INSTALL_DIR" != x; then
 226     if test "x$ProgramW6432" != x; then
 227       TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 228           [$ProgramW6432/$SDK_INSTALL_DIR], [well-known name])
 229     fi
 230     if test "x$PROGRAMW6432" != x; then
 231       TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 232           [$PROGRAMW6432/$SDK_INSTALL_DIR], [well-known name])
 233     fi
 234     if test "x$PROGRAMFILES" != x; then
 235       TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 236           [$PROGRAMFILES/$SDK_INSTALL_DIR], [well-known name])
 237     fi
 238     TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 239         [C:/Program Files/$SDK_INSTALL_DIR], [well-known name])
 240     TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 241         [C:/Program Files (x86)/$SDK_INSTALL_DIR], [well-known name])
 242   fi
 243 ])
 244 
 245 ################################################################################
 246 
 247 AC_DEFUN([TOOLCHAIN_FIND_VISUAL_STUDIO],
 248 [
 249   AC_ARG_WITH(toolchain-version, [AS_HELP_STRING([--with-toolchain-version],
 250       [the version of the toolchain to look for, use '--help' to show possible values @<:@platform dependent@:>@])])
 251 
 252   if test "x$with_toolchain_version" = xlist; then
 253     # List all toolchains
 254     AC_MSG_NOTICE([The following toolchain versions are valid on this platform:])
 255     for version in $VALID_VS_VERSIONS; do
 256       eval VS_DESCRIPTION=\${VS_DESCRIPTION_$version}
 257       $PRINTF "  %-10s  %s\n" $version "$VS_DESCRIPTION"
 258     done
 259 
 260     exit 0
 261   elif test "x$DEVKIT_VS_VERSION" != x; then
 262     VS_VERSION=$DEVKIT_VS_VERSION
 263     TOOLCHAIN_VERSION=$VS_VERSION
 264     # If the devkit has a name, use that as description
 265     VS_DESCRIPTION="$DEVKIT_NAME"
 266     if test "x$VS_DESCRIPTION" = x; then
 267       eval VS_DESCRIPTION="\${VS_DESCRIPTION_${VS_VERSION}}"
 268     fi
 269     eval VS_VERSION_INTERNAL="\${VS_VERSION_INTERNAL_${VS_VERSION}}"
 270     eval MSVCR_NAME="\${VS_MSVCR_${VS_VERSION}}"
 271     eval MSVCP_NAME="\${VS_MSVCP_${VS_VERSION}}"
 272     eval USE_UCRT="\${VS_USE_UCRT_${VS_VERSION}}"
 273     eval VS_SUPPORTED="\${VS_SUPPORTED_${VS_VERSION}}"
 274     eval PLATFORM_TOOLSET="\${VS_VS_PLATFORM_NAME_${VS_VERSION}}"
 275     VS_PATH="$TOOLCHAIN_PATH:$PATH"
 276 
 277     # Convert DEVKIT_VS_INCLUDE into windows style VS_INCLUDE so that it
 278     # can still be exported as INCLUDE for compiler invocations without
 279     # SYSROOT_CFLAGS
 280     OLDIFS="$IFS"
 281     IFS=";"
 282     for i in $DEVKIT_VS_INCLUDE; do
 283       ipath=$i
 284       BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([ipath])
 285       VS_INCLUDE="$VS_INCLUDE;$ipath"
 286     done
 287     # Convert DEVKIT_VS_LIB into VS_LIB so that it can still be exported
 288     # as LIB for compiler invocations without SYSROOT_LDFLAGS
 289     for i in $DEVKIT_VS_LIB; do
 290       libpath=$i
 291       BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([libpath])
 292       VS_LIB="$VS_LIB;$libpath"
 293     done
 294     IFS="$OLDIFS"
 295 
 296     AC_MSG_NOTICE([Found devkit $VS_DESCRIPTION])
 297 
 298   elif test "x$with_toolchain_version" != x; then
 299     # User override; check that it is valid
 300     if test "x${VALID_VS_VERSIONS/$with_toolchain_version/}" = "x${VALID_VS_VERSIONS}"; then
 301       AC_MSG_NOTICE([Visual Studio version $with_toolchain_version is not valid.])
 302       AC_MSG_NOTICE([Valid Visual Studio versions: $VALID_VS_VERSIONS.])
 303       AC_MSG_ERROR([Cannot continue.])
 304     fi
 305     VS_VERSIONS_PROBE_LIST="$with_toolchain_version"
 306   else
 307     # No flag given, use default
 308     VS_VERSIONS_PROBE_LIST="$VALID_VS_VERSIONS"
 309   fi
 310 
 311   for VS_VERSION in $VS_VERSIONS_PROBE_LIST; do
 312     TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE([$VS_VERSION])
 313     if test "x$VS_ENV_CMD" != x; then
 314       TOOLCHAIN_VERSION=$VS_VERSION
 315       eval VS_DESCRIPTION="\${VS_DESCRIPTION_${VS_VERSION}}"
 316       eval VS_VERSION_INTERNAL="\${VS_VERSION_INTERNAL_${VS_VERSION}}"
 317       eval MSVCR_NAME="\${VS_MSVCR_${VS_VERSION}}"
 318       eval MSVCP_NAME="\${VS_MSVCP_${VS_VERSION}}"
 319       eval USE_UCRT="\${VS_USE_UCRT_${VS_VERSION}}"
 320       eval VS_SUPPORTED="\${VS_SUPPORTED_${VS_VERSION}}"
 321       # The rest of the variables are already evaled while probing
 322       AC_MSG_NOTICE([Found $VS_DESCRIPTION])
 323       break
 324     fi
 325   done
 326 
 327   TOOLCHAIN_DESCRIPTION="$VS_DESCRIPTION"
 328   if test "x$VS_SUPPORTED" = "xfalse"; then
 329     UNSUPPORTED_TOOLCHAIN_VERSION=yes
 330   fi
 331 ])
 332 
 333 ################################################################################
 334 # Check if the VS env variables were setup prior to running configure.
 335 # If not, then find vcvarsall.bat and run it automatically, and integrate
 336 # the set env variables into the spec file.
 337 AC_DEFUN([TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV],
 338 [
 339   # Store path to cygwin link.exe to help excluding it when searching for
 340   # VS linker. This must be done before changing the PATH when looking for VS.
 341   AC_PATH_PROG(CYGWIN_LINK, link.exe)
 342   if test "x$CYGWIN_LINK" != x; then
 343     AC_MSG_CHECKING([if the first found link.exe is actually the Cygwin link tool])
 344     "$CYGWIN_LINK" --version > /dev/null
 345     if test $? -eq 0 ; then
 346       AC_MSG_RESULT([yes])
 347     else
 348       AC_MSG_RESULT([no])
 349       # This might be the VS linker. Don't exclude it later on.
 350       CYGWIN_LINK=""
 351     fi
 352   fi
 353 
 354   # First-hand choice is to locate and run the vsvars bat file.
 355   TOOLCHAIN_FIND_VISUAL_STUDIO
 356 
 357   # If we have a devkit, skip all of the below.
 358   if test "x$DEVKIT_VS_VERSION" = x; then
 359     if test "x$VS_ENV_CMD" != x; then
 360       # We have found a Visual Studio environment on disk, let's extract variables from the vsvars bat file.
 361       BASIC_FIXUP_EXECUTABLE(VS_ENV_CMD)
 362 
 363       # Lets extract the variables that are set by vcvarsall.bat/vsvars32.bat/vsvars64.bat
 364       AC_MSG_NOTICE([Trying to extract Visual Studio environment variables])
 365 
 366       # We need to create a couple of temporary files.
 367       VS_ENV_TMP_DIR="$CONFIGURESUPPORT_OUTPUTDIR/vs-env"
 368       $MKDIR -p $VS_ENV_TMP_DIR
 369 
 370       # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment).
 371       # Instead create a shell script which will set the relevant variables when run.
 372       WINPATH_VS_ENV_CMD="$VS_ENV_CMD"
 373       BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_VS_ENV_CMD])
 374 
 375       if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
 376         WINPATH_BASH="bash"
 377       else
 378         WINPATH_BASH="$BASH"
 379         BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_BASH])
 380       fi
 381 
 382       # Generate a DOS batch file which runs $VS_ENV_CMD, and then creates a shell
 383       # script (executable by bash) that will setup the important variables.
 384       EXTRACT_VC_ENV_BAT_FILE="$VS_ENV_TMP_DIR/extract-vs-env.bat"
 385       $ECHO "@echo off" >  $EXTRACT_VC_ENV_BAT_FILE
 386       # This will end up something like:
 387       # call C:/progra~2/micros~2.0/vc/bin/amd64/vcvars64.bat
 388       $ECHO "call \"$WINPATH_VS_ENV_CMD\" $VS_ENV_ARGS" >> $EXTRACT_VC_ENV_BAT_FILE
 389       # In some cases, the VS_ENV_CMD will change directory, change back so
 390       # the set-vs-env.sh ends up in the right place.
 391       $ECHO 'cd %~dp0' >> $EXTRACT_VC_ENV_BAT_FILE
 392       # These will end up something like:
 393       # C:/CygWin/bin/bash -c 'echo VS_PATH=\"$PATH\" > localdevenv.sh
 394       # The trailing space for everyone except PATH is no typo, but is needed due
 395       # to trailing \ in the Windows paths. These will be stripped later.
 396       # Trying pure CMD extract. This results in windows paths that need to
 397       # be converted post extraction, but a simpler script.
 398       $ECHO 'echo VS_PATH="%PATH%" > set-vs-env.sh' \
 399           >> $EXTRACT_VC_ENV_BAT_FILE
 400       $ECHO 'echo VS_INCLUDE="%INCLUDE% " >> set-vs-env.sh' \
 401           >> $EXTRACT_VC_ENV_BAT_FILE
 402       $ECHO 'echo VS_LIB="%LIB% " >> set-vs-env.sh' \
 403           >> $EXTRACT_VC_ENV_BAT_FILE
 404       $ECHO 'echo VCINSTALLDIR="%VCINSTALLDIR% " >> set-vs-env.sh' \
 405           >> $EXTRACT_VC_ENV_BAT_FILE
 406       $ECHO 'echo WindowsSdkDir="%WindowsSdkDir% " >> set-vs-env.sh' \
 407           >> $EXTRACT_VC_ENV_BAT_FILE
 408       $ECHO 'echo WINDOWSSDKDIR="%WINDOWSSDKDIR% " >> set-vs-env.sh' \
 409           >> $EXTRACT_VC_ENV_BAT_FILE
 410 
 411       # Now execute the newly created bat file.
 412       # The | cat is to stop SetEnv.Cmd to mess with system colors on msys.
 413       # Change directory so we don't need to mess with Windows paths in redirects.
 414       cd $VS_ENV_TMP_DIR
 415       $CMD /c extract-vs-env.bat | $CAT
 416       cd $CURDIR
 417 
 418       if test ! -s $VS_ENV_TMP_DIR/set-vs-env.sh; then
 419         AC_MSG_NOTICE([Could not succesfully extract the environment variables needed for the VS setup.])
 420         AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
 421         AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
 422         AC_MSG_ERROR([Cannot continue])
 423       fi
 424 
 425       # Remove windows line endings
 426       $SED -i -e 's|\r||g' $VS_ENV_TMP_DIR/set-vs-env.sh
 427 
 428       # Now set all paths and other env variables. This will allow the rest of
 429       # the configure script to find and run the compiler in the proper way.
 430       AC_MSG_NOTICE([Setting extracted environment variables])
 431       . $VS_ENV_TMP_DIR/set-vs-env.sh
 432       # Now we have VS_PATH, VS_INCLUDE, VS_LIB. For further checking, we
 433       # also define VCINSTALLDIR, WindowsSdkDir and WINDOWSSDKDIR.
 434     else
 435       # We did not find a vsvars bat file, let's hope we are run from a VS command prompt.
 436       AC_MSG_NOTICE([Cannot locate a valid Visual Studio installation, checking current environment])
 437     fi
 438   fi
 439 
 440   # At this point, we should have correct variables in the environment, or we can't continue.
 441   AC_MSG_CHECKING([for Visual Studio variables])
 442 
 443   if test "x$VCINSTALLDIR" != x || test "x$WindowsSDKDir" != x \
 444       || test "x$WINDOWSSDKDIR" != x || test "x$DEVKIT_NAME" != x; then
 445     if test "x$VS_INCLUDE" = x || test "x$VS_LIB" = x; then
 446       AC_MSG_RESULT([present but broken])
 447       AC_MSG_ERROR([Your VC command prompt seems broken, INCLUDE and/or LIB is missing.])
 448     else
 449       AC_MSG_RESULT([ok])
 450       # Remove any trailing "\" ";" and " " from the variables.
 451       VS_INCLUDE=`$ECHO "$VS_INCLUDE" | $SED -e 's/\\\\*;* *$//'`
 452       VS_LIB=`$ECHO "$VS_LIB" | $SED 's/\\\\*;* *$//'`
 453       VCINSTALLDIR=`$ECHO "$VCINSTALLDIR" | $SED 's/\\\\* *$//'`
 454       WindowsSdkDir=`$ECHO "$WindowsSdkDir" | $SED 's/\\\\* *$//'`
 455       WINDOWSSDKDIR=`$ECHO "$WINDOWSSDKDIR" | $SED 's/\\\\* *$//'`
 456       if test -z "$WINDOWSSDKDIR"; then
 457         WINDOWSSDKDIR="$WindowsSdkDir"
 458       fi
 459       # Remove any paths containing # (typically F#) as that messes up make. This
 460       # is needed if visual studio was installed with F# support.
 461       VS_PATH=`$ECHO "$VS_PATH" | $SED 's/[[^:#]]*#[^:]*://g'`
 462 
 463       AC_SUBST(VS_PATH)
 464       AC_SUBST(VS_INCLUDE)
 465       AC_SUBST(VS_LIB)
 466 
 467       # Convert VS_PATH to unix style
 468       OLDIFS="$IFS"
 469       IFS=";"
 470       VS_PATH_WINDOWS="$VS_PATH"
 471       VS_PATH=""
 472       for i in $VS_PATH_WINDOWS; do
 473         path=$i
 474         # Only process non-empty elements
 475         if test "x$path" != x; then
 476           IFS="$OLDIFS"
 477           # Check that directory exists before calling fixup_path
 478           testpath=$path
 479           BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([testpath])
 480           if test -d "$testpath"; then
 481             BASIC_FIXUP_PATH([path])
 482             BASIC_APPEND_TO_PATH(VS_PATH, $path)
 483           fi
 484           IFS=";"
 485         fi
 486       done
 487       # Convert VS_INCLUDE into SYSROOT_CFLAGS
 488       for i in $VS_INCLUDE; do
 489         ipath=$i
 490         # Only process non-empty elements
 491         if test "x$ipath" != x; then
 492           IFS="$OLDIFS"
 493           # Check that directory exists before calling fixup_path
 494           testpath=$ipath
 495           BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([testpath])
 496           if test -d "$testpath"; then
 497             BASIC_FIXUP_PATH([ipath])
 498             SYSROOT_CFLAGS="$SYSROOT_CFLAGS -I$ipath"
 499           fi
 500           IFS=";"
 501         fi
 502       done
 503       # Convert VS_LIB into SYSROOT_LDFLAGS
 504       for i in $VS_LIB; do
 505         libpath=$i
 506         # Only process non-empty elements
 507         if test "x$libpath" != x; then
 508           IFS="$OLDIFS"
 509           # Check that directory exists before calling fixup_path
 510           testpath=$libpath
 511           BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([testpath])
 512           if test -d "$testpath"; then
 513             BASIC_FIXUP_PATH([libpath])
 514             SYSROOT_LDFLAGS="$SYSROOT_LDFLAGS -libpath:$libpath"
 515           fi
 516           IFS=";"
 517         fi
 518       done
 519       IFS="$OLDIFS"
 520     fi
 521   else
 522     AC_MSG_RESULT([not found])
 523 
 524     if test "x$VS_ENV_CMD" = x; then
 525       AC_MSG_NOTICE([Cannot locate a valid Visual Studio or Windows SDK installation on disk,])
 526       AC_MSG_NOTICE([nor is this script run from a Visual Studio command prompt.])
 527     else
 528       AC_MSG_NOTICE([Running the extraction script failed.])
 529     fi
 530     AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
 531     AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
 532     AC_MSG_ERROR([Cannot continue])
 533   fi
 534 ])
 535 
 536 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL],
 537 [
 538   DLL_NAME="$1"
 539   POSSIBLE_MSVC_DLL="$2"
 540   METHOD="$3"
 541   if test -n "$POSSIBLE_MSVC_DLL" -a -e "$POSSIBLE_MSVC_DLL"; then
 542     AC_MSG_NOTICE([Found $DLL_NAME at $POSSIBLE_MSVC_DLL using $METHOD])
 543 
 544     # Need to check if the found msvcr is correct architecture
 545     AC_MSG_CHECKING([found $DLL_NAME architecture])
 546     MSVC_DLL_FILETYPE=`$FILE -b "$POSSIBLE_MSVC_DLL"`
 547     if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
 548       # The MSYS 'file' command returns "PE32 executable for MS Windows (DLL) (GUI) Intel 80386 32-bit"
 549       # on x32 and "PE32+ executable for MS Windows (DLL) (GUI) Mono/.Net assembly" on x64 systems.
 550       if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
 551         CORRECT_MSVCR_ARCH="PE32 executable"
 552       else
 553         CORRECT_MSVCR_ARCH="PE32+ executable"
 554       fi
 555     else
 556       if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
 557         CORRECT_MSVCR_ARCH=386
 558       else
 559         CORRECT_MSVCR_ARCH=x86-64
 560       fi
 561     fi
 562     if $ECHO "$MSVC_DLL_FILETYPE" | $GREP "$CORRECT_MSVCR_ARCH" 2>&1 > /dev/null; then
 563       AC_MSG_RESULT([ok])
 564       MSVC_DLL="$POSSIBLE_MSVC_DLL"
 565       AC_MSG_CHECKING([for $DLL_NAME])
 566       AC_MSG_RESULT([$MSVC_DLL])
 567     else
 568       AC_MSG_RESULT([incorrect, ignoring])
 569       AC_MSG_NOTICE([The file type of the located $DLL_NAME is $MSVC_DLL_FILETYPE])
 570     fi
 571   fi
 572 ])
 573 
 574 AC_DEFUN([TOOLCHAIN_SETUP_MSVC_DLL],
 575 [
 576   DLL_NAME="$1"
 577   MSVC_DLL=
 578 
 579   if test "x$MSVC_DLL" = x; then
 580     if test "x$VCINSTALLDIR" != x; then
 581       CYGWIN_VC_INSTALL_DIR="$VCINSTALLDIR"
 582       BASIC_FIXUP_PATH(CYGWIN_VC_INSTALL_DIR)
 583       if test "$VS_VERSION" -lt 2017; then
 584         # Probe: Using well-known location from Visual Studio 12.0 and older
 585         if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 586           POSSIBLE_MSVC_DLL="$CYGWIN_VC_INSTALL_DIR/redist/x64/Microsoft.VC${VS_VERSION_INTERNAL}.CRT/$DLL_NAME"
 587         else
 588           POSSIBLE_MSVC_DLL="$CYGWIN_VC_INSTALL_DIR/redist/x86/Microsoft.VC${VS_VERSION_INTERNAL}.CRT/$DLL_NAME"
 589         fi
 590       else
 591         # Probe: Using well-known location from VS 2017
 592         if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 593           POSSIBLE_MSVC_DLL="`ls $CYGWIN_VC_INSTALL_DIR/Redist/MSVC/*/x64/Microsoft.VC${VS_VERSION_INTERNAL}.CRT/$DLL_NAME`"
 594         else
 595           POSSIBLE_MSVC_DLL="`ls $CYGWIN_VC_INSTALL_DIR/Redist/MSVC/*/x86/Microsoft.VC${VS_VERSION_INTERNAL}.CRT/$DLL_NAME`"
 596         fi
 597       fi
 598       # In case any of the above finds more than one file, loop over them.
 599       for possible_msvc_dll in $POSSIBLE_MSVC_DLL; do
 600         $ECHO "POSSIBLE_MSVC_DLL $possible_msvc_dll"
 601         TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$possible_msvc_dll],
 602             [well-known location in VCINSTALLDIR])
 603       done
 604     fi
 605   fi
 606 
 607   if test "x$MSVC_DLL" = x; then
 608     # Probe: Check in the Boot JDK directory.
 609     POSSIBLE_MSVC_DLL="$BOOT_JDK/bin/$DLL_NAME"
 610     TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 611         [well-known location in Boot JDK])
 612   fi
 613 
 614   if test "x$MSVC_DLL" = x; then
 615     # Probe: Look in the Windows system32 directory
 616     CYGWIN_SYSTEMROOT="$SYSTEMROOT"
 617     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_SYSTEMROOT)
 618     POSSIBLE_MSVC_DLL="$CYGWIN_SYSTEMROOT/system32/$DLL_NAME"
 619     TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 620         [well-known location in SYSTEMROOT])
 621   fi
 622 
 623   if test "x$MSVC_DLL" = x; then
 624     # Probe: If Visual Studio Express is installed, there is usually one with the debugger
 625     if test "x$VS100COMNTOOLS" != x; then
 626       CYGWIN_VS_TOOLS_DIR="$VS100COMNTOOLS/.."
 627       BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_VS_TOOLS_DIR)
 628       if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 629         POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name $DLL_NAME \
 630             | $GREP -i /x64/ | $HEAD --lines 1`
 631       else
 632         POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name $DLL_NAME \
 633             | $GREP -i /x86/ | $HEAD --lines 1`
 634       fi
 635       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 636           [search of VS100COMNTOOLS])
 637     fi
 638   fi
 639 
 640   if test "x$MSVC_DLL" = x; then
 641     # Probe: Search wildly in the VCINSTALLDIR. We've probably lost by now.
 642     # (This was the original behaviour; kept since it might turn something up)
 643     if test "x$CYGWIN_VC_INSTALL_DIR" != x; then
 644       if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 645         POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name $DLL_NAME \
 646             | $GREP x64 | $HEAD --lines 1`
 647       else
 648         POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name $DLL_NAME \
 649             | $GREP x86 | $GREP -v ia64 | $GREP -v x64 | $HEAD --lines 1`
 650         if test "x$POSSIBLE_MSVC_DLL" = x; then
 651           # We're grasping at straws now...
 652           POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name $DLL_NAME \
 653               | $HEAD --lines 1`
 654         fi
 655       fi
 656 
 657       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 658           [search of VCINSTALLDIR])
 659     fi
 660   fi
 661 
 662   if test "x$MSVC_DLL" = x; then
 663     AC_MSG_CHECKING([for $DLL_NAME])
 664     AC_MSG_RESULT([no])
 665     AC_MSG_ERROR([Could not find $DLL_NAME. Please specify using --with-msvcr-dll.])
 666   fi
 667 ])
 668 
 669 AC_DEFUN([TOOLCHAIN_SETUP_VS_RUNTIME_DLLS],
 670 [
 671   AC_ARG_WITH(msvcr-dll, [AS_HELP_STRING([--with-msvcr-dll],
 672       [path to microsoft C runtime dll (msvcr*.dll) (Windows only) @<:@probed@:>@])])
 673 
 674   if test "x$with_msvcr_dll" != x; then
 675     # If given explicitly by user, do not probe. If not present, fail directly.
 676     TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCR_NAME, [$with_msvcr_dll], [--with-msvcr-dll])
 677     if test "x$MSVC_DLL" = x; then
 678       AC_MSG_ERROR([Could not find a proper $MSVCR_NAME as specified by --with-msvcr-dll])
 679     fi
 680     MSVCR_DLL="$MSVC_DLL"
 681   elif test "x$DEVKIT_MSVCR_DLL" != x; then
 682     TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCR_NAME, [$DEVKIT_MSVCR_DLL], [devkit])
 683     if test "x$MSVC_DLL" = x; then
 684       AC_MSG_ERROR([Could not find a proper $MSVCR_NAME as specified by devkit])
 685     fi
 686     MSVCR_DLL="$MSVC_DLL"
 687   else
 688     TOOLCHAIN_SETUP_MSVC_DLL([${MSVCR_NAME}])
 689     MSVCR_DLL="$MSVC_DLL"
 690   fi
 691   AC_SUBST(MSVCR_DLL)
 692 
 693   AC_ARG_WITH(msvcp-dll, [AS_HELP_STRING([--with-msvcp-dll],
 694       [path to microsoft C++ runtime dll (msvcp*.dll) (Windows only) @<:@probed@:>@])])
 695 
 696   if test "x$MSVCP_NAME" != "x"; then
 697     if test "x$with_msvcp_dll" != x; then
 698       # If given explicitly by user, do not probe. If not present, fail directly.
 699       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCP_NAME, [$with_msvcp_dll], [--with-msvcp-dll])
 700       if test "x$MSVC_DLL" = x; then
 701         AC_MSG_ERROR([Could not find a proper $MSVCP_NAME as specified by --with-msvcp-dll])
 702       fi
 703       MSVCP_DLL="$MSVC_DLL"
 704     elif test "x$DEVKIT_MSVCP_DLL" != x; then
 705       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCP_NAME, [$DEVKIT_MSVCP_DLL], [devkit])
 706       if test "x$MSVC_DLL" = x; then
 707         AC_MSG_ERROR([Could not find a proper $MSVCP_NAME as specified by devkit])
 708       fi
 709       MSVCP_DLL="$MSVC_DLL"
 710     else
 711       TOOLCHAIN_SETUP_MSVC_DLL([${MSVCP_NAME}])
 712       MSVCP_DLL="$MSVC_DLL"
 713     fi
 714     AC_SUBST(MSVCP_DLL)
 715   fi
 716 
 717   AC_ARG_WITH(ucrt-dll-dir, [AS_HELP_STRING([--with-ucrt-dll-dir],
 718       [path to Microsoft Windows Kit UCRT DLL dir (Windows only) @<:@probed@:>@])])
 719 
 720   if test "x$USE_UCRT" = "xtrue"; then
 721     AC_MSG_CHECKING([for UCRT DLL dir])
 722     if test "x$with_ucrt_dll_dir" != x; then
 723       if test -z "$(ls -d $with_ucrt_dll_dir/*.dll 2> /dev/null)"; then
 724         AC_MSG_RESULT([no])
 725         AC_MSG_ERROR([Could not find any dlls in $with_ucrt_dll_dir])
 726       else
 727         AC_MSG_RESULT([$with_ucrt_dll_dir])
 728         UCRT_DLL_DIR="$with_ucrt_dll_dir"
 729         BASIC_FIXUP_PATH([UCRT_DLL_DIR])
 730       fi
 731     elif test "x$DEVKIT_UCRT_DLL_DIR" != "x"; then
 732       UCRT_DLL_DIR="$DEVKIT_UCRT_DLL_DIR"
 733       AC_MSG_RESULT($UCRT_DLL_DIR)
 734     else
 735       CYGWIN_WINDOWSSDKDIR="${WINDOWSSDKDIR}"
 736       BASIC_FIXUP_PATH([CYGWIN_WINDOWSSDKDIR])
 737       dll_subdir=$OPENJDK_TARGET_CPU
 738       if test "x$dll_subdir" = "xx86_64"; then
 739         dll_subdir="x64"
 740       fi
 741       UCRT_DLL_DIR="$CYGWIN_WINDOWSSDKDIR/Redist/ucrt/DLLs/$dll_subdir"
 742       if test -z "$(ls -d "$UCRT_DLL_DIR/"*.dll 2> /dev/null)"; then
 743         # Try with version subdir
 744         UCRT_DLL_DIR="`ls -d $CYGWIN_WINDOWSSDKDIR/Redist/*/ucrt/DLLs/$dll_subdir \
 745             2> /dev/null | $SORT -d | $HEAD -n1`"
 746         if test -z "$UCRT_DLL_DIR" \
 747             || test -z "$(ls -d "$UCRT_DLL_DIR/"*.dll 2> /dev/null)"; then
 748           AC_MSG_RESULT([no])
 749           AC_MSG_ERROR([Could not find any dlls in $UCRT_DLL_DIR])
 750         else
 751           AC_MSG_RESULT($UCRT_DLL_DIR)
 752         fi
 753       else
 754         AC_MSG_RESULT($UCRT_DLL_DIR)
 755       fi
 756     fi
 757   else
 758     UCRT_DLL_DIR=
 759   fi
 760   AC_SUBST(UCRT_DLL_DIR)
 761 ])