make/autoconf/basics_windows.m4
changeset 53110 50677f43ac3d
parent 47252 fdac20095dff
child 54455 542735f2a53e
equal deleted inserted replaced
53109:b99b41325d89 53110:50677f43ac3d
    30     unix_path=`$CYGPATH -u "$windows_path"`
    30     unix_path=`$CYGPATH -u "$windows_path"`
    31     $1="$unix_path"
    31     $1="$unix_path"
    32   elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
    32   elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
    33     unix_path=`$ECHO "$windows_path" | $SED -e 's,^\\(.\\):,/\\1,g' -e 's,\\\\,/,g'`
    33     unix_path=`$ECHO "$windows_path" | $SED -e 's,^\\(.\\):,/\\1,g' -e 's,\\\\,/,g'`
    34     $1="$unix_path"
    34     $1="$unix_path"
       
    35   elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
       
    36     # wslpath does not check the input, only call if an actual windows path was
       
    37     # given.
       
    38     if $ECHO "$windows_path" | $GREP -q ["^[a-zA-Z]:[\\\\/]"]; then
       
    39       unix_path=`$WSLPATH -u "$windows_path"`
       
    40       $1="$unix_path"
       
    41     fi
    35   fi
    42   fi
    36 ])
    43 ])
    37 
    44 
    38 AC_DEFUN([BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH],
    45 AC_DEFUN([BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH],
    39 [
    46 [
    41   if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
    48   if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
    42     windows_path=`$CYGPATH -m "$unix_path"`
    49     windows_path=`$CYGPATH -m "$unix_path"`
    43     $1="$windows_path"
    50     $1="$windows_path"
    44   elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
    51   elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
    45     windows_path=`cmd //c echo $unix_path`
    52     windows_path=`cmd //c echo $unix_path`
       
    53     $1="$windows_path"
       
    54   elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
       
    55     windows_path=`$WSLPATH -m "$unix_path"`
    46     $1="$windows_path"
    56     $1="$windows_path"
    47   fi
    57   fi
    48 ])
    58 ])
    49 
    59 
    50 # Helper function which possibly converts a path using DOS-style short mode.
    60 # Helper function which possibly converts a path using DOS-style short mode.
    98     # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \)
   108     # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \)
    99     new_path=`cmd /c "for %A in (\"$input_path\") do @echo %~sA"|$TR \\\\\\\\ / | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
   109     new_path=`cmd /c "for %A in (\"$input_path\") do @echo %~sA"|$TR \\\\\\\\ / | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
   100   fi
   110   fi
   101 ])
   111 ])
   102 
   112 
       
   113 # Helper function which possibly converts a path using DOS-style short mode.
       
   114 # If so, the updated path is stored in $new_path.
       
   115 # $1: The path to check
       
   116 AC_DEFUN([BASIC_MAKE_WINDOWS_SPACE_SAFE_WSL],
       
   117 [
       
   118   input_path="$1"
       
   119   # Check if we need to convert this using DOS-style short mode. If the path
       
   120   # contains just simple characters, use it. Otherwise (spaces, weird characters),
       
   121   # take no chances and rewrite it.
       
   122   # Note: m4 eats our [], so we need to use @<:@ and @:>@ instead.
       
   123   has_forbidden_chars=`$ECHO "$input_path" | $GREP [[^-_/:a-zA-Z0-9\\.]]`
       
   124   if test "x$has_forbidden_chars" != x; then
       
   125     # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \)
       
   126     TOPDIR_windows="$TOPDIR"
       
   127     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([TOPDIR_windows])
       
   128     # First convert to Windows path to make input valid for cmd
       
   129     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([input_path])
       
   130     new_path=`$CMD /c $TOPDIR_windows/make/scripts/windowsShortName.bat "$input_path" \
       
   131         | $SED -e 's|\r||g' \
       
   132         | $TR \\\\\\\\ / | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
       
   133     # Rewrite back to unix style
       
   134     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([new_path])
       
   135   fi
       
   136 ])
       
   137 
   103 # FIXME: The BASIC_FIXUP_*_CYGWIN/MSYS is most likely too convoluted
   138 # FIXME: The BASIC_FIXUP_*_CYGWIN/MSYS is most likely too convoluted
   104 # and could probably be heavily simplified. However, all changes in this
   139 # and could probably be heavily simplified. However, all changes in this
   105 # area tend to need lot of testing in different scenarios, and in lack of
   140 # area tend to need lot of testing in different scenarios, and in lack of
   106 # proper unit testing, cleaning this up has not been deemed worth the effort
   141 # proper unit testing, cleaning this up has not been deemed worth the effort
   107 # at the moment.
   142 # at the moment.
   153     AC_MSG_NOTICE([Rewriting $1 to "$new_path"])
   188     AC_MSG_NOTICE([Rewriting $1 to "$new_path"])
   154   fi
   189   fi
   155 
   190 
   156   # Save the first 10 bytes of this path to the storage, so fixpath can work.
   191   # Save the first 10 bytes of this path to the storage, so fixpath can work.
   157   all_fixpath_prefixes=("${all_fixpath_prefixes@<:@@@:>@}" "${new_path:0:10}")
   192   all_fixpath_prefixes=("${all_fixpath_prefixes@<:@@@:>@}" "${new_path:0:10}")
       
   193 ])
       
   194 
       
   195 AC_DEFUN([BASIC_FIXUP_PATH_WSL],
       
   196 [
       
   197   # Input might be given as Windows format, start by converting to
       
   198   # unix format.
       
   199   new_path="[$]$1"
       
   200   BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([new_path])
       
   201 
       
   202   # Call helper function which possibly converts this using DOS-style short mode.
       
   203   # If so, the updated path is stored in $new_path.
       
   204   BASIC_MAKE_WINDOWS_SPACE_SAFE_WSL([$new_path])
       
   205 
       
   206   if test "x$path" != "x$new_path"; then
       
   207     $1="$new_path"
       
   208     AC_MSG_NOTICE([Rewriting $1 to "$new_path"])
       
   209   fi
   158 ])
   210 ])
   159 
   211 
   160 AC_DEFUN([BASIC_FIXUP_EXECUTABLE_CYGWIN],
   212 AC_DEFUN([BASIC_FIXUP_EXECUTABLE_CYGWIN],
   161 [
   213 [
   162   # First separate the path from the arguments. This will split at the first
   214   # First separate the path from the arguments. This will split at the first
   303     # Save the first 10 bytes of this path to the storage, so fixpath can work.
   355     # Save the first 10 bytes of this path to the storage, so fixpath can work.
   304     all_fixpath_prefixes=("${all_fixpath_prefixes@<:@@@:>@}" "${new_path:0:10}")
   356     all_fixpath_prefixes=("${all_fixpath_prefixes@<:@@@:>@}" "${new_path:0:10}")
   305   fi
   357   fi
   306 ])
   358 ])
   307 
   359 
       
   360 AC_DEFUN([BASIC_FIXUP_EXECUTABLE_WSL],
       
   361 [
       
   362   # First separate the path from the arguments. This will split at the first
       
   363   # space.
       
   364   complete="[$]$1"
       
   365   path="${complete%% *}"
       
   366   tmp="$complete EOL"
       
   367   arguments="${tmp#* }"
       
   368 
       
   369   # Input might be given as Windows format, start by converting to
       
   370   # unix format.
       
   371   new_path="$path"
       
   372   BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([new_path])
       
   373 
       
   374   # Now try to locate executable using which
       
   375   new_path_bak="$new_path"
       
   376   new_path=`$WHICH "$new_path" 2> /dev/null`
       
   377   # bat and cmd files are not considered executable in WSL
       
   378   if test "x$new_path" = x \
       
   379       && test "x`$ECHO \"$path\" | $GREP -i -e \"\\.bat$\" -e \"\\.cmd$\"`" != x \
       
   380       && test "x`$LS \"$path\" 2>/dev/null`" != x; then
       
   381     new_path="$new_path_back"
       
   382   fi
       
   383   if test "x$new_path" = x; then
       
   384     # Oops. Which didn't find the executable.
       
   385     # The splitting of arguments from the executable at a space might have been incorrect,
       
   386     # since paths with space are more likely in Windows. Give it another try with the whole
       
   387     # argument.
       
   388     path="$complete"
       
   389     arguments="EOL"
       
   390     new_path="$path"
       
   391     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH([new_path])
       
   392     new_path_bak="$new_path"
       
   393     new_path=`$WHICH "$new_path" 2> /dev/null`
       
   394     # bat and cmd files are not considered executable in WSL
       
   395     if test "x$new_path" = x \
       
   396         && test "x`$ECHO \"$path\" | $GREP -i -e \"\\.bat$\" -e \"\\.cmd$\"`" != x \
       
   397         && test "x`$LS \"$path\" 2>/dev/null`" != x; then
       
   398       new_path="$new_path_bak"
       
   399     fi
       
   400     if test "x$new_path" = x; then
       
   401       # It's still not found. Now this is an unrecoverable error.
       
   402       AC_MSG_NOTICE([The path of $1, which resolves as "$complete", is not found.])
       
   403       has_space=`$ECHO "$complete" | $GREP " "`
       
   404       if test "x$has_space" != x; then
       
   405         AC_MSG_NOTICE([You might be mixing spaces in the path and extra arguments, which is not allowed.])
       
   406       fi
       
   407       AC_MSG_ERROR([Cannot locate the the path of $1])
       
   408     fi
       
   409   fi
       
   410 
       
   411   # In WSL, suffixes must be present for Windows executables
       
   412   if test ! -f "$new_path"; then
       
   413     # Try adding .exe or .cmd
       
   414     if test -f "${new_path}.exe"; then
       
   415       input_to_shortpath="${new_path}.exe"
       
   416     elif test -f "${new_path}.cmd"; then
       
   417       input_to_shortpath="${new_path}.cmd"
       
   418     else
       
   419       AC_MSG_NOTICE([The path of $1, which resolves as "$new_path", is invalid.])
       
   420       AC_MSG_NOTICE([Neither "$new_path" nor "$new_path.exe/cmd" can be found])
       
   421       AC_MSG_ERROR([Cannot locate the the path of $1])
       
   422     fi
       
   423   else
       
   424     input_to_shortpath="$new_path"
       
   425   fi
       
   426 
       
   427   # Call helper function which possibly converts this using DOS-style short mode.
       
   428   # If so, the updated path is stored in $new_path.
       
   429   new_path="$input_to_shortpath"
       
   430   BASIC_MAKE_WINDOWS_SPACE_SAFE_WSL([$input_to_shortpath])
       
   431 ])
       
   432 
   308 # Setup basic configuration paths, and platform-specific stuff related to PATHs.
   433 # Setup basic configuration paths, and platform-specific stuff related to PATHs.
   309 AC_DEFUN([BASIC_CHECK_PATHS_WINDOWS],
   434 AC_DEFUN([BASIC_CHECK_PATHS_WINDOWS],
   310 [
   435 [
   311   SRC_ROOT_LENGTH=`$THEPWDCMD -L|$WC -m`
   436   SRC_ROOT_LENGTH=`$THEPWDCMD -L|$WC -m`
   312   if test $SRC_ROOT_LENGTH -gt 100; then
   437   if test $SRC_ROOT_LENGTH -gt 100; then
   351     # The cmd output ends with Windows line endings (CR/LF), the grep command will strip that away
   476     # The cmd output ends with Windows line endings (CR/LF), the grep command will strip that away
   352     MSYS_ROOT_PATH=`cd / ; cmd /c cd | $GREP ".*"`
   477     MSYS_ROOT_PATH=`cd / ; cmd /c cd | $GREP ".*"`
   353     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(MSYS_ROOT_PATH)
   478     BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(MSYS_ROOT_PATH)
   354     AC_MSG_RESULT([$MSYS_ROOT_PATH])
   479     AC_MSG_RESULT([$MSYS_ROOT_PATH])
   355     WINDOWS_ENV_ROOT_PATH="$MSYS_ROOT_PATH"
   480     WINDOWS_ENV_ROOT_PATH="$MSYS_ROOT_PATH"
       
   481   elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
       
   482     AC_MSG_CHECKING([Windows version])
       
   483     # m4 replaces [ and ] so we use @<:@ and @:>@ instead
       
   484     WINDOWS_VERSION=`$CMD /c ver.exe | $EGREP -o '(@<:@0-9@:>@+\.)+@<:@0-9@:>@+'`
       
   485     AC_MSG_RESULT([$WINDOWS_VERSION])
       
   486 
       
   487     AC_MSG_CHECKING([WSL kernel version])
       
   488     WSL_KERNEL_VERSION=`$UNAME -v`
       
   489     AC_MSG_RESULT([$WSL_KERNEL_VERSION])
       
   490 
       
   491     AC_MSG_CHECKING([WSL kernel release])
       
   492     WSL_KERNEL_RELEASE=`$UNAME -r`
       
   493     AC_MSG_RESULT([$WSL_KERNEL_RELEASE])
       
   494 
       
   495     AC_MSG_CHECKING([WSL distribution])
       
   496     WSL_DISTRIBUTION=`$LSB_RELEASE -d | sed 's/Description:\t//'`
       
   497     AC_MSG_RESULT([$WSL_DISTRIBUTION])
       
   498 
       
   499     WINDOWS_ENV_VENDOR='WSL'
       
   500     WINDOWS_ENV_VERSION="$WSL_DISTRIBUTION $WSL_KERNEL_VERSION $WSL_KERNEL_RELEASE (on Windows build $WINDOWS_VERSION)"
   356   else
   501   else
   357     AC_MSG_ERROR([Unknown Windows environment. Neither cygwin nor msys was detected.])
   502     AC_MSG_ERROR([Unknown Windows environment. Neither cygwin, msys, nor wsl was detected.])
   358   fi
   503   fi
   359 
   504 
   360   # Test if windows or unix (cygwin/msys) find is first in path.
   505   # Test if windows or unix (cygwin/msys) find is first in path.
   361   AC_MSG_CHECKING([what kind of 'find' is first on the PATH])
   506   AC_MSG_CHECKING([what kind of 'find' is first on the PATH])
   362   FIND_BINARY_OUTPUT=`find --version 2>&1`
   507   FIND_BINARY_OUTPUT=`find --version 2>&1`
   393       # @ was chosen as separator to minimize risk of other tools messing around with it
   538       # @ was chosen as separator to minimize risk of other tools messing around with it
   394       all_unique_prefixes=`echo "${all_fixpath_prefixes@<:@@@:>@}" \
   539       all_unique_prefixes=`echo "${all_fixpath_prefixes@<:@@@:>@}" \
   395           | tr ' ' '\n' | $GREP '^/./' | $SORT | $UNIQ`
   540           | tr ' ' '\n' | $GREP '^/./' | $SORT | $UNIQ`
   396       fixpath_argument_list=`echo $all_unique_prefixes  | tr ' ' '@'`
   541       fixpath_argument_list=`echo $all_unique_prefixes  | tr ' ' '@'`
   397       FIXPATH="$FIXPATH_BIN -m$fixpath_argument_list"
   542       FIXPATH="$FIXPATH_BIN -m$fixpath_argument_list"
       
   543     elif test "x$OPENJDK_BUILD_OS_ENV" = xwindows.wsl; then
       
   544       FIXPATH="$FIXPATH_BIN -w"
   398     fi
   545     fi
   399     FIXPATH_SRC_W="$FIXPATH_SRC"
   546     FIXPATH_SRC_W="$FIXPATH_SRC"
   400     FIXPATH_BIN_W="$FIXPATH_BIN"
   547     FIXPATH_BIN_W="$FIXPATH_BIN"
   401     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([FIXPATH_SRC_W])
   548     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([FIXPATH_SRC_W])
   402     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([FIXPATH_BIN_W])
   549     BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([FIXPATH_BIN_W])
   410       AC_MSG_RESULT([no])
   557       AC_MSG_RESULT([no])
   411       cat $FIXPATH_DIR/fixpath1.log
   558       cat $FIXPATH_DIR/fixpath1.log
   412       AC_MSG_ERROR([Could not create $FIXPATH_BIN])
   559       AC_MSG_ERROR([Could not create $FIXPATH_BIN])
   413     fi
   560     fi
   414     AC_MSG_RESULT([yes])
   561     AC_MSG_RESULT([yes])
       
   562 
       
   563     if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.wsl"; then
       
   564       OLD_WSLENV="$WSLENV"
       
   565       WSLENV=`$ECHO $WSLENV | $SED 's/PATH\/l://'`
       
   566       BASIC_APPEND_TO_PATH(WSLENV, "FIXPATH_PATH")
       
   567       export WSLENV
       
   568       export FIXPATH_PATH=$VS_PATH_WINDOWS
       
   569       AC_MSG_NOTICE([FIXPATH_PATH is $FIXPATH_PATH])
       
   570       AC_MSG_NOTICE([Rewriting WSLENV from $OLD_WSLENV to $WSLENV])
       
   571     fi
       
   572 
   415     AC_MSG_CHECKING([if fixpath.exe works])
   573     AC_MSG_CHECKING([if fixpath.exe works])
   416     cd $FIXPATH_DIR
   574     cd $FIXPATH_DIR
   417     $FIXPATH $CC $FIXPATH_SRC -Fe$FIXPATH_DIR/fixpath2.exe \
   575     $FIXPATH $CC $FIXPATH_SRC -Fe$FIXPATH_DIR/fixpath2.exe \
   418         > $FIXPATH_DIR/fixpath2.log 2>&1
   576         > $FIXPATH_DIR/fixpath2.log 2>&1
   419     cd $CURDIR
   577     cd $CURDIR