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