common/autoconf/toolchain_windows.m4

Print this page

        

@@ -139,83 +139,89 @@
     # We have found a Visual Studio environment on disk, let's extract variables from the vsvars bat file.
     BASIC_FIXUP_EXECUTABLE(VS_ENV_CMD)
 
     # Lets extract the variables that are set by vcvarsall.bat/vsvars32.bat/vsvars64.bat
     AC_MSG_NOTICE([Trying to extract Visual Studio environment variables])
-    cd $OUTPUT_ROOT
-    # FIXME: The code betweeen ---- was inlined from a separate script and is not properly adapted
-    # to autoconf standards.
-
-    #----
-
-    # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment)
-    # but calculate the difference in Cygwin environment before/after running it and then
-    # apply the diff.
-
-    if test "x$OPENJDK_BUILD_OS_ENV" = xwindows.cygwin; then
-      _vs10varsall=`cygpath -a -m -s "$VS_ENV_CMD"`
-      _dosvs10varsall=`cygpath -a -w -s $_vs10varsall`
-      _dosbash=`cygpath -a -w -s \`which bash\`.*`
-    else
-      _dosvs10varsall=`cmd //c echo $VS_ENV_CMD`
-      _dosbash=`cmd //c echo \`which bash\``
-    fi
 
-    # generate the set of exported vars before/after the vs10 setup
-    $ECHO "@echo off"                                           >  localdevenvtmp.bat
-    $ECHO "$_dosbash -c \"export -p\" > localdevenvtmp.export0" >> localdevenvtmp.bat
-    $ECHO "call $_dosvs10varsall $VS_ENV_ARGS"                  >> localdevenvtmp.bat
-    $ECHO "$_dosbash -c \"export -p\" > localdevenvtmp.export1" >> localdevenvtmp.bat
+    # We need to create a couple of temporary files.
+    VS_ENV_TMP_DIR="$OUTPUT_ROOT/tmp"
+    $MKDIR -p $VS_ENV_TMP_DIR
+
+    # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment).
+    # Instead create a shell script which will set the relevant variables when run.
+    WINPATH_VS_ENV_CMD="$VS_ENV_CMD"
+    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_VS_ENV_CMD])
+    WINPATH_BASH="$BASH"
+    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_BASH])
+
+    # Generate a DOS batch file which runs $VS_ENV_CMD, and then creates a shell
+    # script (executable by bash) that will setup the important variables.
+    EXTRACT_VC_ENV_BAT_FILE="$VS_ENV_TMP_DIR/extract_vs_env.bat"
+    $ECHO "@echo off" >  $EXTRACT_VC_ENV_BAT_FILE
+    # This will end up something like:
+    # call C:/progra~2/micros~2.0/vc/bin/amd64/vcvars64.bat
+    $ECHO "call $WINPATH_VS_ENV_CMD $VS_ENV_ARGS" >> $EXTRACT_VC_ENV_BAT_FILE
+    # These will end up something like:
+    # C:/CygWin/bin/bash -c 'echo VS_PATH=\"$PATH\" > localdevenv.sh
+    # The trailing space for everyone except PATH is no typo, but is needed due
+    # to trailing \ in the Windows paths. These will be stripped later.
+    $ECHO "$WINPATH_BASH -c 'echo VS_PATH="'\"$PATH\" > set_vs_env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
+    $ECHO "$WINPATH_BASH -c 'echo VS_INCLUDE="'\"$INCLUDE \" >> set_vs_env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
+    $ECHO "$WINPATH_BASH -c 'echo VS_LIB="'\"$LIB \" >> set_vs_env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
+    $ECHO "$WINPATH_BASH -c 'echo VCINSTALLDIR="'\"$VCINSTALLDIR \" >> set_vs_env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
+    $ECHO "$WINPATH_BASH -c 'echo WindowsSdkDir="'\"$WindowsSdkDir \" >> set_vs_env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
+    $ECHO "$WINPATH_BASH -c 'echo WINDOWSSDKDIR="'\"$WINDOWSSDKDIR \" >> set_vs_env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
 
     # Now execute the newly created bat file.
-    # The | cat is to stop SetEnv.Cmd to mess with system colors on msys
-    cmd /c localdevenvtmp.bat | cat
-
-    # apply the diff (less some non-vs10 vars named by "!")
-    $SORT localdevenvtmp.export0 | $GREP -v "!" > localdevenvtmp.export0.sort
-    $SORT localdevenvtmp.export1 | $GREP -v "!" > localdevenvtmp.export1.sort
-    $COMM -1 -3 localdevenvtmp.export0.sort localdevenvtmp.export1.sort > localdevenv.sh
-
-    # cleanup
-    $RM localdevenvtmp*
-    #----
+    # The | cat is to stop SetEnv.Cmd to mess with system colors on msys.
+    # Change directory so we don't need to mess with Windows paths in redirects.
+    cd $VS_ENV_TMP_DIR
+    cmd /c extract_vs_env.bat | $CAT
     cd $CURDIR
-    if test ! -s $OUTPUT_ROOT/localdevenv.sh; then
-      AC_MSG_RESULT([no])
+
+    # Remove the generated batch file
+    $RM $EXTRACT_VC_ENV_BAT_FILE
+
+    if test ! -s $VS_ENV_TMP_DIR/set_vs_env.sh; then
       AC_MSG_NOTICE([Could not succesfully extract the envionment variables needed for the VS setup.])
       AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
       AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
       AC_MSG_ERROR([Cannot continue])
     fi
 
     # Now set all paths and other env variables. This will allow the rest of
     # the configure script to find and run the compiler in the proper way.
     AC_MSG_NOTICE([Setting extracted environment variables])
-    . $OUTPUT_ROOT/localdevenv.sh
+    . $VS_ENV_TMP_DIR/set_vs_env.sh
+    # Now we have VS_PATH, VS_INCLUDE, VS_LIB. For further checking, we
+    # also define VCINSTALLDIR, WindowsSdkDir and WINDOWSSDKDIR.
+    # Remove the generated shell script
+    $RM $VS_ENV_TMP_DIR/set_vs_env.sh
   else
     # We did not find a vsvars bat file, let's hope we are run from a VS command prompt.
     AC_MSG_NOTICE([Cannot locate a valid Visual Studio installation, checking current environment])
   fi
 
   # At this point, we should have corrent variables in the environment, or we can't continue.
   AC_MSG_CHECKING([for Visual Studio variables])
 
   if test "x$VCINSTALLDIR" != x || test "x$WindowsSDKDir" != x || test "x$WINDOWSSDKDIR" != x; then
-    if test "x$INCLUDE" = x || test "x$LIB" = x; then
+    if test "x$VS_INCLUDE" = x || test "x$VS_LIB" = x; then
       AC_MSG_RESULT([present but broken])
       AC_MSG_ERROR([Your VC command prompt seems broken, INCLUDE and/or LIB is missing.])
     else
       AC_MSG_RESULT([ok])
-      # Remove any trailing \ from INCLUDE and LIB to avoid trouble in spec.gmk.
-      VS_INCLUDE=`$ECHO "$INCLUDE" | $SED 's/\\\\$//'`
-      VS_LIB=`$ECHO "$LIB" | $SED 's/\\\\$//'`
-      # Remove any paths containing # (typically F#) as that messes up make
-      PATH=`$ECHO "$PATH" | $SED 's/[[^:#]]*#[^:]*://g'`
-      VS_PATH="$PATH"
+      # Remove any trailing "\" and " " from the variables.
+      VS_INCLUDE=`$ECHO "$VS_INCLUDE" | $SED 's/\\\\* *$//'`
+      VS_LIB=`$ECHO "$VS_LIB" | $SED 's/\\\\* *$//'`
+      VCINSTALLDIR=`$ECHO "$VCINSTALLDIR" | $SED 's/\\\\* *$//'`
+      WindowsSDKDir=`$ECHO "$WindowsSDKDir" | $SED 's/\\\\* *$//'`
+      WINDOWSSDKDIR=`$ECHO "$WINDOWSSDKDIR" | $SED 's/\\\\* *$//'`
+
+      AC_SUBST(VS_PATH)
       AC_SUBST(VS_INCLUDE)
       AC_SUBST(VS_LIB)
-      AC_SUBST(VS_PATH)
     fi
   else
     AC_MSG_RESULT([not found])
 
     if test "x$VS_ENV_CMD" = x; then