common/autoconf/toolchain_windows.m4

changeset 0
75a576e87639
child 1133
50aaf272884f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/common/autoconf/toolchain_windows.m4	Wed Apr 27 01:39:08 2016 +0800
     1.3 @@ -0,0 +1,340 @@
     1.4 +#
     1.5 +# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 +#
     1.8 +# This code is free software; you can redistribute it and/or modify it
     1.9 +# under the terms of the GNU General Public License version 2 only, as
    1.10 +# published by the Free Software Foundation.  Oracle designates this
    1.11 +# particular file as subject to the "Classpath" exception as provided
    1.12 +# by Oracle in the LICENSE file that accompanied this code.
    1.13 +#
    1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 +# version 2 for more details (a copy is included in the LICENSE file that
    1.18 +# accompanied this code).
    1.19 +#
    1.20 +# You should have received a copy of the GNU General Public License version
    1.21 +# 2 along with this work; if not, write to the Free Software Foundation,
    1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 +#
    1.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 +# or visit www.oracle.com if you need additional information or have any
    1.26 +# questions.
    1.27 +#
    1.28 +
    1.29 +AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT],
    1.30 +[
    1.31 +  if test "x$VS_ENV_CMD" = x; then
    1.32 +    VS100BASE="$1"
    1.33 +    METHOD="$2"
    1.34 +    BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(VS100BASE)
    1.35 +    if test -d "$VS100BASE"; then
    1.36 +      if test -f "$VS100BASE/$VCVARSFILE"; then
    1.37 +        AC_MSG_NOTICE([Found Visual Studio installation at $VS100BASE using $METHOD])
    1.38 +        VS_ENV_CMD="$VS100BASE/$VCVARSFILE"
    1.39 +      else
    1.40 +        AC_MSG_NOTICE([Found Visual Studio installation at $VS100BASE using $METHOD])
    1.41 +        AC_MSG_NOTICE([Warning: $VCVARSFILE is missing, this is probably Visual Studio Express. Ignoring])
    1.42 +      fi
    1.43 +    fi
    1.44 +  fi
    1.45 +])
    1.46 +
    1.47 +AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT],
    1.48 +[
    1.49 +  if test "x$VS_ENV_CMD" = x; then
    1.50 +    WIN_SDK_BASE="$1"
    1.51 +    METHOD="$2"
    1.52 +    BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(WIN_SDK_BASE)
    1.53 +    if test -d "$WIN_SDK_BASE"; then
    1.54 +      # There have been cases of partial or broken SDK installations. A missing
    1.55 +      # lib dir is not going to work.
    1.56 +      if test ! -d "$WIN_SDK_BASE/../lib"; then
    1.57 +        AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
    1.58 +        AC_MSG_NOTICE([Warning: Installation is broken, lib dir is missing. Ignoring])
    1.59 +      elif test -f "$WIN_SDK_BASE/SetEnv.Cmd"; then
    1.60 +        AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
    1.61 +        VS_ENV_CMD="$WIN_SDK_BASE/SetEnv.Cmd"
    1.62 +        if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
    1.63 +          VS_ENV_ARGS="/x86"
    1.64 +        else
    1.65 +          VS_ENV_ARGS="/x64"
    1.66 +        fi
    1.67 +      else
    1.68 +        AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
    1.69 +        AC_MSG_NOTICE([Warning: Installation is broken, SetEnv.Cmd is missing. Ignoring])
    1.70 +      fi
    1.71 +    fi
    1.72 +  fi
    1.73 +])
    1.74 +
    1.75 +AC_DEFUN([TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE],
    1.76 +[
    1.77 +  if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
    1.78 +    VCVARSFILE="vc/bin/vcvars32.bat"
    1.79 +  else
    1.80 +    VCVARSFILE="vc/bin/amd64/vcvars64.bat"
    1.81 +  fi
    1.82 +
    1.83 +  VS_ENV_CMD=""
    1.84 +  VS_ENV_ARGS=""
    1.85 +  if test "x$with_toolsdir" != x; then
    1.86 +    TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([$with_toolsdir/../..], [--with-tools-dir])
    1.87 +  fi
    1.88 +
    1.89 +  if test "x$with_toolsdir" != x && test "x$VS_ENV_CMD" = x; then
    1.90 +    # Having specified an argument which is incorrect will produce an instant failure;
    1.91 +    # we should not go on looking
    1.92 +    AC_MSG_NOTICE([The path given by --with-tools-dir does not contain a valid Visual Studio installation])
    1.93 +    AC_MSG_NOTICE([Please point to the VC/bin directory within the Visual Studio installation])
    1.94 +    AC_MSG_ERROR([Cannot locate a valid Visual Studio installation])
    1.95 +  fi
    1.96 +
    1.97 +  if test "x$VS100COMNTOOLS" != x; then
    1.98 +    TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([$VS100COMNTOOLS/../..], [VS100COMNTOOLS variable])
    1.99 +  fi
   1.100 +  if test "x$PROGRAMFILES" != x; then
   1.101 +    TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([$PROGRAMFILES/Microsoft Visual Studio 10.0], [well-known name])
   1.102 +  fi
   1.103 +  TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([C:/Program Files/Microsoft Visual Studio 10.0], [well-known name])
   1.104 +  TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([C:/Program Files (x86)/Microsoft Visual Studio 10.0], [well-known name])
   1.105 +
   1.106 +  if test "x$ProgramW6432" != x; then
   1.107 +    TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([$ProgramW6432/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
   1.108 +  fi
   1.109 +  if test "x$PROGRAMW6432" != x; then
   1.110 +    TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([$PROGRAMW6432/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
   1.111 +  fi
   1.112 +  if test "x$PROGRAMFILES" != x; then
   1.113 +    TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([$PROGRAMFILES/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
   1.114 +  fi
   1.115 +  TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([C:/Program Files/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
   1.116 +  TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
   1.117 +])
   1.118 +
   1.119 +# Check if the VS env variables were setup prior to running configure.
   1.120 +# If not, then find vcvarsall.bat and run it automatically, and integrate
   1.121 +# the set env variables into the spec file.
   1.122 +AC_DEFUN([TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV],
   1.123 +[
   1.124 +  # Store path to cygwin link.exe to help excluding it when searching for
   1.125 +  # VS linker. This must be done before changing the PATH when looking for VS.
   1.126 +  AC_PATH_PROG(CYGWIN_LINK, link)
   1.127 +  if test "x$CYGWIN_LINK" != x; then
   1.128 +    AC_MSG_CHECKING([if the first found link.exe is actually the Cygwin link tool])
   1.129 +    "$CYGWIN_LINK" --version > /dev/null
   1.130 +    if test $? -eq 0 ; then
   1.131 +      AC_MSG_RESULT([yes])
   1.132 +    else
   1.133 +      AC_MSG_RESULT([no])
   1.134 +      # This might be the VS linker. Don't exclude it later on.
   1.135 +      CYGWIN_LINK=""
   1.136 +    fi
   1.137 +  fi
   1.138 +
   1.139 +  # First-hand choice is to locate and run the vsvars bat file.
   1.140 +  TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE
   1.141 +  if test "x$VS_ENV_CMD" != x; then
   1.142 +    # We have found a Visual Studio environment on disk, let's extract variables from the vsvars bat file.
   1.143 +    BASIC_FIXUP_EXECUTABLE(VS_ENV_CMD)
   1.144 +
   1.145 +    # Lets extract the variables that are set by vcvarsall.bat/vsvars32.bat/vsvars64.bat
   1.146 +    AC_MSG_NOTICE([Trying to extract Visual Studio environment variables])
   1.147 +    cd $OUTPUT_ROOT
   1.148 +    # FIXME: The code betweeen ---- was inlined from a separate script and is not properly adapted
   1.149 +    # to autoconf standards.
   1.150 +
   1.151 +    #----
   1.152 +
   1.153 +    # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment)
   1.154 +    # but calculate the difference in Cygwin environment before/after running it and then
   1.155 +    # apply the diff.
   1.156 +
   1.157 +    if test "x$OPENJDK_BUILD_OS_ENV" = xwindows.cygwin; then
   1.158 +      _vs10varsall=`cygpath -a -m -s "$VS_ENV_CMD"`
   1.159 +      _dosvs10varsall=`cygpath -a -w -s $_vs10varsall`
   1.160 +      _dosbash=`cygpath -a -w -s \`which bash\`.*`
   1.161 +    else
   1.162 +      _dosvs10varsall=`cmd //c echo $VS_ENV_CMD`
   1.163 +      _dosbash=`cmd //c echo \`which bash\``
   1.164 +    fi
   1.165 +
   1.166 +    # generate the set of exported vars before/after the vs10 setup
   1.167 +    $ECHO "@echo off"                                           >  localdevenvtmp.bat
   1.168 +    $ECHO "$_dosbash -c \"export -p\" > localdevenvtmp.export0" >> localdevenvtmp.bat
   1.169 +    $ECHO "call $_dosvs10varsall $VS_ENV_ARGS"                  >> localdevenvtmp.bat
   1.170 +    $ECHO "$_dosbash -c \"export -p\" > localdevenvtmp.export1" >> localdevenvtmp.bat
   1.171 +
   1.172 +    # Now execute the newly created bat file.
   1.173 +    # The | cat is to stop SetEnv.Cmd to mess with system colors on msys
   1.174 +    cmd /c localdevenvtmp.bat | cat
   1.175 +
   1.176 +    # apply the diff (less some non-vs10 vars named by "!")
   1.177 +    $SORT localdevenvtmp.export0 | $GREP -v "!" > localdevenvtmp.export0.sort
   1.178 +    $SORT localdevenvtmp.export1 | $GREP -v "!" > localdevenvtmp.export1.sort
   1.179 +    $COMM -1 -3 localdevenvtmp.export0.sort localdevenvtmp.export1.sort > localdevenv.sh
   1.180 +
   1.181 +    # cleanup
   1.182 +    $RM localdevenvtmp*
   1.183 +    #----
   1.184 +    cd $CURDIR
   1.185 +    if test ! -s $OUTPUT_ROOT/localdevenv.sh; then
   1.186 +      AC_MSG_RESULT([no])
   1.187 +      AC_MSG_NOTICE([Could not succesfully extract the envionment variables needed for the VS setup.])
   1.188 +      AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
   1.189 +      AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
   1.190 +      AC_MSG_ERROR([Cannot continue])
   1.191 +    fi
   1.192 +
   1.193 +    # Now set all paths and other env variables. This will allow the rest of
   1.194 +    # the configure script to find and run the compiler in the proper way.
   1.195 +    AC_MSG_NOTICE([Setting extracted environment variables])
   1.196 +    . $OUTPUT_ROOT/localdevenv.sh
   1.197 +  else
   1.198 +    # We did not find a vsvars bat file, let's hope we are run from a VS command prompt.
   1.199 +    AC_MSG_NOTICE([Cannot locate a valid Visual Studio installation, checking current environment])
   1.200 +  fi
   1.201 +
   1.202 +  # At this point, we should have corrent variables in the environment, or we can't continue.
   1.203 +  AC_MSG_CHECKING([for Visual Studio variables])
   1.204 +
   1.205 +  if test "x$VCINSTALLDIR" != x || test "x$WindowsSDKDir" != x || test "x$WINDOWSSDKDIR" != x; then
   1.206 +    if test "x$INCLUDE" = x || test "x$LIB" = x; then
   1.207 +      AC_MSG_RESULT([present but broken])
   1.208 +      AC_MSG_ERROR([Your VC command prompt seems broken, INCLUDE and/or LIB is missing.])
   1.209 +    else
   1.210 +      AC_MSG_RESULT([ok])
   1.211 +      # Remove any trailing \ from INCLUDE and LIB to avoid trouble in spec.gmk.
   1.212 +      VS_INCLUDE=`$ECHO "$INCLUDE" | $SED 's/\\\\$//'`
   1.213 +      VS_LIB=`$ECHO "$LIB" | $SED 's/\\\\$//'`
   1.214 +      # Remove any paths containing # (typically F#) as that messes up make
   1.215 +      PATH=`$ECHO "$PATH" | $SED 's/[[^:#]]*#[^:]*://g'`
   1.216 +      VS_PATH="$PATH"
   1.217 +      AC_SUBST(VS_INCLUDE)
   1.218 +      AC_SUBST(VS_LIB)
   1.219 +      AC_SUBST(VS_PATH)
   1.220 +    fi
   1.221 +  else
   1.222 +    AC_MSG_RESULT([not found])
   1.223 +
   1.224 +    if test "x$VS_ENV_CMD" = x; then
   1.225 +      AC_MSG_NOTICE([Cannot locate a valid Visual Studio or Windows SDK installation on disk,])
   1.226 +      AC_MSG_NOTICE([nor is this script run from a Visual Studio command prompt.])
   1.227 +    else
   1.228 +      AC_MSG_NOTICE([Running the extraction script failed.])
   1.229 +    fi
   1.230 +    AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
   1.231 +    AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
   1.232 +    AC_MSG_ERROR([Cannot continue])
   1.233 +  fi
   1.234 +])
   1.235 +
   1.236 +AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL],
   1.237 +[
   1.238 +  POSSIBLE_MSVCR_DLL="$1"
   1.239 +  METHOD="$2"
   1.240 +  if test -e "$POSSIBLE_MSVCR_DLL"; then
   1.241 +    AC_MSG_NOTICE([Found msvcr100.dll at $POSSIBLE_MSVCR_DLL using $METHOD])
   1.242 +    
   1.243 +    # Need to check if the found msvcr is correct architecture
   1.244 +    AC_MSG_CHECKING([found msvcr100.dll architecture])
   1.245 +    MSVCR_DLL_FILETYPE=`$FILE -b "$POSSIBLE_MSVCR_DLL"`
   1.246 +    if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
   1.247 +      CORRECT_MSVCR_ARCH=386
   1.248 +    else
   1.249 +      CORRECT_MSVCR_ARCH=x86-64
   1.250 +    fi
   1.251 +    if $ECHO "$MSVCR_DLL_FILETYPE" | $GREP $CORRECT_MSVCR_ARCH 2>&1 > /dev/null; then
   1.252 +      AC_MSG_RESULT([ok])
   1.253 +      MSVCR_DLL="$POSSIBLE_MSVCR_DLL"
   1.254 +      AC_MSG_CHECKING([for msvcr100.dll])
   1.255 +      AC_MSG_RESULT([$MSVCR_DLL])
   1.256 +    else
   1.257 +      AC_MSG_RESULT([incorrect, ignoring])
   1.258 +      AC_MSG_NOTICE([The file type of the located msvcr100.dll is $MSVCR_DLL_FILETYPE])
   1.259 +    fi
   1.260 +  fi
   1.261 +])
   1.262 +
   1.263 +AC_DEFUN([TOOLCHAIN_SETUP_MSVCR_DLL],
   1.264 +[
   1.265 +  AC_ARG_WITH(msvcr-dll, [AS_HELP_STRING([--with-msvcr-dll],
   1.266 +      [copy this msvcr100.dll into the built JDK (Windows only) @<:@probed@:>@])])
   1.267 +
   1.268 +  if test "x$with_msvcr_dll" != x; then
   1.269 +    # If given explicitely by user, do not probe. If not present, fail directly.
   1.270 +    TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$with_msvcr_dll], [--with-msvcr-dll])
   1.271 +    if test "x$MSVCR_DLL" = x; then
   1.272 +      AC_MSG_ERROR([Could not find a proper msvcr100.dll as specified by --with-msvcr-dll])
   1.273 +    fi
   1.274 +  fi
   1.275 +  
   1.276 +  if test "x$MSVCR_DLL" = x; then
   1.277 +    # Probe: Using well-known location from Visual Studio 10.0
   1.278 +    if test "x$VCINSTALLDIR" != x; then
   1.279 +      CYGWIN_VC_INSTALL_DIR="$VCINSTALLDIR"
   1.280 +      BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_VC_INSTALL_DIR)
   1.281 +      if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
   1.282 +        POSSIBLE_MSVCR_DLL="$CYGWIN_VC_INSTALL_DIR/redist/x64/Microsoft.VC100.CRT/msvcr100.dll"
   1.283 +      else
   1.284 +        POSSIBLE_MSVCR_DLL="$CYGWIN_VC_INSTALL_DIR/redist/x86/Microsoft.VC100.CRT/msvcr100.dll"
   1.285 +      fi
   1.286 +      TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [well-known location in VCINSTALLDIR])
   1.287 +    fi
   1.288 +  fi
   1.289 +
   1.290 +  if test "x$MSVCR_DLL" = x; then
   1.291 +    # Probe: Check in the Boot JDK directory.
   1.292 +    POSSIBLE_MSVCR_DLL="$BOOT_JDK/bin/msvcr100.dll"
   1.293 +    TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [well-known location in Boot JDK])
   1.294 +  fi
   1.295 +  
   1.296 +  if test "x$MSVCR_DLL" = x; then
   1.297 +    # Probe: Look in the Windows system32 directory 
   1.298 +    CYGWIN_SYSTEMROOT="$SYSTEMROOT"
   1.299 +    BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_SYSTEMROOT)
   1.300 +    POSSIBLE_MSVCR_DLL="$CYGWIN_SYSTEMROOT/system32/msvcr100.dll"
   1.301 +    TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [well-known location in SYSTEMROOT])
   1.302 +  fi
   1.303 +
   1.304 +  if test "x$MSVCR_DLL" = x; then
   1.305 +    # Probe: If Visual Studio Express is installed, there is usually one with the debugger
   1.306 +    if test "x$VS100COMNTOOLS" != x; then
   1.307 +      CYGWIN_VS_TOOLS_DIR="$VS100COMNTOOLS/.."
   1.308 +      BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_VS_TOOLS_DIR)
   1.309 +      if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
   1.310 +        POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name msvcr100.dll | $GREP -i /x64/ | $HEAD --lines 1`
   1.311 +      else
   1.312 +        POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name msvcr100.dll | $GREP -i /x86/ | $HEAD --lines 1`
   1.313 +      fi
   1.314 +      TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [search of VS100COMNTOOLS])
   1.315 +    fi
   1.316 +  fi
   1.317 +      
   1.318 +  if test "x$MSVCR_DLL" = x; then
   1.319 +    # Probe: Search wildly in the VCINSTALLDIR. We've probably lost by now.
   1.320 +    # (This was the original behaviour; kept since it might turn up something)
   1.321 +    if test "x$CYGWIN_VC_INSTALL_DIR" != x; then
   1.322 +      if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
   1.323 +        POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name msvcr100.dll | $GREP x64 | $HEAD --lines 1`
   1.324 +      else
   1.325 +        POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name msvcr100.dll | $GREP x86 | $GREP -v ia64 | $GREP -v x64 | $HEAD --lines 1`
   1.326 +        if test "x$POSSIBLE_MSVCR_DLL" = x; then
   1.327 +          # We're grasping at straws now...
   1.328 +          POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name msvcr100.dll | $HEAD --lines 1`
   1.329 +        fi
   1.330 +      fi
   1.331 +      
   1.332 +      TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [search of VCINSTALLDIR])
   1.333 +    fi
   1.334 +  fi
   1.335 +  
   1.336 +  if test "x$MSVCR_DLL" = x; then
   1.337 +    AC_MSG_CHECKING([for msvcr100.dll])
   1.338 +    AC_MSG_RESULT([no])
   1.339 +    AC_MSG_ERROR([Could not find msvcr100.dll. Please specify using --with-msvcr-dll.])
   1.340 +  fi
   1.341 +
   1.342 +  BASIC_FIXUP_PATH(MSVCR_DLL)
   1.343 +])

mercurial