1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
|
#
# Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
###############################################################################
# Appends a string to a path variable, only adding the : when needed.
AC_DEFUN([UTIL_APPEND_TO_PATH],
[
if test "x$2" != x; then
if test "x[$]$1" = x; then
$1="$2"
else
$1="[$]$1:$2"
fi
fi
])
###############################################################################
# Prepends a string to a path variable, only adding the : when needed.
AC_DEFUN([UTIL_PREPEND_TO_PATH],
[
if test "x$2" != x; then
if test "x[$]$1" = x; then
$1="$2"
else
$1="$2:[$]$1"
fi
fi
])
###############################################################################
# This will make sure the given variable points to a full and proper
# path. This means:
# 1) There will be no spaces in the path. On unix platforms,
# spaces in the path will result in an error. On Windows,
# the path will be rewritten using short-style to be space-free.
# 2) The path will be absolute, and it will be in unix-style (on
# cygwin).
# $1: The name of the variable to fix
# $2: if NOFAIL, errors will be silently ignored
AC_DEFUN([UTIL_FIXUP_PATH],
[
# Only process if variable expands to non-empty
path="[$]$1"
if test "x$path" != x; then
if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
if test "x$2" = "xNOFAIL"; then
quiet_option="-q"
fi
imported_path=`$FIXPATH_BASE $quiet_option import "$path"`
$FIXPATH_BASE verify "$imported_path"
if test $? -ne 0; then
if test "x$2" != "xNOFAIL"; then
AC_MSG_ERROR([The path of $1, which resolves as "$path", could not be imported.])
else
imported_path=""
fi
fi
if test "x$imported_path" != "x$path"; then
$1="$imported_path"
fi
else
[ if [[ "$path" =~ " " ]]; then ]
if test "x$2" != "xNOFAIL"; then
AC_MSG_NOTICE([The path of $1, which resolves as "$path", is invalid.])
AC_MSG_ERROR([Spaces are not allowed in this path.])
else
path=""
fi
fi
# Use eval to expand a potential ~.
eval new_path="$path"
if test ! -e "$new_path"; then
if test "x$2" != "xNOFAIL"; then
AC_MSG_ERROR([The path of $1, which resolves as "$new_path", is not found.])
else
new_path=""
fi
fi
# Make the path absolute
if test "x$new_path" != x; then
if test -d "$new_path"; then
path="`cd "$new_path"; pwd -L`"
else
dir="`$DIRNAME "$new_path"`"
base="`$BASENAME "$new_path"`"
path="`cd "$dir"; pwd -L`/$base"
fi
else
path=""
fi
$1="$path"
fi
fi
])
###############################################################################
# Check if the given file is a unix-style or windows-style executable, that is,
# if it expects paths in unix-style or windows-style.
# Returns "windows" or "unix" in $RESULT.
AC_DEFUN([UTIL_CHECK_WINENV_EXEC_TYPE],
[
# For cygwin and msys2, if it's linked with the correct helper lib, it
# accept unix paths
if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin" || \
test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys2"; then
linked_libs=`$LDD $1 2>&1`
if test $? -ne 0; then
# Non-binary files (e.g. shell scripts) are unix files
RESULT=unix
else
[ if [[ "$linked_libs" =~ $WINENV_MARKER_DLL ]]; then ]
RESULT=unix
else
RESULT=windows
fi
fi
elif test "x$OPENJDK_BUILD_OS" = "xwindows"; then
# On WSL, we can check if it is a PE file
file_type=`$FILE -b $1 2>&1`
[ if [[ $file_type =~ PE.*Windows ]]; then ]
RESULT=windows
else
RESULT=unix
fi
else
RESULT=unix
fi
])
###############################################################################
# This will make sure the given variable points to a executable
# with a full and proper path. This means:
# 1) There will be no spaces in the path. On unix platforms,
# spaces in the path will result in an error. On Windows,
# the path will be rewritten using short-style to be space-free.
# 2) The path will be absolute, and it will be in unix-style (on
# cygwin).
# Any arguments given to the executable is preserved.
# If the input variable does not have a directory specification, then
# it need to be in the PATH.
# $1: The name of the variable to fix
# $2: Where to look for the command (replaces $PATH)
# $3: set to NOFIXPATH to skip prefixing FIXPATH, even if needed on platform
AC_DEFUN([UTIL_FIXUP_EXECUTABLE],
[
input="[$]$1"
# Only process if variable expands to non-empty
if test "x$input" != x; then
# First separate the path from the arguments. This will split at the first
# space.
[ if [[ "$OPENJDK_BUILD_OS" = "windows" && input =~ ^$FIXPATH ]]; then
line="${input#$FIXPATH }"
fixpath_prefix="$FIXPATH "
else
line="$input"
fixpath_prefix=""
fi ]
path="${line%% *}"
arguments="${line#"$path"}"
[ if ! [[ "$path" =~ /|\\ ]]; then ]
# This is a command without path (e.g. "gcc" or "echo")
command_type=`type -t "$path"`
if test "x$command_type" = xbuiltin || test "x$command_type" = xkeyword; then
# Shell builtin or keyword; we're done here
new_path="$path"
else
# Search in $PATH using bash built-in 'type -p'.
saved_path="$PATH"
if test "x$2" != x; then
PATH="$2"
fi
new_path=`type -p "$path"`
if test "x$new_path" = x && test "x$OPENJDK_BUILD_OS" = "xwindows"; then
# Try again with .exe
new_path="`type -p "$path.exe"`"
fi
PATH="$saved_path"
if test "x$new_path" = x; then
AC_MSG_NOTICE([The command for $1, which resolves as "$input", is not found in the PATH.])
AC_MSG_ERROR([Cannot locate $path])
fi
fi
else
# This is a path with slashes, don't look at $PATH
if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
# fixpath.sh import will do all heavy lifting for us
new_path=`$FIXPATH_BASE import "$path"`
if test ! -e $new_path; then
# It failed, but maybe spaces were part of the path and not separating
# the command and argument. Retry using that assumption.
new_path=`$FIXPATH_BASE import "$input"`
if test ! -e $new_path; then
AC_MSG_NOTICE([The command for $1, which resolves as "$input", can not be found.])
AC_MSG_ERROR([Cannot locate $input])
fi
# It worked, clear all "arguments"
arguments=""
fi
else # on unix
# Make absolute
$1="$path"
UTIL_FIXUP_PATH($1, NOFAIL)
new_path="[$]$1"
if test ! -e $new_path; then
AC_MSG_NOTICE([The command for $1, which resolves as "$input", is not found])
[ if [[ "$path" =~ " " ]]; then ]
AC_MSG_NOTICE([This might be caused by spaces in the path, which is not allowed.])
fi
AC_MSG_ERROR([Cannot locate $path])
fi
if test ! -x $new_path; then
AC_MSG_NOTICE([The command for $1, which resolves as "$input", is not executable.])
AC_MSG_ERROR([Cannot execute command at $path])
fi
fi # end on unix
fi # end with or without slashes
# Now we have a usable command as new_path, with arguments in arguments
if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
if test "x$fixpath_prefix" = x; then
# Only mess around if fixpath_prefix was not given
UTIL_CHECK_WINENV_EXEC_TYPE("$new_path")
if test "x$RESULT" = xwindows; then
fixpath_prefix="$FIXPATH "
# make sure we have an .exe suffix (but not two)
new_path="${new_path%.exe}.exe"
else
# If we have gotten a .exe suffix, remove it
new_path="${new_path%.exe}"
fi
fi
fi
if test "x$3" = xNOFIXPATH; then
fixpath_prefix=""
fi
# Now join together the path and the arguments once again
new_complete="$fixpath_prefix$new_path$arguments"
$1="$new_complete"
fi
])
###############################################################################
# Setup a tool for the given variable. If correctly specified by the user,
# use that value, otherwise search for the tool using the supplied code snippet.
# $1: variable to set
# $2: code snippet to call to look for the tool
# $3: code snippet to call if variable was used to find tool
AC_DEFUN([UTIL_SETUP_TOOL],
[
# Publish this variable in the help.
AC_ARG_VAR($1, [Override default value for $1])
if [[ -z "${$1+x}" ]]; then
# The variable is not set by user, try to locate tool using the code snippet
$2
else
# The variable is set, but is it from the command line or the environment?
# Try to remove the string !$1! from our list.
try_remove_var=${CONFIGURE_OVERRIDDEN_VARIABLES//!$1!/}
if test "x$try_remove_var" = "x$CONFIGURE_OVERRIDDEN_VARIABLES"; then
# If it failed, the variable was not from the command line. Ignore it,
# but warn the user (except for BASH, which is always set by the calling BASH).
if test "x$1" != xBASH; then
AC_MSG_WARN([Ignoring value of $1 from the environment. Use command line variables instead.])
fi
# Try to locate tool using the code snippet
$2
else
# If it succeeded, then it was overridden by the user. We will use it
# for the tool.
# First remove it from the list of overridden variables, so we can test
# for unknown variables in the end.
CONFIGURE_OVERRIDDEN_VARIABLES="$try_remove_var"
tool_override=[$]$1
# Check if we try to supply an empty value
if test "x$tool_override" = x; then
AC_MSG_CHECKING([for $1])
AC_MSG_RESULT([[[disabled by user]]])
else
# Split up override in command part and argument part
tool_and_args=($tool_override)
[ tool_command=${tool_and_args[0]} ]
[ unset 'tool_and_args[0]' ]
[ tool_args=${tool_and_args[@]} ]
# Check if the provided tool contains a complete path.
tool_basename="${tool_command##*/}"
if test "x$tool_basename" = "x$tool_command"; then
# A command without a complete path is provided, search $PATH.
AC_MSG_NOTICE([Will search for user supplied tool "$tool_basename"])
AC_PATH_PROGS($1, $tool_basename ${tool_basename}.exe)
tool_command="[$]$1"
if test "x$tool_command" = x; then
AC_MSG_ERROR([User supplied tool $1="$tool_basename" could not be found in PATH])
fi
else
# Otherwise we believe it is a complete path. Use it as it is.
if test ! -x "$tool_command" && test ! -x "${tool_command}.exe"; then
AC_MSG_ERROR([User supplied tool $1="$tool_command" does not exist or is not executable])
fi
if test ! -x "$tool_command"; then
tool_command="${tool_command}.exe"
fi
$1="$tool_command"
fi
if test "x$tool_args" != x; then
# If we got arguments, re-append them to the command after the fixup.
$1="[$]$1 $tool_args"
fi
AC_MSG_CHECKING([for $1])
AC_MSG_RESULT([[$]$1 [[user supplied]]])
fi
fi
$3
fi
])
###############################################################################
# Locate a tool using proper methods.
# $1: variable to set
# $2: executable name (or list of names) to look for
# $3: [path]
# $4: set to NOFIXPATH to skip prefixing FIXPATH, even if needed on platform
AC_DEFUN([UTIL_LOOKUP_PROGS],
[
UTIL_SETUP_TOOL($1, [
$1=""
if test "x$3" != x; then
old_path="$PATH"
PATH="$3"
fi
for name in $2; do
AC_MSG_CHECKING(for $name)
command_type=`type -t "$name"`
if test "x$command_type" = xbuiltin || test "x$command_type" = xkeyword; then
# Shell builtin or keyword; we're done here
full_path="$name"
$1="$full_path"
AC_MSG_RESULT([[$full_path [builtin]]])
break
else
# Search in $PATH
old_ifs="$IFS"
IFS=":"
for elem in $PATH; do
IFS="$old_ifs"
if test "x$elem" = x; then
continue
fi
full_path="$elem/$name"
if test ! -e "$full_path" && test "x$OPENJDK_BUILD_OS" = "xwindows"; then
# Try again with .exe
full_path="$elem/$name.exe"
fi
if test -e "$full_path"; then
$1="$full_path"
UTIL_FIXUP_EXECUTABLE($1, $3, $4)
result="[$]$1"
# If we have FIXPATH enabled, strip all instances of it and prepend
# a single one, to avoid double fixpath prefixing.
if test "x$4" != xNOFIXPATH; then
[ if [[ $FIXPATH != "" && $result =~ ^"$FIXPATH " ]]; then ]
result="\$FIXPATH ${result#"$FIXPATH "}"
fi
fi
AC_MSG_RESULT([$result])
break 2;
fi
done
IFS="$old_ifs"
fi
AC_MSG_RESULT([[[not found]]])
done
if test "x$3" != x; then
PATH="$old_path"
fi
])
])
###############################################################################
# Call UTIL_SETUP_TOOL with AC_CHECK_TOOLS to locate the tool. This will look
# first for cross-compilation tools.
# $1: variable to set
# $2: executable name (or list of names) to look for
# $3: [path]
AC_DEFUN([UTIL_LOOKUP_TOOLCHAIN_PROGS],
[
if test "x$ac_tool_prefix" = x; then
UTIL_LOOKUP_PROGS($1, $2, $3)
else
prefixed_names=$(for name in $2; do echo ${ac_tool_prefix}${name} $name; done)
UTIL_LOOKUP_PROGS($1, $prefixed_names, $3)
fi
])
###############################################################################
# Test that variable $1 denoting a program is not empty. If empty, exit with an error.
# $1: variable to check
AC_DEFUN([UTIL_CHECK_NONEMPTY],
[
if test "x[$]$1" = x; then
AC_MSG_ERROR([Could not find required tool for $1])
fi
])
###############################################################################
# Like UTIL_LOOKUP_PROGS but fails if no tool was found.
# $1: variable to set
# $2: executable name (or list of names) to look for
# $3: [path]
AC_DEFUN([UTIL_REQUIRE_PROGS],
[
UTIL_LOOKUP_PROGS($1, $2, $3)
UTIL_CHECK_NONEMPTY($1)
])
###############################################################################
# Like UTIL_LOOKUP_PROGS but fails if no tool was found.
# $1: variable to set
# $2: executable name (or list of names) to look for
# $3: [path]
AC_DEFUN([UTIL_REQUIRE_TOOLCHAIN_PROGS],
[
UTIL_LOOKUP_TOOLCHAIN_PROGS($1, $2, $3)
UTIL_CHECK_NONEMPTY($1)
])
###############################################################################
# Like UTIL_SETUP_TOOL but fails if no tool was found.
# $1: variable to set
# $2: autoconf macro to call to look for the special tool
AC_DEFUN([UTIL_REQUIRE_SPECIAL],
[
UTIL_SETUP_TOOL($1, [$2])
UTIL_CHECK_NONEMPTY($1)
# The special macro will return an absolute path, and is only used for
# unix tools. No further processing needed.
])
###############################################################################
# Add FIXPATH prefix to variable. Normally this is done by UTIL_LOOKUP_PROGS
# or UTIL_FIXUP_EXECUTABLE, but in some circumstances this has to be done
# explicitly, such as when the command in question does not exist yet.
#
# $1: variable to add fixpath to
AC_DEFUN([UTIL_ADD_FIXPATH],
[
if test "x$FIXPATH" != x; then
$1="$FIXPATH [$]$1"
fi
])
###############################################################################
AC_DEFUN([UTIL_REMOVE_SYMBOLIC_LINKS],
[
if test "x$OPENJDK_BUILD_OS" != xwindows; then
# Follow a chain of symbolic links. Use readlink
# where it exists, else fall back to horribly
# complicated shell code.
if test "x$READLINK_TESTED" != yes; then
# On MacOSX there is a readlink tool with a different
# purpose than the GNU readlink tool. Check the found readlink.
READLINK_ISGNU=`$READLINK --version 2>&1 | $GREP GNU`
# If READLINK_ISGNU is empty, then it's a non-GNU readlink. Don't use it.
READLINK_TESTED=yes
fi
if test "x$READLINK" != x && test "x$READLINK_ISGNU" != x; then
$1=`$READLINK -f [$]$1`
else
# Save the current directory for restoring afterwards
STARTDIR=$PWD
COUNTER=0
sym_link_dir=`$DIRNAME [$]$1`
sym_link_file=`$BASENAME [$]$1`
cd $sym_link_dir
# Use -P flag to resolve symlinks in directories.
cd `pwd -P`
sym_link_dir=`pwd -P`
# Resolve file symlinks
while test $COUNTER -lt 20; do
ISLINK=`$LS -l $sym_link_dir/$sym_link_file | $GREP '\->' | $SED -e 's/.*-> \(.*\)/\1/'`
if test "x$ISLINK" == x; then
# This is not a symbolic link! We are done!
break
fi
# Again resolve directory symlinks since the target of the just found
# link could be in a different directory
cd `$DIRNAME $ISLINK`
sym_link_dir=`pwd -P`
sym_link_file=`$BASENAME $ISLINK`
let COUNTER=COUNTER+1
done
cd $STARTDIR
$1=$sym_link_dir/$sym_link_file
fi
fi
])
|