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="2013 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 
  41 VS_DESCRIPTION_2012="Microsoft Visual Studio 2012"
  42 VS_VERSION_INTERNAL_2012=110
  43 VS_MSVCR_2012=msvcr110.dll
  44 VS_MSVCP_2012=msvcp110.dll
  45 VS_ENVVAR_2012="VS110COMNTOOLS"
  46 VS_VS_INSTALLDIR_2012="Microsoft Visual Studio 11.0"
  47 VS_SDK_INSTALLDIR_2012=
  48 VS_VS_PLATFORM_NAME_2012="v110"
  49 VS_SDK_PLATFORM_NAME_2012=
  50 
  51 VS_DESCRIPTION_2013="Microsoft Visual Studio 2013"
  52 VS_VERSION_INTERNAL_2013=120
  53 VS_MSVCR_2013=msvcr120.dll
  54 VS_MSVCP_2013=msvcp120.dll
  55 VS_ENVVAR_2013="VS120COMNTOOLS"
  56 VS_VS_INSTALLDIR_2013="Microsoft Visual Studio 12.0"
  57 VS_SDK_INSTALLDIR_2013=
  58 VS_VS_PLATFORM_NAME_2013="v120"
  59 VS_SDK_PLATFORM_NAME_2013=
  60 
  61 ################################################################################
  62 
  63 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT],
  64 [
  65   if test "x$VS_ENV_CMD" = x; then
  66     VS_VERSION="$1"
  67     VS_BASE="$2"
  68     METHOD="$3"
  69 
  70     if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
  71       VCVARSFILE="vc/bin/vcvars32.bat"
  72     else
  73       VCVARSFILE="vc/bin/amd64/vcvars64.bat"
  74     fi
  75 
  76     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(VS_BASE)
  77     if test -d "$VS_BASE"; then
  78       if test -f "$VS_BASE/$VCVARSFILE"; then
  79         AC_MSG_NOTICE([Found Visual Studio installation at $VS_BASE using $METHOD])
  80         VS_ENV_CMD="$VS_BASE/$VCVARSFILE"
  81         # PLATFORM_TOOLSET is used during the compilation of the freetype sources (see
  82         # 'LIB_BUILD_FREETYPE' in libraries.m4) and must be one of 'v100', 'v110' or 'v120' for VS 2010, 2012 or VS2013
  83         eval PLATFORM_TOOLSET="\${VS_VS_PLATFORM_NAME_${VS_VERSION}}"
  84       else
  85         AC_MSG_NOTICE([Found Visual Studio installation at $VS_BASE using $METHOD])
  86         AC_MSG_NOTICE([Warning: $VCVARSFILE is missing, this is probably Visual Studio Express. Ignoring])
  87       fi
  88     fi
  89   fi
  90 ])
  91 
  92 ################################################################################
  93 
  94 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT],
  95 [
  96   if test "x$VS_ENV_CMD" = x; then
  97     VS_VERSION="$1"
  98     WIN_SDK_BASE="$2"
  99     METHOD="$3"
 100     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(WIN_SDK_BASE)
 101     if test -d "$WIN_SDK_BASE"; then
 102       # There have been cases of partial or broken SDK installations. A missing
 103       # lib dir is not going to work.
 104       if test ! -d "$WIN_SDK_BASE/lib"; then
 105         AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
 106         AC_MSG_NOTICE([Warning: Installation is broken, lib dir is missing. Ignoring])
 107       elif test -f "$WIN_SDK_BASE/Bin/SetEnv.Cmd"; then
 108         AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
 109         VS_ENV_CMD="$WIN_SDK_BASE/Bin/SetEnv.Cmd"
 110         if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
 111           VS_ENV_ARGS="/x86"
 112         else
 113           VS_ENV_ARGS="/x64"
 114         fi
 115         # PLATFORM_TOOLSET is used during the compilation of the freetype sources (see
 116         # 'LIB_BUILD_FREETYPE' in libraries.m4) and must be 'Windows7.1SDK' for Windows7.1SDK
 117         # TODO: improve detection for other versions of SDK
 118         eval PLATFORM_TOOLSET="\${VS_SDK_PLATFORM_NAME_${VS_VERSION}}"
 119       else
 120         AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
 121         AC_MSG_NOTICE([Warning: Installation is broken, SetEnv.Cmd is missing. Ignoring])
 122       fi
 123     fi
 124   fi
 125 ])
 126 
 127 ################################################################################
 128 # Finds the bat or cmd file in Visual Studio or the SDK that sets up a proper
 129 # build environment and assigns it to VS_ENV_CMD
 130 AC_DEFUN([TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE],
 131 [
 132   VS_VERSION="$1"
 133   eval VS_COMNTOOLS_VAR="\${VS_ENVVAR_${VS_VERSION}}"
 134   eval VS_COMNTOOLS="\$${VS_COMNTOOLS_VAR}"
 135   eval VS_INSTALL_DIR="\${VS_VS_INSTALLDIR_${VS_VERSION}}"
 136   eval SDK_INSTALL_DIR="\${VS_SDK_INSTALLDIR_${VS_VERSION}}"
 137 
 138   # When using --with-tools-dir, assume it points to the correct and default
 139   # version of Visual Studio or that --with-toolchain-version was also set.
 140   if test "x$with_tools_dir" != x; then
 141     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 142         [$with_tools_dir/../..], [--with-tools-dir])
 143     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 144         [$with_tools_dir/../../..], [--with-tools-dir])
 145     if test "x$VS_ENV_CMD" = x; then
 146       # Having specified an argument which is incorrect will produce an instant failure;
 147       # we should not go on looking
 148       AC_MSG_NOTICE([The path given by --with-tools-dir does not contain a valid])
 149       AC_MSG_NOTICE([Visual Studio installation. Please point to the VC/bin or VC/bin/amd64])
 150       AC_MSG_NOTICE([directory within the Visual Studio installation])
 151       AC_MSG_ERROR([Cannot locate a valid Visual Studio installation])
 152     fi
 153   fi
 154 
 155   VS_ENV_CMD=""
 156   VS_ENV_ARGS=""
 157 
 158   if test "x$VS_COMNTOOLS" != x; then
 159     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 160         [$VS_COMNTOOLS/../..], [$VS_COMNTOOLS_VAR variable])
 161   fi
 162   if test "x$PROGRAMFILES" != x; then
 163     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 164         [$PROGRAMFILES/$VS_INSTALL_DIR], [well-known name])
 165   fi
 166   # Work around the insanely named ProgramFiles(x86) env variable
 167   PROGRAMFILES_X86="`env | $SED -n 's/^ProgramFiles(x86)=//p'`"
 168   if test "x$PROGRAMFILES_X86" != x; then
 169     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 170         [$PROGRAMFILES_X86/$VS_INSTALL_DIR], [well-known name])
 171   fi
 172   TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 173       [C:/Program Files/$VS_INSTALL_DIR], [well-known name])
 174   TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([${VS_VERSION}],
 175       [C:/Program Files (x86)/$VS_INSTALL_DIR], [well-known name])
 176 
 177   if test "x$SDK_INSTALL_DIR" != x; then
 178     if test "x$ProgramW6432" != x; then
 179       TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 180           [$ProgramW6432/$SDK_INSTALL_DIR], [well-known name])
 181     fi
 182     if test "x$PROGRAMW6432" != x; then
 183       TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 184           [$PROGRAMW6432/$SDK_INSTALL_DIR], [well-known name])
 185     fi
 186     if test "x$PROGRAMFILES" != x; then
 187       TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 188           [$PROGRAMFILES/$SDK_INSTALL_DIR], [well-known name])
 189     fi
 190     TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 191         [C:/Program Files/$SDK_INSTALL_DIR], [well-known name])
 192     TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([${VS_VERSION}],
 193         [C:/Program Files (x86)/$SDK_INSTALL_DIR], [well-known name])
 194   fi
 195 ])
 196 
 197 ################################################################################
 198 
 199 AC_DEFUN([TOOLCHAIN_FIND_VISUAL_STUDIO],
 200 [
 201   AC_ARG_WITH(toolchain-version, [AS_HELP_STRING([--with-toolchain-version],
 202       [the version of the toolchain to look for, use '--help' to show possible values @<:@platform dependent@:>@])])
 203 
 204   if test "x$with_toolchain_version" = xlist; then
 205     # List all toolchains
 206     AC_MSG_NOTICE([The following toolchain versions are valid on this platform:])
 207     for version in $VALID_VS_VERSIONS; do
 208       eval VS_DESCRIPTION=\${VS_DESCRIPTION_$version}
 209       $PRINTF "  %-10s  %s\n" $version "$VS_DESCRIPTION"
 210     done
 211 
 212     exit 0
 213   elif test "x$DEVKIT_VS_VERSION" != x; then
 214     VS_VERSION=$DEVKIT_VS_VERSION
 215     TOOLCHAIN_VERSION=$VS_VERSION
 216     eval VS_DESCRIPTION="\${VS_DESCRIPTION_${VS_VERSION}}"
 217     eval VS_VERSION_INTERNAL="\${VS_VERSION_INTERNAL_${VS_VERSION}}"
 218     eval MSVCR_NAME="\${VS_MSVCR_${VS_VERSION}}"
 219     eval MSVCP_NAME="\${VS_MSVCP_${VS_VERSION}}"
 220     eval PLATFORM_TOOLSET="\${VS_VS_PLATFORM_NAME_${VS_VERSION}}"
 221     VS_PATH="$TOOLCHAIN_PATH:$PATH"
 222 
 223     # Convert DEVKIT_VS_INCLUDE into windows style VS_INCLUDE so that it
 224     # can still be exported as INCLUDE for compiler invocations without
 225     # SYSROOT_CFLAGS
 226     OLDIFS="$IFS"
 227     IFS=";"
 228     for i in $DEVKIT_VS_INCLUDE; do
 229       ipath=$i
 230       BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([ipath])
 231       VS_INCLUDE="$VS_INCLUDE;$ipath"
 232     done
 233     # Convert DEVKIT_VS_LIB into VS_LIB so that it can still be exported
 234     # as LIB for compiler invocations without SYSROOT_LDFLAGS
 235     for i in $DEVKIT_VS_LIB; do
 236       libpath=$i
 237       BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([libpath])
 238       VS_LIB="$VS_LIB;$libpath"
 239     done
 240     IFS="$OLDIFS"
 241 
 242     AC_MSG_NOTICE([Found devkit $VS_DESCRIPTION])
 243 
 244   elif test "x$with_toolchain_version" != x; then
 245     # User override; check that it is valid
 246     if test "x${VALID_VS_VERSIONS/$with_toolchain_version/}" = "x${VALID_VS_VERSIONS}"; then
 247       AC_MSG_NOTICE([Visual Studio version $with_toolchain_version is not valid.])
 248       AC_MSG_NOTICE([Valid Visual Studio versions: $VALID_VS_VERSIONS.])
 249       AC_MSG_ERROR([Cannot continue.])
 250     fi
 251     VS_VERSIONS_PROBE_LIST="$with_toolchain_version"
 252   else
 253     # No flag given, use default
 254     VS_VERSIONS_PROBE_LIST="$VALID_VS_VERSIONS"
 255   fi
 256 
 257   for VS_VERSION in $VS_VERSIONS_PROBE_LIST; do
 258     TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE([$VS_VERSION])
 259     if test "x$VS_ENV_CMD" != x; then
 260       TOOLCHAIN_VERSION=$VS_VERSION
 261       eval VS_DESCRIPTION="\${VS_DESCRIPTION_${VS_VERSION}}"
 262       eval VS_VERSION_INTERNAL="\${VS_VERSION_INTERNAL_${VS_VERSION}}"
 263       eval MSVCR_NAME="\${VS_MSVCR_${VS_VERSION}}"
 264       eval MSVCP_NAME="\${VS_MSVCP_${VS_VERSION}}"
 265       # The rest of the variables are already evaled while probing
 266       AC_MSG_NOTICE([Found $VS_DESCRIPTION])
 267       break
 268     fi
 269   done
 270 ])
 271 
 272 ################################################################################
 273 # Check if the VS env variables were setup prior to running configure.
 274 # If not, then find vcvarsall.bat and run it automatically, and integrate
 275 # the set env variables into the spec file.
 276 AC_DEFUN([TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV],
 277 [
 278   # Store path to cygwin link.exe to help excluding it when searching for
 279   # VS linker. This must be done before changing the PATH when looking for VS.
 280   AC_PATH_PROG(CYGWIN_LINK, link)
 281   if test "x$CYGWIN_LINK" != x; then
 282     AC_MSG_CHECKING([if the first found link.exe is actually the Cygwin link tool])
 283     "$CYGWIN_LINK" --version > /dev/null
 284     if test $? -eq 0 ; then
 285       AC_MSG_RESULT([yes])
 286     else
 287       AC_MSG_RESULT([no])
 288       # This might be the VS linker. Don't exclude it later on.
 289       CYGWIN_LINK=""
 290     fi
 291   fi
 292 
 293   # First-hand choice is to locate and run the vsvars bat file.
 294   TOOLCHAIN_FIND_VISUAL_STUDIO
 295 
 296   # If we have a devkit, skip all of the below.
 297   if test "x$DEVKIT_VS_VERSION" = x; then
 298     if test "x$VS_ENV_CMD" != x; then
 299       # We have found a Visual Studio environment on disk, let's extract variables from the vsvars bat file.
 300       BASIC_FIXUP_EXECUTABLE(VS_ENV_CMD)
 301 
 302       # Lets extract the variables that are set by vcvarsall.bat/vsvars32.bat/vsvars64.bat
 303       AC_MSG_NOTICE([Trying to extract Visual Studio environment variables])
 304 
 305       # We need to create a couple of temporary files.
 306       VS_ENV_TMP_DIR="$CONFIGURESUPPORT_OUTPUTDIR/vs-env"
 307       $MKDIR -p $VS_ENV_TMP_DIR
 308 
 309       # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment).
 310       # Instead create a shell script which will set the relevant variables when run.
 311       WINPATH_VS_ENV_CMD="$VS_ENV_CMD"
 312       BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_VS_ENV_CMD])
 313       WINPATH_BASH="$BASH"
 314       BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_BASH])
 315 
 316       # Generate a DOS batch file which runs $VS_ENV_CMD, and then creates a shell
 317       # script (executable by bash) that will setup the important variables.
 318       EXTRACT_VC_ENV_BAT_FILE="$VS_ENV_TMP_DIR/extract-vs-env.bat"
 319       $ECHO "@echo off" >  $EXTRACT_VC_ENV_BAT_FILE
 320       # This will end up something like:
 321       # call C:/progra~2/micros~2.0/vc/bin/amd64/vcvars64.bat
 322       $ECHO "call $WINPATH_VS_ENV_CMD $VS_ENV_ARGS" >> $EXTRACT_VC_ENV_BAT_FILE
 323       # These will end up something like:
 324       # C:/CygWin/bin/bash -c 'echo VS_PATH=\"$PATH\" > localdevenv.sh
 325       # The trailing space for everyone except PATH is no typo, but is needed due
 326       # to trailing \ in the Windows paths. These will be stripped later.
 327       $ECHO "$WINPATH_BASH -c 'echo VS_PATH="'\"$PATH\" > set-vs-env.sh' \
 328           >> $EXTRACT_VC_ENV_BAT_FILE
 329       $ECHO "$WINPATH_BASH -c 'echo VS_INCLUDE="'\"$INCLUDE\;$include \" >> set-vs-env.sh' \
 330           >> $EXTRACT_VC_ENV_BAT_FILE
 331       $ECHO "$WINPATH_BASH -c 'echo VS_LIB="'\"$LIB\;$lib \" >> set-vs-env.sh' \
 332           >> $EXTRACT_VC_ENV_BAT_FILE
 333       $ECHO "$WINPATH_BASH -c 'echo VCINSTALLDIR="'\"$VCINSTALLDIR \" >> set-vs-env.sh' \
 334           >> $EXTRACT_VC_ENV_BAT_FILE
 335       $ECHO "$WINPATH_BASH -c 'echo WindowsSdkDir="'\"$WindowsSdkDir \" >> set-vs-env.sh' \
 336           >> $EXTRACT_VC_ENV_BAT_FILE
 337       $ECHO "$WINPATH_BASH -c 'echo WINDOWSSDKDIR="'\"$WINDOWSSDKDIR \" >> set-vs-env.sh' \
 338           >> $EXTRACT_VC_ENV_BAT_FILE
 339 
 340       # Now execute the newly created bat file.
 341       # The | cat is to stop SetEnv.Cmd to mess with system colors on msys.
 342       # Change directory so we don't need to mess with Windows paths in redirects.
 343       cd $VS_ENV_TMP_DIR
 344       cmd /c extract-vs-env.bat | $CAT
 345       cd $CURDIR
 346 
 347       if test ! -s $VS_ENV_TMP_DIR/set-vs-env.sh; then
 348         AC_MSG_NOTICE([Could not succesfully extract the envionment variables needed for the VS setup.])
 349         AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
 350         AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
 351         AC_MSG_ERROR([Cannot continue])
 352       fi
 353 
 354       # Now set all paths and other env variables. This will allow the rest of
 355       # the configure script to find and run the compiler in the proper way.
 356       AC_MSG_NOTICE([Setting extracted environment variables])
 357       . $VS_ENV_TMP_DIR/set-vs-env.sh
 358       # Now we have VS_PATH, VS_INCLUDE, VS_LIB. For further checking, we
 359       # also define VCINSTALLDIR, WindowsSdkDir and WINDOWSSDKDIR.
 360     else
 361       # We did not find a vsvars bat file, let's hope we are run from a VS command prompt.
 362       AC_MSG_NOTICE([Cannot locate a valid Visual Studio installation, checking current environment])
 363     fi
 364   fi
 365 
 366   # At this point, we should have correct variables in the environment, or we can't continue.
 367   AC_MSG_CHECKING([for Visual Studio variables])
 368 
 369   if test "x$VCINSTALLDIR" != x || test "x$WindowsSDKDir" != x \
 370       || test "x$WINDOWSSDKDIR" != x || test "x$DEVKIT_NAME" != x; then
 371     if test "x$VS_INCLUDE" = x || test "x$VS_LIB" = x; then
 372       AC_MSG_RESULT([present but broken])
 373       AC_MSG_ERROR([Your VC command prompt seems broken, INCLUDE and/or LIB is missing.])
 374     else
 375       AC_MSG_RESULT([ok])
 376       # Remove any trailing "\" ";" and " " from the variables.
 377       VS_INCLUDE=`$ECHO "$VS_INCLUDE" | $SED -e 's/\\\\*;* *$//'`
 378       VS_LIB=`$ECHO "$VS_LIB" | $SED 's/\\\\*;* *$//'`
 379       VCINSTALLDIR=`$ECHO "$VCINSTALLDIR" | $SED 's/\\\\* *$//'`
 380       WindowsSDKDir=`$ECHO "$WindowsSDKDir" | $SED 's/\\\\* *$//'`
 381       WINDOWSSDKDIR=`$ECHO "$WINDOWSSDKDIR" | $SED 's/\\\\* *$//'`
 382       # Remove any paths containing # (typically F#) as that messes up make. This
 383       # is needed if visual studio was installed with F# support.
 384       VS_PATH=`$ECHO "$VS_PATH" | $SED 's/[[^:#]]*#[^:]*://g'`
 385 
 386       AC_SUBST(VS_PATH)
 387       AC_SUBST(VS_INCLUDE)
 388       AC_SUBST(VS_LIB)
 389 
 390       # Convert VS_INCLUDE into SYSROOT_CFLAGS
 391       OLDIFS="$IFS"
 392       IFS=";"
 393       for i in $VS_INCLUDE; do
 394         ipath=$i
 395         # Only process non-empty elements
 396         if test "x$ipath" != x; then
 397           IFS="$OLDIFS"
 398           # Check that directory exists before calling fixup_path
 399           testpath=$ipath
 400           BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([testpath])
 401           if test -d "$testpath"; then
 402             BASIC_FIXUP_PATH([ipath])
 403             SYSROOT_CFLAGS="$SYSROOT_CFLAGS -I$ipath"
 404           fi
 405           IFS=";"
 406         fi
 407       done
 408       # Convert VS_LIB into SYSROOT_LDFLAGS
 409       for i in $VS_LIB; do
 410         libpath=$i
 411         # Only process non-empty elements
 412         if test "x$libpath" != x; then
 413           IFS="$OLDIFS"
 414           # Check that directory exists before calling fixup_path
 415           testpath=$libpath
 416           BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([testpath])
 417           if test -d "$testpath"; then
 418             BASIC_FIXUP_PATH([libpath])
 419             SYSROOT_LDFLAGS="$SYSROOT_LDFLAGS -libpath:$libpath"
 420           fi
 421           IFS=";"
 422         fi
 423       done
 424       IFS="$OLDIFS"
 425     fi
 426   else
 427     AC_MSG_RESULT([not found])
 428 
 429     if test "x$VS_ENV_CMD" = x; then
 430       AC_MSG_NOTICE([Cannot locate a valid Visual Studio or Windows SDK installation on disk,])
 431       AC_MSG_NOTICE([nor is this script run from a Visual Studio command prompt.])
 432     else
 433       AC_MSG_NOTICE([Running the extraction script failed.])
 434     fi
 435     AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
 436     AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
 437     AC_MSG_ERROR([Cannot continue])
 438   fi
 439 ])
 440 
 441 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL],
 442 [
 443   DLL_NAME="$1"
 444   POSSIBLE_MSVC_DLL="$2"
 445   METHOD="$3"
 446   if test -n "$POSSIBLE_MSVC_DLL" -a -e "$POSSIBLE_MSVC_DLL"; then
 447     AC_MSG_NOTICE([Found $DLL_NAME at $POSSIBLE_MSVC_DLL using $METHOD])
 448 
 449     # Need to check if the found msvcr is correct architecture
 450     AC_MSG_CHECKING([found $DLL_NAME architecture])
 451     MSVC_DLL_FILETYPE=`$FILE -b "$POSSIBLE_MSVC_DLL"`
 452     if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
 453       # The MSYS 'file' command returns "PE32 executable for MS Windows (DLL) (GUI) Intel 80386 32-bit"
 454       # on x32 and "PE32+ executable for MS Windows (DLL) (GUI) Mono/.Net assembly" on x64 systems.
 455       if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
 456         CORRECT_MSVCR_ARCH="PE32 executable"
 457       else
 458         CORRECT_MSVCR_ARCH="PE32+ executable"
 459       fi
 460     else
 461       if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
 462         CORRECT_MSVCR_ARCH=386
 463       else
 464         CORRECT_MSVCR_ARCH=x86-64
 465       fi
 466     fi
 467     if $ECHO "$MSVC_DLL_FILETYPE" | $GREP "$CORRECT_MSVCR_ARCH" 2>&1 > /dev/null; then
 468       AC_MSG_RESULT([ok])
 469       MSVC_DLL="$POSSIBLE_MSVC_DLL"
 470       BASIC_FIXUP_PATH(MSVC_DLL)
 471       AC_MSG_CHECKING([for $DLL_NAME])
 472       AC_MSG_RESULT([$MSVC_DLL])
 473     else
 474       AC_MSG_RESULT([incorrect, ignoring])
 475       AC_MSG_NOTICE([The file type of the located $DLL_NAME is $MSVC_DLL_FILETYPE])
 476     fi
 477   fi
 478 ])
 479 
 480 AC_DEFUN([TOOLCHAIN_SETUP_MSVC_DLL],
 481 [
 482   DLL_NAME="$1"
 483   MSVC_DLL=
 484 
 485   if test "x$MSVC_DLL" = x; then
 486     # Probe: Using well-known location from Visual Studio 10.0
 487     if test "x$VCINSTALLDIR" != x; then
 488       CYGWIN_VC_INSTALL_DIR="$VCINSTALLDIR"
 489       BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_VC_INSTALL_DIR)
 490       if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 491         POSSIBLE_MSVC_DLL="$CYGWIN_VC_INSTALL_DIR/redist/x64/Microsoft.VC${VS_VERSION_INTERNAL}.CRT/$DLL_NAME"
 492       else
 493         POSSIBLE_MSVC_DLL="$CYGWIN_VC_INSTALL_DIR/redist/x86/Microsoft.VC${VS_VERSION_INTERNAL}.CRT/$DLL_NAME"
 494       fi
 495       $ECHO "POSSIBLE_MSVC_DLL $POSSIBLEMSVC_DLL"
 496       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 497           [well-known location in VCINSTALLDIR])
 498     fi
 499   fi
 500 
 501   if test "x$MSVC_DLL" = x; then
 502     # Probe: Check in the Boot JDK directory.
 503     POSSIBLE_MSVC_DLL="$BOOT_JDK/bin/$DLL_NAME"
 504     TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 505         [well-known location in Boot JDK])
 506   fi
 507 
 508   if test "x$MSVC_DLL" = x; then
 509     # Probe: Look in the Windows system32 directory
 510     CYGWIN_SYSTEMROOT="$SYSTEMROOT"
 511     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_SYSTEMROOT)
 512     POSSIBLE_MSVC_DLL="$CYGWIN_SYSTEMROOT/system32/$DLL_NAME"
 513     TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 514         [well-known location in SYSTEMROOT])
 515   fi
 516 
 517   if test "x$MSVC_DLL" = x; then
 518     # Probe: If Visual Studio Express is installed, there is usually one with the debugger
 519     if test "x$VS100COMNTOOLS" != x; then
 520       CYGWIN_VS_TOOLS_DIR="$VS100COMNTOOLS/.."
 521       BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_VS_TOOLS_DIR)
 522       if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 523         POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name $DLL_NAME \
 524             | $GREP -i /x64/ | $HEAD --lines 1`
 525       else
 526         POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name $DLL_NAME \
 527             | $GREP -i /x86/ | $HEAD --lines 1`
 528       fi
 529       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 530           [search of VS100COMNTOOLS])
 531     fi
 532   fi
 533 
 534   if test "x$MSVC_DLL" = x; then
 535     # Probe: Search wildly in the VCINSTALLDIR. We've probably lost by now.
 536     # (This was the original behaviour; kept since it might turn something up)
 537     if test "x$CYGWIN_VC_INSTALL_DIR" != x; then
 538       if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 539         POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name $DLL_NAME \
 540             | $GREP x64 | $HEAD --lines 1`
 541       else
 542         POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name $DLL_NAME \
 543             | $GREP x86 | $GREP -v ia64 | $GREP -v x64 | $HEAD --lines 1`
 544         if test "x$POSSIBLE_MSVC_DLL" = x; then
 545           # We're grasping at straws now...
 546           POSSIBLE_MSVC_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name $DLL_NAME \
 547               | $HEAD --lines 1`
 548         fi
 549       fi
 550 
 551       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL([$DLL_NAME], [$POSSIBLE_MSVC_DLL],
 552           [search of VCINSTALLDIR])
 553     fi
 554   fi
 555 
 556   if test "x$MSVC_DLL" = x; then
 557     AC_MSG_CHECKING([for $DLL_NAME])
 558     AC_MSG_RESULT([no])
 559     AC_MSG_ERROR([Could not find $DLL_NAME. Please specify using --with-msvcr-dll.])
 560   fi
 561 ])
 562 
 563 AC_DEFUN([TOOLCHAIN_SETUP_VS_RUNTIME_DLLS],
 564 [
 565   AC_ARG_WITH(msvcr-dll, [AS_HELP_STRING([--with-msvcr-dll],
 566       [path to microsoft C runtime dll (msvcr*.dll) (Windows only) @<:@probed@:>@])])
 567 
 568   if test "x$with_msvcr_dll" != x; then
 569     # If given explicitely by user, do not probe. If not present, fail directly.
 570     TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCR_NAME, [$with_msvcr_dll], [--with-msvcr-dll])
 571     if test "x$MSVC_DLL" = x; then
 572       AC_MSG_ERROR([Could not find a proper $MSVCR_NAME as specified by --with-msvcr-dll])
 573     fi
 574     MSVCR_DLL="$MSVC_DLL"
 575   elif test "x$DEVKIT_MSVCR_DLL" != x; then
 576     TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCR_NAME, [$DEVKIT_MSVCR_DLL], [devkit])
 577     if test "x$MSVC_DLL" = x; then
 578       AC_MSG_ERROR([Could not find a proper $MSVCR_NAME as specified by devkit])
 579     fi  
 580     MSVCR_DLL="$MSVC_DLL"
 581   else
 582     TOOLCHAIN_SETUP_MSVC_DLL([${MSVCR_NAME}])
 583     MSVCR_DLL="$MSVC_DLL"
 584   fi
 585   AC_SUBST(MSVCR_DLL)
 586 
 587   AC_ARG_WITH(msvcp-dll, [AS_HELP_STRING([--with-msvcp-dll],
 588       [path to microsoft C++ runtime dll (msvcp*.dll) (Windows only) @<:@probed@:>@])])
 589 
 590   if test "x$MSVCP_NAME" != "x"; then
 591     if test "x$with_msvcp_dll" != x; then
 592       # If given explicitely by user, do not probe. If not present, fail directly.
 593       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCP_NAME, [$with_msvcp_dll], [--with-msvcp-dll])
 594       if test "x$MSVC_DLL" = x; then
 595         AC_MSG_ERROR([Could not find a proper $MSVCP_NAME as specified by --with-msvcp-dll])
 596       fi
 597       MSVCP_DLL="$MSVC_DLL"
 598     elif test "x$DEVKIT_MSVCP_DLL" != x; then
 599       TOOLCHAIN_CHECK_POSSIBLE_MSVC_DLL($MSVCP_NAME, [$DEVKIT_MSVCP_DLL], [devkit])
 600       if test "x$MSVC_DLL" = x; then
 601         AC_MSG_ERROR([Could not find a proper $MSVCP_NAME as specified by devkit])
 602       fi  
 603       MSVCP_DLL="$MSVC_DLL"
 604     else
 605       TOOLCHAIN_SETUP_MSVC_DLL([${MSVCP_NAME}])
 606       MSVCP_DLL="$MSVC_DLL"
 607     fi
 608     AC_SUBST(MSVCP_DLL)
 609   fi
 610 ])