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 226 if test "x$SDK_INSTALL_DIR" != x; then 227 if test "x$ProgramW6432" != x; then 228 TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}], 229 [$ProgramW6432/$SDK_INSTALL_DIR], [well-known name]) 230 fi 231 if test "x$PROGRAMW6432" != x; then 232 TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}], 233 [$PROGRAMW6432/$SDK_INSTALL_DIR], [well-known name]) 234 fi 235 if test "x$PROGRAMFILES" != x; then 236 TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}], 237 [$PROGRAMFILES/$SDK_INSTALL_DIR], [well-known name]) 238 fi 239 TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}], 240 [C:/Program Files/$SDK_INSTALL_DIR], [well-known name]) 241 TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}], 242 [C:/Program Files (x86)/$SDK_INSTALL_DIR], [well-known name]) 243 fi 244 ]) 245 246 ################################################################################ 247 248 AC_DEFUN([TOOLCHAIN_FIND_VISUAL_STUDIO], 249 [ 250 AC_ARG_WITH(toolchain-version, [AS_HELP_STRING([--with-toolchain-version], 251 [the version of the toolchain to look for, use '--help' to show possible values @<:@platform dependent@:>@])]) 252 253 if test "x$with_toolchain_version" = xlist; then 254 # List all toolchains 255 AC_MSG_NOTICE([The following toolchain versions are valid on this platform:]) 256 for version in $VALID_VS_VERSIONS; do 257 eval VS_DESCRIPTION=\${VS_DESCRIPTION_$version} 258 $PRINTF " %-10s %s\n" $version "$VS_DESCRIPTION" 259 done 260 261 exit 0 262 elif test "x$DEVKIT_VS_VERSION" != x; then 263 VS_VERSION=$DEVKIT_VS_VERSION 264 TOOLCHAIN_VERSION=$VS_VERSION 265 # If the devkit has a name, use that as description 266 VS_DESCRIPTION="$DEVKIT_NAME" 267 if test "x$VS_DESCRIPTION" = x; then 268 eval VS_DESCRIPTION="\${VS_DESCRIPTION_${VS_VERSION}}" 269 fi 270 eval VS_VERSION_INTERNAL="\${VS_VERSION_INTERNAL_${VS_VERSION}}" 271 eval MSVCR_NAME="\${VS_MSVCR_${VS_VERSION}}" 272 eval MSVCP_NAME="\${VS_MSVCP_${VS_VERSION}}" 273 eval USE_UCRT="\${VS_USE_UCRT_${VS_VERSION}}" 274 eval VS_SUPPORTED="\${VS_SUPPORTED_${VS_VERSION}}" 275 eval PLATFORM_TOOLSET="\${VS_VS_PLATFORM_NAME_${VS_VERSION}}" 276 VS_PATH="$TOOLCHAIN_PATH:$PATH" 277 278 # Convert DEVKIT_VS_INCLUDE into windows style VS_INCLUDE so that it 279 # can still be exported as INCLUDE for compiler invocations without 280 # SYSROOT_CFLAGS 281 OLDIFS="$IFS" 282 IFS=";" 283 for i in $DEVKIT_VS_INCLUDE; do 284 ipath=$i 285 BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([ipath]) 286 VS_INCLUDE="$VS_INCLUDE;$ipath" 287 done 288 # Convert DEVKIT_VS_LIB into VS_LIB so that it can still be exported 289 # as LIB for compiler invocations without SYSROOT_LDFLAGS 290 for i in $DEVKIT_VS_LIB; do 291 libpath=$i 292 BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([libpath]) 293 VS_LIB="$VS_LIB;$libpath" 294 done 295 IFS="$OLDIFS" 296 297 AC_MSG_NOTICE([Found devkit $VS_DESCRIPTION]) 298 299 elif test "x$with_toolchain_version" != x; then 300 # User override; check that it is valid 301 if test "x${VALID_VS_VERSIONS/$with_toolchain_version/}" = "x${VALID_VS_VERSIONS}"; then 302 AC_MSG_NOTICE([Visual Studio version $with_toolchain_version is not valid.]) 303 AC_MSG_NOTICE([Valid Visual Studio versions: $VALID_VS_VERSIONS.]) 304 AC_MSG_ERROR([Cannot continue.]) 305 fi 306 VS_VERSIONS_PROBE_LIST="$with_toolchain_version" 307 else 308 # No flag given, use default 309 VS_VERSIONS_PROBE_LIST="$VALID_VS_VERSIONS" 310 fi 311 312 for VS_VERSION in $VS_VERSIONS_PROBE_LIST; do 313 TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE([$VS_VERSION]) 314 if test "x$VS_ENV_CMD" != x; then 315 TOOLCHAIN_VERSION=$VS_VERSION 316 eval VS_DESCRIPTION="\${VS_DESCRIPTION_${VS_VERSION}}" 317 eval VS_VERSION_INTERNAL="\${VS_VERSION_INTERNAL_${VS_VERSION}}" 318 eval MSVCR_NAME="\${VS_MSVCR_${VS_VERSION}}" 319 eval MSVCP_NAME="\${VS_MSVCP_${VS_VERSION}}" 320 eval USE_UCRT="\${VS_USE_UCRT_${VS_VERSION}}" 321 eval VS_SUPPORTED="\${VS_SUPPORTED_${VS_VERSION}}" 322 # The rest of the variables are already evaled while probing 323 AC_MSG_NOTICE([Found $VS_DESCRIPTION]) 324 break 325 fi 326 done 327 328 TOOLCHAIN_DESCRIPTION="$VS_DESCRIPTION" 329 if test "x$VS_SUPPORTED" = "xfalse"; then 330 UNSUPPORTED_TOOLCHAIN_VERSION=yes 331 fi 332 ]) 333 334 ################################################################################ 335 # Check if the VS env variables were setup prior to running configure. 336 # If not, then find vcvarsall.bat and run it automatically, and integrate 337 # the set env variables into the spec file. 338 AC_DEFUN([TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV], 339 [ 340 # Store path to cygwin link.exe to help excluding it when searching for 341 # VS linker. This must be done before changing the PATH when looking for VS. 342 AC_PATH_PROG(CYGWIN_LINK, link) 343 if test "x$CYGWIN_LINK" != x; then 344 AC_MSG_CHECKING([if the first found link.exe is actually the Cygwin link tool]) 345 "$CYGWIN_LINK" --version > /dev/null 346 if test $? -eq 0 ; then 347 AC_MSG_RESULT([yes]) 348 else 349 AC_MSG_RESULT([no]) 350 # This might be the VS linker. Don't exclude it later on. 351 CYGWIN_LINK="" 352 fi 353 fi 354 355 # First-hand choice is to locate and run the vsvars bat file. 356 TOOLCHAIN_FIND_VISUAL_STUDIO 357 358 # If we have a devkit, skip all of the below. 359 if test "x$DEVKIT_VS_VERSION" = x; then 360 if test "x$VS_ENV_CMD" != x; then 361 # We have found a Visual Studio environment on disk, let's extract variables from the vsvars bat file. 362 BASIC_FIXUP_EXECUTABLE(VS_ENV_CMD) 363 364 # Lets extract the variables that are set by vcvarsall.bat/vsvars32.bat/vsvars64.bat 365 AC_MSG_NOTICE([Trying to extract Visual Studio environment variables]) 366 367 # We need to create a couple of temporary files. 368 VS_ENV_TMP_DIR="$CONFIGURESUPPORT_OUTPUTDIR/vs-env" 369 $MKDIR -p $VS_ENV_TMP_DIR 370 371 # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment). 372 # Instead create a shell script which will set the relevant variables when run. 373 WINPATH_VS_ENV_CMD="$VS_ENV_CMD" 374 BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_VS_ENV_CMD]) 375 WINPATH_BASH="$BASH" 376 BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_BASH]) 377 378 # Generate a DOS batch file which runs $VS_ENV_CMD, and then creates a shell 379 # script (executable by bash) that will setup the important variables. 380 EXTRACT_VC_ENV_BAT_FILE="$VS_ENV_TMP_DIR/extract-vs-env.bat" 381 $ECHO "@echo off" > $EXTRACT_VC_ENV_BAT_FILE 382 # This will end up something like: 383 # call C:/progra~2/micros~2.0/vc/bin/amd64/vcvars64.bat 384 $ECHO "call $WINPATH_VS_ENV_CMD $VS_ENV_ARGS" >> $EXTRACT_VC_ENV_BAT_FILE 385 # In some cases, the VS_ENV_CMD will change directory, change back so 386 # the set-vs-env.sh ends up in the right place. 387 $ECHO 'cd %~dp0' >> $EXTRACT_VC_ENV_BAT_FILE 388 # These will end up something like: 389 # C:/CygWin/bin/bash -c 'echo VS_PATH=\"$PATH\" > localdevenv.sh 390 # The trailing space for everyone except PATH is no typo, but is needed due 391 # to trailing \ in the Windows paths. These will be stripped later. 392 $ECHO "$WINPATH_BASH -c 'echo VS_PATH="'\"$PATH\" > set-vs-env.sh' \ 393 >> $EXTRACT_VC_ENV_BAT_FILE 394 $ECHO "$WINPATH_BASH -c 'echo VS_INCLUDE="'\"$INCLUDE\;$include \" >> set-vs-env.sh' \ 395 >> $EXTRACT_VC_ENV_BAT_FILE 396 $ECHO "$WINPATH_BASH -c 'echo VS_LIB="'\"$LIB\;$lib \" >> set-vs-env.sh' \ 397 >> $EXTRACT_VC_ENV_BAT_FILE 398 $ECHO "$WINPATH_BASH -c 'echo VCINSTALLDIR="'\"$VCINSTALLDIR \" >> set-vs-env.sh' \ 399 >> $EXTRACT_VC_ENV_BAT_FILE 400 $ECHO "$WINPATH_BASH -c 'echo WindowsSdkDir="'\"$WindowsSdkDir \" >> set-vs-env.sh' \ 401 >> $EXTRACT_VC_ENV_BAT_FILE 402 $ECHO "$WINPATH_BASH -c 'echo WINDOWSSDKDIR="'\"$WINDOWSSDKDIR \" >> set-vs-env.sh' \ 403 >> $EXTRACT_VC_ENV_BAT_FILE 404 405 # Now execute the newly created bat file. 406 # The | cat is to stop SetEnv.Cmd to mess with system colors on msys. 407 # Change directory so we don't need to mess with Windows paths in redirects. 408 cd $VS_ENV_TMP_DIR 409 cmd /c extract-vs-env.bat | $CAT 410 cd $CURDIR 411 412 if test ! -s $VS_ENV_TMP_DIR/set-vs-env.sh; then 413 AC_MSG_NOTICE([Could not succesfully extract the envionment variables needed for the VS setup.]) 414 AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation]) 415 AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.]) 416 AC_MSG_ERROR([Cannot continue]) 417 fi 418 419 # Now set all paths and other env variables. This will allow the rest of 420 # the configure script to find and run the compiler in the proper way. 421 AC_MSG_NOTICE([Setting extracted environment variables]) 422 . $VS_ENV_TMP_DIR/set-vs-env.sh 423 # Now we have VS_PATH, VS_INCLUDE, VS_LIB. For further checking, we 424 # also define VCINSTALLDIR, WindowsSdkDir and WINDOWSSDKDIR. 425 else 426 # We did not find a vsvars bat file, let's hope we are run from a VS command prompt. 427 AC_MSG_NOTICE([Cannot locate a valid Visual Studio installation, checking current environment]) 428 fi 429 fi 430 431 # At this point, we should have correct variables in the environment, or we can't continue. 432 AC_MSG_CHECKING([for Visual Studio variables]) 433 434 if test "x$VCINSTALLDIR" != x || test "x$WindowsSDKDir" != x \ 435 || test "x$WINDOWSSDKDIR" != x || test "x$DEVKIT_NAME" != x; then 436 if test "x$VS_INCLUDE" = x || test "x$VS_LIB" = x; then 437 AC_MSG_RESULT([present but broken]) 438 AC_MSG_ERROR([Your VC command prompt seems broken, INCLUDE and/or LIB is missing.]) 439 else 440 AC_MSG_RESULT([ok]) 441 # Remove any trailing "\" ";" and " " from the variables. 442 VS_INCLUDE=`$ECHO "$VS_INCLUDE" | $SED -e 's/\\\\*;* *$//'` 443 VS_LIB=`$ECHO "$VS_LIB" | $SED 's/\\\\*;* *$//'` 444 VCINSTALLDIR=`$ECHO "$VCINSTALLDIR" | $SED 's/\\\\* *$//'` 445 WindowsSdkDir=`$ECHO "$WindowsSdkDir" | $SED 's/\\\\* *$//'` 446 WINDOWSSDKDIR=`$ECHO "$WINDOWSSDKDIR" | $SED 's/\\\\* *$//'` 447 if test -z "$WINDOWSSDKDIR"; then 448 WINDOWSSDKDIR="$WindowsSdkDir" 449 fi 450 # Remove any paths containing # (typically F#) as that messes up make. This 451 # is needed if visual studio was installed with F# support. 452 VS_PATH=`$ECHO "$VS_PATH" | $SED 's/[[^:#]]*#[^:]*://g'` 453 454 AC_SUBST(VS_PATH) 455 AC_SUBST(VS_INCLUDE) 456 AC_SUBST(VS_LIB) 457 458 # Convert VS_INCLUDE into SYSROOT_CFLAGS 459 OLDIFS="$IFS" 460 IFS=";" 461 for i in $VS_INCLUDE; do 462 ipath=$i 463 # Only process non-empty elements 464 if test "x$ipath" != x; then 465 IFS="$OLDIFS" 466 # Check that directory exists before calling fixup_path 467 testpath=$ipath 468 BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([testpath]) 469 if test -d "$testpath"; then 470 BASIC_FIXUP_PATH([ipath]) 471 SYSROOT_CFLAGS="$SYSROOT_CFLAGS -I$ipath" 472 fi 473 IFS=";" 474 fi 475 done 476 # Convert VS_LIB into SYSROOT_LDFLAGS 477 for i in $VS_LIB; do 478 libpath=$i 479 # Only process non-empty elements 480 if test "x$libpath" != x; then 481 IFS="$OLDIFS" 482 # Check that directory exists before calling fixup_path 483 testpath=$libpath 484 BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([testpath]) 485 if test -d "$testpath"; then 486 BASIC_FIXUP_PATH([libpath]) 487 SYSROOT_LDFLAGS="$SYSROOT_LDFLAGS -libpath:$libpath" 488 fi 489 IFS=";" 490 fi 491 done 492 IFS="$OLDIFS" 493 fi 494 else 495 AC_MSG_RESULT([not found]) 496 497 if test "x$VS_ENV_CMD" = x; then 498 AC_MSG_NOTICE([Cannot locate a valid Visual Studio or Windows SDK installation on disk,]) 499 AC_MSG_NOTICE([nor is this script run from a Visual Studio command prompt.]) 500 else 501 AC_MSG_NOTICE([Running the extraction script failed.]) 502 fi 503 AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation]) 504 AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.]) 505 AC_MSG_ERROR([Cannot continue]) 506 fi 507 ]) 508 509 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL], 510 [ 511 DLL_NAME="$1" 512 POSSIBLE_MSVC_DLL="$2" 513 METHOD="$3" 514 if test -n "$POSSIBLE_MSVC_DLL" -a -e "$POSSIBLE_MSVC_DLL"; then 515 AC_MSG_NOTICE([Found $DLL_NAME at $POSSIBLE_MSVC_DLL using $METHOD]) 516 517 # Need to check if the found msvcr is correct architecture 518 AC_MSG_CHECKING([found $DLL_NAME architecture]) 519 MSVC_DLL_FILETYPE=`$FILE -b "$POSSIBLE_MSVC_DLL"` 520 if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then 521 # The MSYS 'file' command returns "PE32 executable for MS Windows (DLL) (GUI) Intel 80386 32-bit" 522 # on x32 and "PE32+ executable for MS Windows (DLL) (GUI) Mono/.Net assembly" on x64 systems. 523 if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then 524 CORRECT_MSVCR_ARCH="PE32 executable" 525 else 526 CORRECT_MSVCR_ARCH="PE32+ executable" 527 fi 528 else 529 if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then 530 CORRECT_MSVCR_ARCH=386 531 else 532 CORRECT_MSVCR_ARCH=x86-64 533 fi 534 fi 535 if $ECHO "$MSVC_DLL_FILETYPE" | $GREP "$CORRECT_MSVCR_ARCH" 2>&1 > /dev/null; then 536 AC_MSG_RESULT([ok]) 537 MSVC_DLL="$POSSIBLE_MSVC_DLL" 538 AC_MSG_CHECKING([for $DLL_NAME]) 539 AC_MSG_RESULT([$MSVC_DLL]) 540 else 541 AC_MSG_RESULT([incorrect, ignoring]) 542 AC_MSG_NOTICE([The file type of the located $DLL_NAME is $MSVC_DLL_FILETYPE]) 543 fi 544 fi 545 ]) 546 547 AC_DEFUN([TOOLCHAIN_SETUP_MSVC_DLL], 548 [ 549 DLL_NAME="$1" 550 MSVC_DLL= 551 552 if test "x$MSVC_DLL" = x; then 553 if test "x$VCINSTALLDIR" != x; then 554 CYGWIN_VC_INSTALL_DIR="$VCINSTALLDIR" 555 BASIC_FIXUP_PATH(CYGWIN_VC_INSTALL_DIR) 556 if test "$VS_VERSION" -lt 2017; then 557 # Probe: Using well-known location from Visual Studio 12.0 and older 558 if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then 559 POSSIBLE_MSVC_DLL="$CYGWIN_VC_INSTALL_DIR/redist/x64/Microsoft.VC${VS_VERSION_INTERNAL}.CRT/$DLL_NAME" 560 else 561 POSSIBLE_MSVC_DLL="$CYGWIN_VC_INSTALL_DIR/redist/x86/Microsoft.VC${VS_VERSION_INTERNAL}.CRT/$DLL_NAME" 562 fi 563 else 564 # Probe: Using well-known location from VS 2017 565 if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then 566 POSSIBLE_MSVC_DLL="`ls $CYGWIN_VC_INSTALL_DIR/Redist/MSVC/*/x64/Microsoft.VC${VS_VERSION_INTERNAL}.CRT/$DLL_NAME`" 567 else 568 POSSIBLE_MSVC_DLL="`ls $CYGWIN_VC_INSTALL_DIR/Redist/MSVC/*/x86/Microsoft.VC${VS_VERSION_INTERNAL}.CRT/$DLL_NAME`" 569 fi 570 fi 571 # In case any of the above finds more than one file, loop over them. 572 for possible_msvc_dll in $POSSIBLE_MSVC_DLL; do 573 $ECHO "POSSIBLE_MSVC_DLL $possible_msvc_dll" 574 TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$possible_msvc_dll], 575 [well-known location in VCINSTALLDIR]) 576 done 577 fi 578 fi 579 580 if test "x$MSVC_DLL" = x; then 581 # Probe: Check in the Boot JDK directory. 582 POSSIBLE_MSVC_DLL="$BOOT_JDK/bin/$DLL_NAME" 583 TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL], 584 [well-known location in Boot JDK]) 585 fi 586 587 if test "x$MSVC_DLL" = x; then 588 # Probe: Look in the Windows system32 directory 589 CYGWIN_SYSTEMROOT="$SYSTEMROOT" 590 BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_SYSTEMROOT) 591 POSSIBLE_MSVC_DLL="$CYGWIN_SYSTEMROOT/system32/$DLL_NAME" 592 TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL], 593 [well-known location in SYSTEMROOT]) 594 fi 595 596 if test "x$MSVC_DLL" = x; then 597 # Probe: If Visual Studio Express is installed, there is usually one with the debugger 598 if test "x$VS100COMNTOOLS" != x; then 599 CYGWIN_VS_TOOLS_DIR="$VS100COMNTOOLS/.." 600 BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_VS_TOOLS_DIR) 601 if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then 602 POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name $DLL_NAME \ 603 | $GREP -i /x64/ | $HEAD --lines 1` 604 else 605 POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name $DLL_NAME \ 606 | $GREP -i /x86/ | $HEAD --lines 1` 607 fi 608 TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL], 609 [search of VS100COMNTOOLS]) 610 fi 611 fi 612 613 if test "x$MSVC_DLL" = x; then 614 # Probe: Search wildly in the VCINSTALLDIR. We've probably lost by now. 615 # (This was the original behaviour; kept since it might turn something up) 616 if test "x$CYGWIN_VC_INSTALL_DIR" != x; then 617 if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then 618 POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name $DLL_NAME \ 619 | $GREP x64 | $HEAD --lines 1` 620 else 621 POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name $DLL_NAME \ 622 | $GREP x86 | $GREP -v ia64 | $GREP -v x64 | $HEAD --lines 1` 623 if test "x$POSSIBLE_MSVC_DLL" = x; then 624 # We're grasping at straws now... 625 POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name $DLL_NAME \ 626 | $HEAD --lines 1` 627 fi 628 fi 629 630 TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL], 631 [search of VCINSTALLDIR]) 632 fi 633 fi 634 635 if test "x$MSVC_DLL" = x; then 636 AC_MSG_CHECKING([for $DLL_NAME]) 637 AC_MSG_RESULT([no]) 638 AC_MSG_ERROR([Could not find $DLL_NAME. Please specify using --with-msvcr-dll.]) 639 fi 640 ]) 641 642 AC_DEFUN([TOOLCHAIN_SETUP_VS_RUNTIME_DLLS], 643 [ 644 AC_ARG_WITH(msvcr-dll, [AS_HELP_STRING([--with-msvcr-dll], 645 [path to microsoft C runtime dll (msvcr*.dll) (Windows only) @<:@probed@:>@])]) 646 647 if test "x$with_msvcr_dll" != x; then 648 # If given explicitly by user, do not probe. If not present, fail directly. 649 TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCR_NAME, [$with_msvcr_dll], [--with-msvcr-dll]) 650 if test "x$MSVC_DLL" = x; then 651 AC_MSG_ERROR([Could not find a proper $MSVCR_NAME as specified by --with-msvcr-dll]) 652 fi 653 MSVCR_DLL="$MSVC_DLL" 654 elif test "x$DEVKIT_MSVCR_DLL" != x; then 655 TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCR_NAME, [$DEVKIT_MSVCR_DLL], [devkit]) 656 if test "x$MSVC_DLL" = x; then 657 AC_MSG_ERROR([Could not find a proper $MSVCR_NAME as specified by devkit]) 658 fi 659 MSVCR_DLL="$MSVC_DLL" 660 else 661 TOOLCHAIN_SETUP_MSVC_DLL([${MSVCR_NAME}]) 662 MSVCR_DLL="$MSVC_DLL" 663 fi 664 AC_SUBST(MSVCR_DLL) 665 666 AC_ARG_WITH(msvcp-dll, [AS_HELP_STRING([--with-msvcp-dll], 667 [path to microsoft C++ runtime dll (msvcp*.dll) (Windows only) @<:@probed@:>@])]) 668 669 if test "x$MSVCP_NAME" != "x"; then 670 if test "x$with_msvcp_dll" != x; then 671 # If given explicitly by user, do not probe. If not present, fail directly. 672 TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCP_NAME, [$with_msvcp_dll], [--with-msvcp-dll]) 673 if test "x$MSVC_DLL" = x; then 674 AC_MSG_ERROR([Could not find a proper $MSVCP_NAME as specified by --with-msvcp-dll]) 675 fi 676 MSVCP_DLL="$MSVC_DLL" 677 elif test "x$DEVKIT_MSVCP_DLL" != x; then 678 TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCP_NAME, [$DEVKIT_MSVCP_DLL], [devkit]) 679 if test "x$MSVC_DLL" = x; then 680 AC_MSG_ERROR([Could not find a proper $MSVCP_NAME as specified by devkit]) 681 fi 682 MSVCP_DLL="$MSVC_DLL" 683 else 684 TOOLCHAIN_SETUP_MSVC_DLL([${MSVCP_NAME}]) 685 MSVCP_DLL="$MSVC_DLL" 686 fi 687 AC_SUBST(MSVCP_DLL) 688 fi 689 690 AC_ARG_WITH(ucrt-dll-dir, [AS_HELP_STRING([--with-ucrt-dll-dir], 691 [path to Microsoft Windows Kit UCRT DLL dir (Windows only) @<:@probed@:>@])]) 692 693 if test "x$USE_UCRT" = "xtrue"; then 694 AC_MSG_CHECKING([for UCRT DLL dir]) 695 if test "x$with_ucrt_dll_dir" != x; then 696 if test -z "$(ls -d "$with_ucrt_dll_dir/*.dll" 2> /dev/null)"; then 697 AC_MSG_RESULT([no]) 698 AC_MSG_ERROR([Could not find any dlls in $with_ucrt_dll_dir]) 699 else 700 AC_MSG_RESULT([$with_ucrt_dll_dir]) 701 UCRT_DLL_DIR="$with_ucrt_dll_dir" 702 BASIC_FIXUP_PATH([UCRT_DLL_DIR]) 703 fi 704 elif test "x$DEVKIT_UCRT_DLL_DIR" != "x"; then 705 UCRT_DLL_DIR="$DEVKIT_UCRT_DLL_DIR" 706 AC_MSG_RESULT($UCRT_DLL_DIR) 707 else 708 CYGWIN_WINDOWSSDKDIR="${WINDOWSSDKDIR}" 709 BASIC_FIXUP_PATH([CYGWIN_WINDOWSSDKDIR]) 710 dll_subdir=$OPENJDK_TARGET_CPU 711 if test "x$dll_subdir" = "xx86_64"; then 712 dll_subdir="x64" 713 fi 714 UCRT_DLL_DIR="$CYGWIN_WINDOWSSDKDIR/Redist/ucrt/DLLs/$dll_subdir" 715 if test -z "$(ls -d "$UCRT_DLL_DIR/"*.dll 2> /dev/null)"; then 716 AC_MSG_RESULT([no]) 717 AC_MSG_ERROR([Could not find any dlls in $UCRT_DLL_DIR]) 718 else 719 AC_MSG_RESULT($UCRT_DLL_DIR) 720 fi 721 fi 722 else 723 UCRT_DLL_DIR= 724 fi 725 AC_SUBST(UCRT_DLL_DIR) 726 ])