common/autoconf/toolchain_windows.m4

changeset 2208
feba63b3fa36
parent 857
5b4f14990dd1
child 2209
cddffb220808
     1.1 --- a/common/autoconf/toolchain_windows.m4	Thu Apr 05 08:14:51 2018 -0700
     1.2 +++ b/common/autoconf/toolchain_windows.m4	Fri Apr 06 04:13:09 2018 -0700
     1.3 @@ -141,46 +141,44 @@
     1.4  
     1.5      # Lets extract the variables that are set by vcvarsall.bat/vsvars32.bat/vsvars64.bat
     1.6      AC_MSG_NOTICE([Trying to extract Visual Studio environment variables])
     1.7 -    cd $OUTPUT_ROOT
     1.8 -    # FIXME: The code betweeen ---- was inlined from a separate script and is not properly adapted
     1.9 -    # to autoconf standards.
    1.10  
    1.11 -    #----
    1.12 +    # We need to create a couple of temporary files.
    1.13 +    VS_ENV_TMP_DIR="$OUTPUT_ROOT/vs-env"
    1.14 +    $MKDIR -p $VS_ENV_TMP_DIR
    1.15  
    1.16 -    # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment)
    1.17 -    # but calculate the difference in Cygwin environment before/after running it and then
    1.18 -    # apply the diff.
    1.19 +    # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment).
    1.20 +    # Instead create a shell script which will set the relevant variables when run.
    1.21 +    WINPATH_VS_ENV_CMD="$VS_ENV_CMD"
    1.22 +    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_VS_ENV_CMD])
    1.23 +    WINPATH_BASH="$BASH"
    1.24 +    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_BASH])
    1.25  
    1.26 -    if test "x$OPENJDK_BUILD_OS_ENV" = xwindows.cygwin; then
    1.27 -      _vs10varsall=`cygpath -a -m -s "$VS_ENV_CMD"`
    1.28 -      _dosvs10varsall=`cygpath -a -w -s $_vs10varsall`
    1.29 -      _dosbash=`cygpath -a -w -s \`which bash\`.*`
    1.30 -    else
    1.31 -      _dosvs10varsall=`cmd //c echo $VS_ENV_CMD`
    1.32 -      _dosbash=`cmd //c echo \`which bash\``
    1.33 -    fi
    1.34 -
    1.35 -    # generate the set of exported vars before/after the vs10 setup
    1.36 -    $ECHO "@echo off"                                           >  localdevenvtmp.bat
    1.37 -    $ECHO "$_dosbash -c \"export -p\" > localdevenvtmp.export0" >> localdevenvtmp.bat
    1.38 -    $ECHO "call $_dosvs10varsall $VS_ENV_ARGS"                  >> localdevenvtmp.bat
    1.39 -    $ECHO "$_dosbash -c \"export -p\" > localdevenvtmp.export1" >> localdevenvtmp.bat
    1.40 +    # Generate a DOS batch file which runs $VS_ENV_CMD, and then creates a shell
    1.41 +    # script (executable by bash) that will setup the important variables.
    1.42 +    EXTRACT_VC_ENV_BAT_FILE="$VS_ENV_TMP_DIR/extract-vs-env.bat"
    1.43 +    $ECHO "@echo off" >  $EXTRACT_VC_ENV_BAT_FILE
    1.44 +    # This will end up something like:
    1.45 +    # call C:/progra~2/micros~2.0/vc/bin/amd64/vcvars64.bat
    1.46 +    $ECHO "call $WINPATH_VS_ENV_CMD $VS_ENV_ARGS" >> $EXTRACT_VC_ENV_BAT_FILE
    1.47 +    # These will end up something like:
    1.48 +    # C:/CygWin/bin/bash -c 'echo VS_PATH=\"$PATH\" > localdevenv.sh
    1.49 +    # The trailing space for everyone except PATH is no typo, but is needed due
    1.50 +    # to trailing \ in the Windows paths. These will be stripped later.
    1.51 +    $ECHO "$WINPATH_BASH -c 'echo VS_PATH="'\"$PATH\" > set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
    1.52 +    $ECHO "$WINPATH_BASH -c 'echo VS_INCLUDE="'\"$INCLUDE \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
    1.53 +    $ECHO "$WINPATH_BASH -c 'echo VS_LIB="'\"$LIB \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
    1.54 +    $ECHO "$WINPATH_BASH -c 'echo VCINSTALLDIR="'\"$VCINSTALLDIR \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
    1.55 +    $ECHO "$WINPATH_BASH -c 'echo WindowsSdkDir="'\"$WindowsSdkDir \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
    1.56 +    $ECHO "$WINPATH_BASH -c 'echo WINDOWSSDKDIR="'\"$WINDOWSSDKDIR \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
    1.57  
    1.58      # Now execute the newly created bat file.
    1.59 -    # The | cat is to stop SetEnv.Cmd to mess with system colors on msys
    1.60 -    cmd /c localdevenvtmp.bat | cat
    1.61 +    # The | cat is to stop SetEnv.Cmd to mess with system colors on msys.
    1.62 +    # Change directory so we don't need to mess with Windows paths in redirects.
    1.63 +    cd $VS_ENV_TMP_DIR
    1.64 +    cmd /c extract-vs-env.bat | $CAT
    1.65 +    cd $CURDIR
    1.66  
    1.67 -    # apply the diff (less some non-vs10 vars named by "!")
    1.68 -    $SORT localdevenvtmp.export0 | $GREP -v "!" > localdevenvtmp.export0.sort
    1.69 -    $SORT localdevenvtmp.export1 | $GREP -v "!" > localdevenvtmp.export1.sort
    1.70 -    $COMM -1 -3 localdevenvtmp.export0.sort localdevenvtmp.export1.sort > localdevenv.sh
    1.71 -
    1.72 -    # cleanup
    1.73 -    $RM localdevenvtmp*
    1.74 -    #----
    1.75 -    cd $CURDIR
    1.76 -    if test ! -s $OUTPUT_ROOT/localdevenv.sh; then
    1.77 -      AC_MSG_RESULT([no])
    1.78 +    if test ! -s $VS_ENV_TMP_DIR/set-vs-env.sh; then
    1.79        AC_MSG_NOTICE([Could not succesfully extract the envionment variables needed for the VS setup.])
    1.80        AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
    1.81        AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
    1.82 @@ -190,30 +188,33 @@
    1.83      # Now set all paths and other env variables. This will allow the rest of
    1.84      # the configure script to find and run the compiler in the proper way.
    1.85      AC_MSG_NOTICE([Setting extracted environment variables])
    1.86 -    . $OUTPUT_ROOT/localdevenv.sh
    1.87 +    . $VS_ENV_TMP_DIR/set-vs-env.sh
    1.88 +    # Now we have VS_PATH, VS_INCLUDE, VS_LIB. For further checking, we
    1.89 +    # also define VCINSTALLDIR, WindowsSdkDir and WINDOWSSDKDIR.
    1.90    else
    1.91      # We did not find a vsvars bat file, let's hope we are run from a VS command prompt.
    1.92      AC_MSG_NOTICE([Cannot locate a valid Visual Studio installation, checking current environment])
    1.93    fi
    1.94  
    1.95 -  # At this point, we should have corrent variables in the environment, or we can't continue.
    1.96 +  # At this point, we should have correct variables in the environment, or we can't continue.
    1.97    AC_MSG_CHECKING([for Visual Studio variables])
    1.98  
    1.99    if test "x$VCINSTALLDIR" != x || test "x$WindowsSDKDir" != x || test "x$WINDOWSSDKDIR" != x; then
   1.100 -    if test "x$INCLUDE" = x || test "x$LIB" = x; then
   1.101 +    if test "x$VS_INCLUDE" = x || test "x$VS_LIB" = x; then
   1.102        AC_MSG_RESULT([present but broken])
   1.103        AC_MSG_ERROR([Your VC command prompt seems broken, INCLUDE and/or LIB is missing.])
   1.104      else
   1.105        AC_MSG_RESULT([ok])
   1.106 -      # Remove any trailing \ from INCLUDE and LIB to avoid trouble in spec.gmk.
   1.107 -      VS_INCLUDE=`$ECHO "$INCLUDE" | $SED 's/\\\\$//'`
   1.108 -      VS_LIB=`$ECHO "$LIB" | $SED 's/\\\\$//'`
   1.109 -      # Remove any paths containing # (typically F#) as that messes up make
   1.110 -      PATH=`$ECHO "$PATH" | $SED 's/[[^:#]]*#[^:]*://g'`
   1.111 -      VS_PATH="$PATH"
   1.112 +      # Remove any trailing "\" and " " from the variables.
   1.113 +      VS_INCLUDE=`$ECHO "$VS_INCLUDE" | $SED 's/\\\\* *$//'`
   1.114 +      VS_LIB=`$ECHO "$VS_LIB" | $SED 's/\\\\* *$//'`
   1.115 +      VCINSTALLDIR=`$ECHO "$VCINSTALLDIR" | $SED 's/\\\\* *$//'`
   1.116 +      WindowsSDKDir=`$ECHO "$WindowsSDKDir" | $SED 's/\\\\* *$//'`
   1.117 +      WINDOWSSDKDIR=`$ECHO "$WINDOWSSDKDIR" | $SED 's/\\\\* *$//'`
   1.118 +
   1.119 +      AC_SUBST(VS_PATH)
   1.120        AC_SUBST(VS_INCLUDE)
   1.121        AC_SUBST(VS_LIB)
   1.122 -      AC_SUBST(VS_PATH)
   1.123      fi
   1.124    else
   1.125      AC_MSG_RESULT([not found])

mercurial