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([BASIC_WINDOWS_REWRITE_AS_UNIX_PATH], 27 [ 28 windows_path="[$]$1" 29 if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then 30 unix_path=`$CYGPATH -u "$windows_path"` 31 $1="$unix_path" 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'` 34 $1="$unix_path" 35 fi 36 ]) 37 38 AC_DEFUN([BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH], 39 [ 40 unix_path="[$]$1" 41 if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then 42 windows_path=`$CYGPATH -m "$unix_path"` 43 $1="$windows_path" 44 elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then 45 windows_path=`cmd //c echo $unix_path` 46 $1="$windows_path" 47 fi 48 ]) 49 50 # Helper function which possibly converts a path using DOS-style short mode. 51 # If so, the updated path is stored in $new_path. 52 # $1: The path to check 53 AC_DEFUN([BASIC_MAKE_WINDOWS_SPACE_SAFE_CYGWIN], 54 [ 55 input_path="$1" 56 # Check if we need to convert this using DOS-style short mode. If the path 57 # contains just simple characters, use it. Otherwise (spaces, weird characters), 58 # take no chances and rewrite it. 59 # Note: m4 eats our [], so we need to use @<:@ and @:>@ instead. 60 has_forbidden_chars=`$ECHO "$input_path" | $GREP @<:@^-._/a-zA-Z0-9@:>@` 61 if test "x$has_forbidden_chars" != x; then 62 # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \) 63 shortmode_path=`$CYGPATH -s -m -a "$input_path"` 64 path_after_shortmode=`$CYGPATH -u "$shortmode_path"` 65 if test "x$path_after_shortmode" != "x$input_to_shortpath"; then 66 # Going to short mode and back again did indeed matter. Since short mode is 67 # case insensitive, let's make it lowercase to improve readability. 68 shortmode_path=`$ECHO "$shortmode_path" | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` 69 # Now convert it back to Unix-stile (cygpath) 70 input_path=`$CYGPATH -u "$shortmode_path"` 71 new_path="$input_path" 72 fi 73 fi 74 75 test_cygdrive_prefix=`$ECHO $input_path | $GREP ^/cygdrive/` 76 if test "x$test_cygdrive_prefix" = x; then 77 # As a simple fix, exclude /usr/bin since it's not a real path. 78 if test "x`$ECHO $1 | $GREP ^/usr/bin/`" = x; then 79 # The path is in a Cygwin special directory (e.g. /home). We need this converted to 80 # a path prefixed by /cygdrive for fixpath to work. 81 new_path="$CYGWIN_ROOT_PATH$input_path" 82 fi 83 fi 84 ]) 85 86 # Helper function which possibly converts a path using DOS-style short mode. 87 # If so, the updated path is stored in $new_path. 88 # $1: The path to check 89 AC_DEFUN([BASIC_MAKE_WINDOWS_SPACE_SAFE_MSYS], 90 [ 91 input_path="$1" 92 # Check if we need to convert this using DOS-style short mode. If the path 93 # contains just simple characters, use it. Otherwise (spaces, weird characters), 94 # take no chances and rewrite it. 95 # Note: m4 eats our [], so we need to use @<:@ and @:>@ instead. 96 has_forbidden_chars=`$ECHO "$input_path" | $GREP @<:@^-_/:a-zA-Z0-9@:>@` 97 if test "x$has_forbidden_chars" != x; then 98 # 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'` 100 fi 101 ]) 102 103 # FIXME: The BASIC_FIXUP_*_CYGWIN/MSYS is most likely too convoluted 104 # 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 106 # proper unit testing, cleaning this up has not been deemed worth the effort 107 # at the moment. 108 109 AC_DEFUN([BASIC_FIXUP_PATH_CYGWIN], 110 [ 111 # Input might be given as Windows format, start by converting to 112 # unix format. 113 path="[$]$1" 114 new_path=`$CYGPATH -u "$path"` 115 116 # Cygwin tries to hide some aspects of the Windows file system, such that binaries are 117 # named .exe but called without that suffix. Therefore, "foo" and "foo.exe" are considered 118 # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then 119 # "foo.exe" is OK but "foo" is an error. 120 # 121 # This test is therefore slightly more accurate than "test -f" to check for file precense. 122 # It is also a way to make sure we got the proper file name for the real test later on. 123 test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` 124 if test "x$test_shortpath" = x; then 125 AC_MSG_NOTICE([The path of $1, which resolves as "$path", is invalid.]) 126 AC_MSG_ERROR([Cannot locate the the path of $1]) 127 fi 128 129 # Call helper function which possibly converts this using DOS-style short mode. 130 # If so, the updated path is stored in $new_path. 131 BASIC_MAKE_WINDOWS_SPACE_SAFE_CYGWIN([$new_path]) 132 133 if test "x$path" != "x$new_path"; then 134 $1="$new_path" 135 AC_MSG_NOTICE([Rewriting $1 to "$new_path"]) 136 fi 137 ]) 138 139 AC_DEFUN([BASIC_FIXUP_PATH_MSYS], 140 [ 141 path="[$]$1" 142 has_colon=`$ECHO $path | $GREP ^.:` 143 new_path="$path" 144 if test "x$has_colon" = x; then 145 # Not in mixed or Windows style, start by that. 146 new_path=`cmd //c echo $path` 147 fi 148 149 BASIC_MAKE_WINDOWS_SPACE_SAFE_MSYS([$new_path]) 150 BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(new_path) 151 if test "x$path" != "x$new_path"; then 152 $1="$new_path" 153 AC_MSG_NOTICE([Rewriting $1 to "$new_path"]) 154 fi 155 156 # 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}") 158 ]) 159 160 AC_DEFUN([BASIC_FIXUP_EXECUTABLE_CYGWIN], 161 [ 162 # First separate the path from the arguments. This will split at the first 163 # space. 164 complete="[$]$1" 165 path="${complete%% *}" 166 tmp="$complete EOL" 167 arguments="${tmp#* }" 168 169 # Input might be given as Windows format, start by converting to 170 # unix format. 171 new_path=`$CYGPATH -u "$path"` 172 173 # Now try to locate executable using which 174 new_path=`$WHICH "$new_path" 2> /dev/null` 175 # bat and cmd files are not always considered executable in cygwin causing which 176 # to not find them 177 if test "x$new_path" = x \ 178 && test "x`$ECHO \"$path\" | $GREP -i -e \"\\.bat$\" -e \"\\.cmd$\"`" != x \ 179 && test "x`$LS \"$path\" 2>/dev/null`" != x; then 180 new_path=`$CYGPATH -u "$path"` 181 fi 182 if test "x$new_path" = x; then 183 # Oops. Which didn't find the executable. 184 # The splitting of arguments from the executable at a space might have been incorrect, 185 # since paths with space are more likely in Windows. Give it another try with the whole 186 # argument. 187 path="$complete" 188 arguments="EOL" 189 new_path=`$CYGPATH -u "$path"` 190 new_path=`$WHICH "$new_path" 2> /dev/null` 191 # bat and cmd files are not always considered executable in cygwin causing which 192 # to not find them 193 if test "x$new_path" = x \ 194 && test "x`$ECHO \"$path\" | $GREP -i -e \"\\.bat$\" -e \"\\.cmd$\"`" != x \ 195 && test "x`$LS \"$path\" 2>/dev/null`" != x; then 196 new_path=`$CYGPATH -u "$path"` 197 fi 198 if test "x$new_path" = x; then 199 # It's still not found. Now this is an unrecoverable error. 200 AC_MSG_NOTICE([The path of $1, which resolves as "$complete", is not found.]) 201 has_space=`$ECHO "$complete" | $GREP " "` 202 if test "x$has_space" != x; then 203 AC_MSG_NOTICE([You might be mixing spaces in the path and extra arguments, which is not allowed.]) 204 fi 205 AC_MSG_ERROR([Cannot locate the the path of $1]) 206 fi 207 fi 208 209 # Cygwin tries to hide some aspects of the Windows file system, such that binaries are 210 # named .exe but called without that suffix. Therefore, "foo" and "foo.exe" are considered 211 # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then 212 # "foo.exe" is OK but "foo" is an error. 213 # 214 # This test is therefore slightly more accurate than "test -f" to check for file presence. 215 # It is also a way to make sure we got the proper file name for the real test later on. 216 test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` 217 if test "x$test_shortpath" = x; then 218 # Short path failed, file does not exist as specified. 219 # Try adding .exe or .cmd 220 if test -f "${new_path}.exe"; then 221 input_to_shortpath="${new_path}.exe" 222 elif test -f "${new_path}.cmd"; then 223 input_to_shortpath="${new_path}.cmd" 224 else 225 AC_MSG_NOTICE([The path of $1, which resolves as "$new_path", is invalid.]) 226 AC_MSG_NOTICE([Neither "$new_path" nor "$new_path.exe/cmd" can be found]) 227 AC_MSG_ERROR([Cannot locate the the path of $1]) 228 fi 229 else 230 input_to_shortpath="$new_path" 231 fi 232 233 # Call helper function which possibly converts this using DOS-style short mode. 234 # If so, the updated path is stored in $new_path. 235 new_path="$input_to_shortpath" 236 BASIC_MAKE_WINDOWS_SPACE_SAFE_CYGWIN([$input_to_shortpath]) 237 # remove trailing .exe if any 238 new_path="${new_path/%.exe/}" 239 ]) 240 241 AC_DEFUN([BASIC_FIXUP_EXECUTABLE_MSYS], 242 [ 243 # First separate the path from the arguments. This will split at the first 244 # space. 245 complete="[$]$1" 246 path="${complete%% *}" 247 tmp="$complete EOL" 248 arguments="${tmp#* }" 249 250 # Input might be given as Windows format, start by converting to 251 # unix format. 252 new_path="$path" 253 BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(new_path) 254 255 # Now try to locate executable using which 256 new_path=`$WHICH "$new_path" 2> /dev/null` 257 258 if test "x$new_path" = x; then 259 # Oops. Which didn't find the executable. 260 # The splitting of arguments from the executable at a space might have been incorrect, 261 # since paths with space are more likely in Windows. Give it another try with the whole 262 # argument. 263 path="$complete" 264 arguments="EOL" 265 new_path="$path" 266 BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(new_path) 267 268 new_path=`$WHICH "$new_path" 2> /dev/null` 269 270 if test "x$new_path" = x; then 271 # It's still not found. Now this is an unrecoverable error. 272 AC_MSG_NOTICE([The path of $1, which resolves as "$complete", is not found.]) 273 has_space=`$ECHO "$complete" | $GREP " "` 274 if test "x$has_space" != x; then 275 AC_MSG_NOTICE([You might be mixing spaces in the path and extra arguments, which is not allowed.]) 276 fi 277 AC_MSG_ERROR([Cannot locate the the path of $1]) 278 fi 279 fi 280 281 # Now new_path has a complete unix path to the binary 282 if test "x`$ECHO $new_path | $GREP ^/bin/`" != x; then 283 # Keep paths in /bin as-is, but remove trailing .exe if any 284 new_path="${new_path/%.exe/}" 285 # Do not save /bin paths to all_fixpath_prefixes! 286 else 287 # Not in mixed or Windows style, start by that. 288 new_path=`cmd //c echo $new_path` 289 BASIC_MAKE_WINDOWS_SPACE_SAFE_MSYS([$new_path]) 290 # Output is in $new_path 291 BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(new_path) 292 # remove trailing .exe if any 293 new_path="${new_path/%.exe/}" 294 295 # Save the first 10 bytes of this path to the storage, so fixpath can work. 296 all_fixpath_prefixes=("${all_fixpath_prefixes@<:@@@:>@}" "${new_path:0:10}") 297 fi 298 ]) 299 300 # Setup basic configuration paths, and platform-specific stuff related to PATHs. 301 AC_DEFUN([BASIC_CHECK_PATHS_WINDOWS], 302 [ 303 SRC_ROOT_LENGTH=`$THEPWDCMD -L|$WC -m` 304 if test $SRC_ROOT_LENGTH -gt 100; then 305 AC_MSG_ERROR([Your base path is too long. It is $SRC_ROOT_LENGTH characters long, but only 100 is supported]) 306 fi 307 308 if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then 309 AC_MSG_CHECKING([cygwin release]) 310 CYGWIN_VERSION=`$UNAME -r` 311 AC_MSG_RESULT([$CYGWIN_VERSION]) 312 WINDOWS_ENV_VENDOR='cygwin' 313 WINDOWS_ENV_VERSION="$CYGWIN_VERSION" 314 315 CYGWIN_VERSION_OK=`$ECHO $CYGWIN_VERSION | $GREP ^1.7.` 316 if test "x$CYGWIN_VERSION_OK" = x; then 317 AC_MSG_NOTICE([Your cygwin is too old. You are running $CYGWIN_VERSION, but at least cygwin 1.7 is required. Please upgrade.]) 318 AC_MSG_ERROR([Cannot continue]) 319 fi 320 if test "x$CYGPATH" = x; then 321 AC_MSG_ERROR([Something is wrong with your cygwin installation since I cannot find cygpath.exe in your path]) 322 fi 323 AC_MSG_CHECKING([cygwin root directory as unix-style path]) 324 # The cmd output ends with Windows line endings (CR/LF), the grep command will strip that away 325 cygwin_winpath_root=`cd / ; cmd /c cd | grep ".*"` 326 # Force cygpath to report the proper root by including a trailing space, and then stripping it off again. 327 CYGWIN_ROOT_PATH=`$CYGPATH -u "$cygwin_winpath_root " | $CUT -f 1 -d " "` 328 AC_MSG_RESULT([$CYGWIN_ROOT_PATH]) 329 WINDOWS_ENV_ROOT_PATH="$CYGWIN_ROOT_PATH" 330 test_cygdrive_prefix=`$ECHO $CYGWIN_ROOT_PATH | $GREP ^/cygdrive/` 331 if test "x$test_cygdrive_prefix" = x; then 332 AC_MSG_ERROR([Your cygdrive prefix is not /cygdrive. This is currently not supported. Change with mount -c.]) 333 fi 334 elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then 335 AC_MSG_CHECKING([msys release]) 336 MSYS_VERSION=`$UNAME -r` 337 AC_MSG_RESULT([$MSYS_VERSION]) 338 339 WINDOWS_ENV_VENDOR='msys' 340 WINDOWS_ENV_VERSION="$MSYS_VERSION" 341 342 AC_MSG_CHECKING([msys root directory as unix-style path]) 343 # The cmd output ends with Windows line endings (CR/LF), the grep command will strip that away 344 MSYS_ROOT_PATH=`cd / ; cmd /c cd | grep ".*"` 345 BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(MSYS_ROOT_PATH) 346 AC_MSG_RESULT([$MSYS_ROOT_PATH]) 347 WINDOWS_ENV_ROOT_PATH="$MSYS_ROOT_PATH" 348 else 349 AC_MSG_ERROR([Unknown Windows environment. Neither cygwin nor msys was detected.]) 350 fi 351 352 # Test if windows or unix (cygwin/msys) find is first in path. 353 AC_MSG_CHECKING([what kind of 'find' is first on the PATH]) 354 FIND_BINARY_OUTPUT=`find --version 2>&1` 355 if test "x`echo $FIND_BINARY_OUTPUT | $GREP GNU`" != x; then 356 AC_MSG_RESULT([unix style]) 357 elif test "x`echo $FIND_BINARY_OUTPUT | $GREP FIND`" != x; then 358 AC_MSG_RESULT([Windows]) 359 AC_MSG_NOTICE([Your path contains Windows tools (C:\Windows\system32) before your unix (cygwin or msys) tools.]) 360 AC_MSG_NOTICE([This will not work. Please correct and make sure /usr/bin (or similar) is first in path.]) 361 AC_MSG_ERROR([Cannot continue]) 362 else 363 AC_MSG_RESULT([unknown]) 364 AC_MSG_WARN([It seems that your find utility is non-standard.]) 365 fi 366 ]) 367 368 AC_DEFUN_ONCE([BASIC_COMPILE_FIXPATH], 369 [ 370 # When using cygwin or msys, we need a wrapper binary that renames 371 # /cygdrive/c/ arguments into c:/ arguments and peeks into 372 # @files and rewrites these too! This wrapper binary is 373 # called fixpath. 374 FIXPATH= 375 if test "x$OPENJDK_BUILD_OS" = xwindows; then 376 AC_MSG_CHECKING([if fixpath can be created]) 377 FIXPATH_SRC="$SRC_ROOT/common/src/fixpath.c" 378 FIXPATH_BIN="$OUTPUT_ROOT/fixpath.exe" 379 if test "x$OPENJDK_BUILD_OS_ENV" = xwindows.cygwin; then 380 FIXPATH_SRC=`$CYGPATH -m $FIXPATH_SRC` 381 FIXPATH_BIN=`$CYGPATH -m $FIXPATH_BIN` 382 # Important to keep the .exe suffix on Cygwin for Hotspot makefiles 383 FIXPATH="$OUTPUT_ROOT/fixpath.exe -c" 384 elif test "x$OPENJDK_BUILD_OS_ENV" = xwindows.msys; then 385 FIXPATH_SRC=`cmd //c echo $FIXPATH_SRC` 386 FIXPATH_BIN=`cmd //c echo $FIXPATH_BIN` 387 388 # Take all collected prefixes and turn them into a -m/c/foo@/c/bar@... command line 389 # @ was chosen as separator to minimize risk of other tools messing around with it 390 all_unique_prefixes=`echo "${all_fixpath_prefixes@<:@@@:>@}" | tr ' ' '\n' | grep '^/./' | sort | uniq` 391 fixpath_argument_list=`echo $all_unique_prefixes | tr ' ' '@'` 392 393 FIXPATH="$OUTPUT_ROOT/fixpath -m$fixpath_argument_list" 394 fi 395 rm -f $OUTPUT_ROOT/fixpath* 396 cd $OUTPUT_ROOT 397 $CC $FIXPATH_SRC -Fe$FIXPATH_BIN > $OUTPUT_ROOT/fixpath1.log 2>&1 398 cd $CURDIR 399 400 if test ! -x $OUTPUT_ROOT/fixpath.exe; then 401 AC_MSG_RESULT([no]) 402 cat $OUTPUT_ROOT/fixpath1.log 403 AC_MSG_ERROR([Could not create $OUTPUT_ROOT/fixpath.exe]) 404 fi 405 AC_MSG_RESULT([yes]) 406 AC_MSG_CHECKING([if fixpath.exe works]) 407 cd $OUTPUT_ROOT 408 $FIXPATH $CC $SRC_ROOT/common/src/fixpath.c -Fe$OUTPUT_ROOT/fixpath2.exe > $OUTPUT_ROOT/fixpath2.log 2>&1 409 cd $CURDIR 410 if test ! -x $OUTPUT_ROOT/fixpath2.exe; then 411 AC_MSG_RESULT([no]) 412 cat $OUTPUT_ROOT/fixpath2.log 413 AC_MSG_ERROR([fixpath did not work!]) 414 fi 415 AC_MSG_RESULT([yes]) 416 rm -f $OUTPUT_ROOT/fixpath?.??? $OUTPUT_ROOT/fixpath.obj 417 fi 418 419 AC_SUBST(FIXPATH) 420 ])