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 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT],
  27 [
  28   if test "x$VS_ENV_CMD" = x; then
  29     VS100BASE="$1"
  30     METHOD="$2"
  31     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(VS100BASE)
  32     if test -d "$VS100BASE"; then
  33       if test -f "$VS100BASE/$VCVARSFILE"; then
  34         AC_MSG_NOTICE([Found Visual Studio installation at $VS100BASE using $METHOD])
  35         VS_ENV_CMD="$VS100BASE/$VCVARSFILE"
  36       else
  37         AC_MSG_NOTICE([Found Visual Studio installation at $VS100BASE using $METHOD])
  38         AC_MSG_NOTICE([Warning: $VCVARSFILE is missing, this is probably Visual Studio Express. Ignoring])
  39       fi
  40     fi
  41   fi
  42 ])
  43 
  44 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT],
  45 [
  46   if test "x$VS_ENV_CMD" = x; then
  47     WIN_SDK_BASE="$1"
  48     METHOD="$2"
  49     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(WIN_SDK_BASE)
  50     if test -d "$WIN_SDK_BASE"; then
  51       # There have been cases of partial or broken SDK installations. A missing
  52       # lib dir is not going to work.
  53       if test ! -d "$WIN_SDK_BASE/../lib"; then
  54         AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
  55         AC_MSG_NOTICE([Warning: Installation is broken, lib dir is missing. Ignoring])
  56       elif test -f "$WIN_SDK_BASE/SetEnv.Cmd"; then
  57         AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
  58         VS_ENV_CMD="$WIN_SDK_BASE/SetEnv.Cmd"
  59         if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
  60           VS_ENV_ARGS="/x86"
  61         else
  62           VS_ENV_ARGS="/x64"
  63         fi
  64       else
  65         AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
  66         AC_MSG_NOTICE([Warning: Installation is broken, SetEnv.Cmd is missing. Ignoring])
  67       fi
  68     fi
  69   fi
  70 ])
  71 
  72 AC_DEFUN([TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE],
  73 [
  74   if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
  75     VCVARSFILE="vc/bin/vcvars32.bat"
  76   else
  77     VCVARSFILE="vc/bin/amd64/vcvars64.bat"
  78   fi
  79 
  80   VS_ENV_CMD=""
  81   VS_ENV_ARGS=""
  82   if test "x$with_toolsdir" != x; then
  83     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([$with_toolsdir/../..], [--with-tools-dir])
  84   fi
  85 
  86   if test "x$with_toolsdir" != x && test "x$VS_ENV_CMD" = x; then
  87     # Having specified an argument which is incorrect will produce an instant failure;
  88     # we should not go on looking
  89     AC_MSG_NOTICE([The path given by --with-tools-dir does not contain a valid Visual Studio installation])
  90     AC_MSG_NOTICE([Please point to the VC/bin directory within the Visual Studio installation])
  91     AC_MSG_ERROR([Cannot locate a valid Visual Studio installation])
  92   fi
  93 
  94   if test "x$VS100COMNTOOLS" != x; then
  95     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([$VS100COMNTOOLS/../..], [VS100COMNTOOLS variable])
  96   fi
  97   if test "x$PROGRAMFILES" != x; then
  98     TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([$PROGRAMFILES/Microsoft Visual Studio 10.0], [well-known name])
  99   fi
 100   TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([C:/Program Files/Microsoft Visual Studio 10.0], [well-known name])
 101   TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([C:/Program Files (x86)/Microsoft Visual Studio 10.0], [well-known name])
 102 
 103   if test "x$ProgramW6432" != x; then
 104     TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([$ProgramW6432/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
 105   fi
 106   if test "x$PROGRAMW6432" != x; then
 107     TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([$PROGRAMW6432/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
 108   fi
 109   if test "x$PROGRAMFILES" != x; then
 110     TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([$PROGRAMFILES/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
 111   fi
 112   TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([C:/Program Files/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
 113   TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
 114 ])
 115 
 116 # Check if the VS env variables were setup prior to running configure.
 117 # If not, then find vcvarsall.bat and run it automatically, and integrate
 118 # the set env variables into the spec file.
 119 AC_DEFUN([TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV],
 120 [
 121   # Store path to cygwin link.exe to help excluding it when searching for
 122   # VS linker. This must be done before changing the PATH when looking for VS.
 123   AC_PATH_PROG(CYGWIN_LINK, link)
 124   if test "x$CYGWIN_LINK" != x; then
 125     AC_MSG_CHECKING([if the first found link.exe is actually the Cygwin link tool])
 126     "$CYGWIN_LINK" --version > /dev/null
 127     if test $? -eq 0 ; then
 128       AC_MSG_RESULT([yes])
 129     else
 130       AC_MSG_RESULT([no])
 131       # This might be the VS linker. Don't exclude it later on.
 132       CYGWIN_LINK=""
 133     fi
 134   fi
 135 
 136   # First-hand choice is to locate and run the vsvars bat file.
 137   TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE
 138   if test "x$VS_ENV_CMD" != x; then
 139     # We have found a Visual Studio environment on disk, let's extract variables from the vsvars bat file.
 140     BASIC_FIXUP_EXECUTABLE(VS_ENV_CMD)
 141 
 142     # Lets extract the variables that are set by vcvarsall.bat/vsvars32.bat/vsvars64.bat
 143     AC_MSG_NOTICE([Trying to extract Visual Studio environment variables])
 144 
 145     # We need to create a couple of temporary files.
 146     VS_ENV_TMP_DIR="$OUTPUT_ROOT/tmp"
 147     $MKDIR -p $VS_ENV_TMP_DIR
 148 
 149     # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment).
 150     # Instead create a shell script which will set the relevant variables when run.
 151     WINPATH_VS_ENV_CMD="$VS_ENV_CMD"
 152     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_VS_ENV_CMD])
 153     WINPATH_BASH="$BASH"
 154     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_BASH])
 155 
 156     # Generate a DOS batch file which runs $VS_ENV_CMD, and then creates a shell
 157     # script (executable by bash) that will setup the important variables.
 158     EXTRACT_VC_ENV_BAT_FILE="$VS_ENV_TMP_DIR/extract_vs_env.bat"
 159     $ECHO "@echo off" >  $EXTRACT_VC_ENV_BAT_FILE
 160     # This will end up something like:
 161     # call C:/progra~2/micros~2.0/vc/bin/amd64/vcvars64.bat
 162     $ECHO "call $WINPATH_VS_ENV_CMD $VS_ENV_ARGS" >> $EXTRACT_VC_ENV_BAT_FILE
 163     # These will end up something like:
 164     # C:/CygWin/bin/bash -c 'echo VS_PATH=\"$PATH\" > localdevenv.sh
 165     # The trailing space for everyone except PATH is no typo, but is needed due
 166     # to trailing \ in the Windows paths. These will be stripped later.
 167     $ECHO "$WINPATH_BASH -c 'echo VS_PATH="'\"$PATH\" > set_vs_env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
 168     $ECHO "$WINPATH_BASH -c 'echo VS_INCLUDE="'\"$INCLUDE \" >> set_vs_env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
 169     $ECHO "$WINPATH_BASH -c 'echo VS_LIB="'\"$LIB \" >> set_vs_env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
 170     $ECHO "$WINPATH_BASH -c 'echo VCINSTALLDIR="'\"$VCINSTALLDIR \" >> set_vs_env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
 171     $ECHO "$WINPATH_BASH -c 'echo WindowsSdkDir="'\"$WindowsSdkDir \" >> set_vs_env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
 172     $ECHO "$WINPATH_BASH -c 'echo WINDOWSSDKDIR="'\"$WINDOWSSDKDIR \" >> set_vs_env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
 173 
 174     # Now execute the newly created bat file.
 175     # The | cat is to stop SetEnv.Cmd to mess with system colors on msys.
 176     # Change directory so we don't need to mess with Windows paths in redirects.
 177     cd $VS_ENV_TMP_DIR
 178     cmd /c extract_vs_env.bat | $CAT
 179     cd $CURDIR
 180 
 181     # Remove the generated batch file
 182     $RM $EXTRACT_VC_ENV_BAT_FILE
 183 
 184     if test ! -s $VS_ENV_TMP_DIR/set_vs_env.sh; then
 185       AC_MSG_NOTICE([Could not succesfully extract the envionment variables needed for the VS setup.])
 186       AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
 187       AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
 188       AC_MSG_ERROR([Cannot continue])
 189     fi
 190 
 191     # Now set all paths and other env variables. This will allow the rest of
 192     # the configure script to find and run the compiler in the proper way.
 193     AC_MSG_NOTICE([Setting extracted environment variables])
 194     . $VS_ENV_TMP_DIR/set_vs_env.sh
 195     # Now we have VS_PATH, VS_INCLUDE, VS_LIB. For further checking, we
 196     # also define VCINSTALLDIR, WindowsSdkDir and WINDOWSSDKDIR.
 197     # Remove the generated shell script
 198     $RM $VS_ENV_TMP_DIR/set_vs_env.sh
 199   else
 200     # We did not find a vsvars bat file, let's hope we are run from a VS command prompt.
 201     AC_MSG_NOTICE([Cannot locate a valid Visual Studio installation, checking current environment])
 202   fi
 203 
 204   # At this point, we should have corrent variables in the environment, or we can't continue.
 205   AC_MSG_CHECKING([for Visual Studio variables])
 206 
 207   if test "x$VCINSTALLDIR" != x || test "x$WindowsSDKDir" != x || test "x$WINDOWSSDKDIR" != x; then
 208     if test "x$VS_INCLUDE" = x || test "x$VS_LIB" = x; then
 209       AC_MSG_RESULT([present but broken])
 210       AC_MSG_ERROR([Your VC command prompt seems broken, INCLUDE and/or LIB is missing.])
 211     else
 212       AC_MSG_RESULT([ok])
 213       # Remove any trailing "\" and " " from the variables.
 214       VS_INCLUDE=`$ECHO "$VS_INCLUDE" | $SED 's/\\\\* *$//'`
 215       VS_LIB=`$ECHO "$VS_LIB" | $SED 's/\\\\* *$//'`
 216       VCINSTALLDIR=`$ECHO "$VCINSTALLDIR" | $SED 's/\\\\* *$//'`
 217       WindowsSDKDir=`$ECHO "$WindowsSDKDir" | $SED 's/\\\\* *$//'`
 218       WINDOWSSDKDIR=`$ECHO "$WINDOWSSDKDIR" | $SED 's/\\\\* *$//'`
 219 
 220       AC_SUBST(VS_PATH)
 221       AC_SUBST(VS_INCLUDE)
 222       AC_SUBST(VS_LIB)
 223     fi
 224   else
 225     AC_MSG_RESULT([not found])
 226 
 227     if test "x$VS_ENV_CMD" = x; then
 228       AC_MSG_NOTICE([Cannot locate a valid Visual Studio or Windows SDK installation on disk,])
 229       AC_MSG_NOTICE([nor is this script run from a Visual Studio command prompt.])
 230     else
 231       AC_MSG_NOTICE([Running the extraction script failed.])
 232     fi
 233     AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
 234     AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
 235     AC_MSG_ERROR([Cannot continue])
 236   fi
 237 ])
 238 
 239 AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL],
 240 [
 241   POSSIBLE_MSVCR_DLL="$1"
 242   METHOD="$2"
 243   if test -e "$POSSIBLE_MSVCR_DLL"; then
 244     AC_MSG_NOTICE([Found msvcr100.dll at $POSSIBLE_MSVCR_DLL using $METHOD])
 245     
 246     # Need to check if the found msvcr is correct architecture
 247     AC_MSG_CHECKING([found msvcr100.dll architecture])
 248     MSVCR_DLL_FILETYPE=`$FILE -b "$POSSIBLE_MSVCR_DLL"`
 249     if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
 250       CORRECT_MSVCR_ARCH=386
 251     else
 252       CORRECT_MSVCR_ARCH=x86-64
 253     fi
 254     if $ECHO "$MSVCR_DLL_FILETYPE" | $GREP $CORRECT_MSVCR_ARCH 2>&1 > /dev/null; then
 255       AC_MSG_RESULT([ok])
 256       MSVCR_DLL="$POSSIBLE_MSVCR_DLL"
 257       AC_MSG_CHECKING([for msvcr100.dll])
 258       AC_MSG_RESULT([$MSVCR_DLL])
 259     else
 260       AC_MSG_RESULT([incorrect, ignoring])
 261       AC_MSG_NOTICE([The file type of the located msvcr100.dll is $MSVCR_DLL_FILETYPE])
 262     fi
 263   fi
 264 ])
 265 
 266 AC_DEFUN([TOOLCHAIN_SETUP_MSVCR_DLL],
 267 [
 268   AC_ARG_WITH(msvcr-dll, [AS_HELP_STRING([--with-msvcr-dll],
 269       [copy this msvcr100.dll into the built JDK (Windows only) @<:@probed@:>@])])
 270 
 271   if test "x$with_msvcr_dll" != x; then
 272     # If given explicitely by user, do not probe. If not present, fail directly.
 273     TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$with_msvcr_dll], [--with-msvcr-dll])
 274     if test "x$MSVCR_DLL" = x; then
 275       AC_MSG_ERROR([Could not find a proper msvcr100.dll as specified by --with-msvcr-dll])
 276     fi
 277   fi
 278   
 279   if test "x$MSVCR_DLL" = x; then
 280     # Probe: Using well-known location from Visual Studio 10.0
 281     if test "x$VCINSTALLDIR" != x; then
 282       CYGWIN_VC_INSTALL_DIR="$VCINSTALLDIR"
 283       BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_VC_INSTALL_DIR)
 284       if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 285         POSSIBLE_MSVCR_DLL="$CYGWIN_VC_INSTALL_DIR/redist/x64/Microsoft.VC100.CRT/msvcr100.dll"
 286       else
 287         POSSIBLE_MSVCR_DLL="$CYGWIN_VC_INSTALL_DIR/redist/x86/Microsoft.VC100.CRT/msvcr100.dll"
 288       fi
 289       TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [well-known location in VCINSTALLDIR])
 290     fi
 291   fi
 292 
 293   if test "x$MSVCR_DLL" = x; then
 294     # Probe: Check in the Boot JDK directory.
 295     POSSIBLE_MSVCR_DLL="$BOOT_JDK/bin/msvcr100.dll"
 296     TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [well-known location in Boot JDK])
 297   fi
 298   
 299   if test "x$MSVCR_DLL" = x; then
 300     # Probe: Look in the Windows system32 directory 
 301     CYGWIN_SYSTEMROOT="$SYSTEMROOT"
 302     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_SYSTEMROOT)
 303     POSSIBLE_MSVCR_DLL="$CYGWIN_SYSTEMROOT/system32/msvcr100.dll"
 304     TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [well-known location in SYSTEMROOT])
 305   fi
 306 
 307   if test "x$MSVCR_DLL" = x; then
 308     # Probe: If Visual Studio Express is installed, there is usually one with the debugger
 309     if test "x$VS100COMNTOOLS" != x; then
 310       CYGWIN_VS_TOOLS_DIR="$VS100COMNTOOLS/.."
 311       BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_VS_TOOLS_DIR)
 312       if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 313         POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name msvcr100.dll | $GREP -i /x64/ | $HEAD --lines 1`
 314       else
 315         POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name msvcr100.dll | $GREP -i /x86/ | $HEAD --lines 1`
 316       fi
 317       TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [search of VS100COMNTOOLS])
 318     fi
 319   fi
 320       
 321   if test "x$MSVCR_DLL" = x; then
 322     # Probe: Search wildly in the VCINSTALLDIR. We've probably lost by now.
 323     # (This was the original behaviour; kept since it might turn up something)
 324     if test "x$CYGWIN_VC_INSTALL_DIR" != x; then
 325       if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 326         POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name msvcr100.dll | $GREP x64 | $HEAD --lines 1`
 327       else
 328         POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name msvcr100.dll | $GREP x86 | $GREP -v ia64 | $GREP -v x64 | $HEAD --lines 1`
 329         if test "x$POSSIBLE_MSVCR_DLL" = x; then
 330           # We're grasping at straws now...
 331           POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name msvcr100.dll | $HEAD --lines 1`
 332         fi
 333       fi
 334       
 335       TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [search of VCINSTALLDIR])
 336     fi
 337   fi
 338   
 339   if test "x$MSVCR_DLL" = x; then
 340     AC_MSG_CHECKING([for msvcr100.dll])
 341     AC_MSG_RESULT([no])
 342     AC_MSG_ERROR([Could not find msvcr100.dll. Please specify using --with-msvcr-dll.])
 343   fi
 344 
 345   BASIC_FIXUP_PATH(MSVCR_DLL)
 346 ])