basics.m4 28.9 KB
Newer Older
1
#
2
# Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# 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.
#

E
erikj 已提交
26
# Test if $1 is a valid argument to $3 (often is $JAVA passed as $3)
27
# If so, then append $1 to $2 \
E
erikj 已提交
28
# Also set JVM_ARG_OK to true/false depending on outcome.
29 30
AC_DEFUN([ADD_JVM_ARG_IF_OK],
[
31 32 33 34 35 36 37 38 39 40 41 42 43
  $ECHO "Check if jvm arg is ok: $1" >&AS_MESSAGE_LOG_FD
  $ECHO "Command: $3 $1 -version" >&AS_MESSAGE_LOG_FD
  OUTPUT=`$3 $1 -version 2>&1`
  FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn`
  FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""`
  if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then
    $2="[$]$2 $1"
    JVM_ARG_OK=true
  else
    $ECHO "Arg failed:" >&AS_MESSAGE_LOG_FD
    $ECHO "$OUTPUT" >&AS_MESSAGE_LOG_FD
    JVM_ARG_OK=false
  fi
44 45
])

46 47 48 49 50 51 52 53 54 55
# Appends a string to a path variable, only adding the : when needed.
AC_DEFUN([BASIC_APPEND_TO_PATH],
[
  if test "x[$]$1" = x; then
    $1="$2"
  else
    $1="[$]$1:$2"
  fi
])

O
ohair 已提交
56 57 58 59 60 61 62 63 64
# 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 posix 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
AC_DEFUN([BASIC_FIXUP_PATH],
65
[
O
ohair 已提交
66 67 68 69 70 71 72 73 74 75 76
  if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
    BASIC_FIXUP_PATH_CYGWIN($1)
  elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
    BASIC_FIXUP_PATH_MSYS($1)
  else
    # We're on a posix platform. Hooray! :)
    path="[$]$1"
    has_space=`$ECHO "$path" | $GREP " "`
    if test "x$has_space" != x; then
      AC_MSG_NOTICE([The path of $1, which resolves as "$path", is invalid.])
      AC_MSG_ERROR([Spaces are not allowed in this path.])
77
    fi
78 79 80 81 82 83 84

    # Use eval to expand a potential ~
    eval path="$path"
    if test ! -f "$path" && test ! -d "$path"; then
      AC_MSG_ERROR([The path of $1, which resolves as "$path", is not found.])
    fi

85
    $1="`cd "$path"; $THEPWDCMD -L`"
O
ohair 已提交
86
  fi
87 88
])

O
ohair 已提交
89 90 91 92 93 94 95 96 97 98 99 100
# 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 posix 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
AC_DEFUN([BASIC_FIXUP_EXECUTABLE],
101
[
O
ohair 已提交
102 103 104 105 106 107 108 109 110 111 112 113 114
  if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
    BASIC_FIXUP_EXECUTABLE_CYGWIN($1)
  elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
    BASIC_FIXUP_EXECUTABLE_MSYS($1)
  else
    # We're on a posix platform. Hooray! :)
    # First separate the path from the arguments. This will split at the first
    # space.
    complete="[$]$1"
    path="${complete%% *}"
    tmp="$complete EOL"
    arguments="${tmp#* }"

115 116 117 118 119 120 121 122 123 124 125 126 127 128
    # Cannot rely on the command "which" here since it doesn't always work.
    is_absolute_path=`$ECHO "$path" | $GREP ^/`
    if test -z "$is_absolute_path"; then
      # Path to executable is not absolute. Find it.
      IFS_save="$IFS"
      IFS=:
      for p in $PATH; do
        if test -f "$p/$path" && test -x "$p/$path"; then
          new_path="$p/$path"
          break
        fi
      done
      IFS="$IFS_save"
    else
129
      # This is an absolute path, we can use it without further modifications.
130 131
      new_path="$path"
    fi
132

O
ohair 已提交
133
    if test "x$new_path" = x; then
134 135 136 137
      AC_MSG_NOTICE([The path of $1, which resolves as "$complete", is not found.])
      has_space=`$ECHO "$complete" | $GREP " "`
      if test "x$has_space" != x; then
        AC_MSG_NOTICE([This might be caused by spaces in the path, which is not allowed.])
O
ohair 已提交
138
      fi
139 140
      AC_MSG_ERROR([Cannot locate the the path of $1])
    fi
O
ohair 已提交
141 142
  fi

143 144 145 146 147 148
  # Now join together the path and the arguments once again
  if test "x$arguments" != xEOL; then
    new_complete="$new_path ${arguments% *}"
  else
    new_complete="$new_path"
  fi
O
ohair 已提交
149 150

  if test "x$complete" != "x$new_complete"; then
151 152 153
    $1="$new_complete"
    AC_MSG_NOTICE([Rewriting $1 to "$new_complete"])
  fi
154 155
])

O
ohair 已提交
156
AC_DEFUN([BASIC_REMOVE_SYMBOLIC_LINKS],
157
[
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
  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.
      ISGNU=`$READLINK --version 2>&1 | $GREP GNU`
      if test "x$ISGNU" = x; then
        # A readlink that we do not know how to use.
        # Are there other non-GNU readlinks out there?
        READLINK_TESTED=yes
        READLINK=
      fi
    fi
173

174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
    if test "x$READLINK" != 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 `$THEPWDCMD -P`
      sym_link_dir=`$THEPWDCMD -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
192
        fi
193 194 195 196 197 198 199 200 201
        # Again resolve directory symlinks since the target of the just found
        # link could be in a different directory
        cd `$DIRNAME $ISLINK`
        sym_link_dir=`$THEPWDCMD -P`
        sym_link_file=`$BASENAME $ISLINK`
        let COUNTER=COUNTER+1
      done
      cd $STARTDIR
      $1=$sym_link_dir/$sym_link_file
202
    fi
203
  fi
204 205
])

206 207 208 209 210 211 212 213 214
# Register a --with argument but mark it as deprecated
# $1: The name of the with argument to deprecate, not including --with-
AC_DEFUN([BASIC_DEPRECATED_ARG_WITH],
[
  AC_ARG_WITH($1, [AS_HELP_STRING([--with-$1],
      [Deprecated. Option is kept for backwards compatibility and is ignored])],
      [AC_MSG_WARN([Option --with-$1 is deprecated and will be ignored.])])
])

215 216 217 218 219 220 221 222 223 224 225 226
# Register a --enable argument but mark it as deprecated
# $1: The name of the with argument to deprecate, not including --enable-
# $2: The name of the argument to deprecate, in shell variable style (i.e. with _ instead of -)
AC_DEFUN([BASIC_DEPRECATED_ARG_ENABLE],
[
  AC_ARG_ENABLE($1, [AS_HELP_STRING([--enable-$1],
      [Deprecated. Option is kept for backwards compatibility and is ignored])])
  if test "x$enable_$2" != x; then
    AC_MSG_WARN([Option --enable-$1 is deprecated and will be ignored.])
  fi
])

227 228
AC_DEFUN_ONCE([BASIC_INIT],
[
229 230 231 232 233 234
  # Save the original command line. This is passed to us by the wrapper configure script.
  AC_SUBST(CONFIGURE_COMMAND_LINE)
  DATE_WHEN_CONFIGURED=`LANG=C date`
  AC_SUBST(DATE_WHEN_CONFIGURED)
  AC_MSG_NOTICE([Configuration created at $DATE_WHEN_CONFIGURED.])
  AC_MSG_NOTICE([configure script generated at timestamp $DATE_WHEN_GENERATED.])
O
ohair 已提交
235 236 237 238 239 240
])

# Test that variable $1 denoting a program is not empty. If empty, exit with an error.
# $1: variable to check
AC_DEFUN([BASIC_CHECK_NONEMPTY],
[
241
  if test "x[$]$1" = x; then
242 243 244 245 246 247 248 249 250 251 252
    AC_MSG_ERROR([Could not find required tool for $1])
  fi
])

# Check that there are no unprocessed overridden variables left.
# If so, they are an incorrect argument and we will exit with an error.
AC_DEFUN([BASIC_CHECK_LEFTOVER_OVERRIDDEN],
[
  if test "x$CONFIGURE_OVERRIDDEN_VARIABLES" != x; then
    # Replace the separating ! with spaces before presenting for end user.
    unknown_variables=${CONFIGURE_OVERRIDDEN_VARIABLES//!/ }
253
    AC_MSG_WARN([The following variables might be unknown to configure: $unknown_variables])
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
  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
AC_DEFUN([BASIC_SETUP_TOOL],
[
  # Publish this variable in the help.
  AC_ARG_VAR($1, [Override default value for $1])

  if test "x[$]$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
282
    else
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
      # 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"

      # Check if the provided tool contains a complete path.
      tool_specified="[$]$1"
      tool_basename="${tool_specified##*/}"
      if test "x$tool_basename" = "x$tool_specified"; then
        # A command without a complete path is provided, search $PATH.
        AC_MSG_NOTICE([Will search for user supplied tool $1=$tool_basename])
        AC_PATH_PROG($1, $tool_basename)
        if test "x[$]$1" = x; then
          AC_MSG_ERROR([User supplied tool $tool_basename could not be found])
        fi
      else
        # Otherwise we believe it is a complete path. Use it as it is.
        AC_MSG_NOTICE([Will use user supplied tool $1=$tool_specified])
        AC_MSG_CHECKING([for $1])
        if test ! -x "$tool_specified"; then
          AC_MSG_RESULT([not found])
          AC_MSG_ERROR([User supplied tool $1=$tool_specified does not exist or is not executable])
        fi
        AC_MSG_RESULT([$tool_specified])
      fi
O
ohair 已提交
310
    fi
311
  fi
O
ohair 已提交
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
# Call BASIC_SETUP_TOOL with AC_PATH_PROGS to locate the tool
# $1: variable to set
# $2: executable name (or list of names) to look for
AC_DEFUN([BASIC_PATH_PROGS],
[
  BASIC_SETUP_TOOL($1, [AC_PATH_PROGS($1, $2)])
])

# Call BASIC_SETUP_TOOL with AC_CHECK_TOOLS to locate the tool
# $1: variable to set
# $2: executable name (or list of names) to look for
AC_DEFUN([BASIC_CHECK_TOOLS],
[
  BASIC_SETUP_TOOL($1, [AC_CHECK_TOOLS($1, $2)])
])

# Like BASIC_PATH_PROGS but fails if no tool was found.
# $1: variable to set
# $2: executable name (or list of names) to look for
AC_DEFUN([BASIC_REQUIRE_PROGS],
[
  BASIC_PATH_PROGS($1, $2)
  BASIC_CHECK_NONEMPTY($1)
])

# Like BASIC_SETUP_TOOL but fails if no tool was found.
O
ohair 已提交
340
# $1: variable to set
341 342
# $2: autoconf macro to call to look for the special tool
AC_DEFUN([BASIC_REQUIRE_SPECIAL],
O
ohair 已提交
343
[
344 345
  BASIC_SETUP_TOOL($1, [$2])
  BASIC_CHECK_NONEMPTY($1)
O
ohair 已提交
346 347 348 349 350 351
])

# Setup the most fundamental tools that relies on not much else to set up,
# but is used by much of the early bootstrap code.
AC_DEFUN_ONCE([BASIC_SETUP_FUNDAMENTAL_TOOLS],
[
352 353 354 355 356 357 358
  # Start with tools that do not need have cross compilation support
  # and can be expected to be found in the default PATH. These tools are
  # used by configure. Nor are these tools expected to be found in the
  # devkit from the builddeps server either, since they are
  # needed to download the devkit.

  # First are all the simple required tools.
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
  BASIC_REQUIRE_PROGS(BASENAME, basename)
  BASIC_REQUIRE_PROGS(BASH, bash)
  BASIC_REQUIRE_PROGS(CAT, cat)
  BASIC_REQUIRE_PROGS(CHMOD, chmod)
  BASIC_REQUIRE_PROGS(CMP, cmp)
  BASIC_REQUIRE_PROGS(COMM, comm)
  BASIC_REQUIRE_PROGS(CP, cp)
  BASIC_REQUIRE_PROGS(CPIO, cpio)
  BASIC_REQUIRE_PROGS(CUT, cut)
  BASIC_REQUIRE_PROGS(DATE, date)
  BASIC_REQUIRE_PROGS(DIFF, [gdiff diff])
  BASIC_REQUIRE_PROGS(DIRNAME, dirname)
  BASIC_REQUIRE_PROGS(ECHO, echo)
  BASIC_REQUIRE_PROGS(EXPR, expr)
  BASIC_REQUIRE_PROGS(FILE, file)
  BASIC_REQUIRE_PROGS(FIND, find)
  BASIC_REQUIRE_PROGS(HEAD, head)
  BASIC_REQUIRE_PROGS(LN, ln)
  BASIC_REQUIRE_PROGS(LS, ls)
  BASIC_REQUIRE_PROGS(MKDIR, mkdir)
  BASIC_REQUIRE_PROGS(MKTEMP, mktemp)
  BASIC_REQUIRE_PROGS(MV, mv)
  BASIC_REQUIRE_PROGS(NAWK, [nawk gawk awk])
  BASIC_REQUIRE_PROGS(PRINTF, printf)
  BASIC_REQUIRE_PROGS(RM, rm)
  BASIC_REQUIRE_PROGS(SH, sh)
  BASIC_REQUIRE_PROGS(SORT, sort)
  BASIC_REQUIRE_PROGS(TAIL, tail)
  BASIC_REQUIRE_PROGS(TAR, tar)
  BASIC_REQUIRE_PROGS(TEE, tee)
  BASIC_REQUIRE_PROGS(TOUCH, touch)
  BASIC_REQUIRE_PROGS(TR, tr)
  BASIC_REQUIRE_PROGS(UNAME, uname)
  BASIC_REQUIRE_PROGS(UNIQ, uniq)
  BASIC_REQUIRE_PROGS(WC, wc)
  BASIC_REQUIRE_PROGS(WHICH, which)
  BASIC_REQUIRE_PROGS(XARGS, xargs)
396 397

  # Then required tools that require some special treatment.
398 399 400 401 402
  BASIC_REQUIRE_SPECIAL(AWK, [AC_PROG_AWK])
  BASIC_REQUIRE_SPECIAL(GREP, [AC_PROG_GREP])
  BASIC_REQUIRE_SPECIAL(EGREP, [AC_PROG_EGREP])
  BASIC_REQUIRE_SPECIAL(FGREP, [AC_PROG_FGREP])
  BASIC_REQUIRE_SPECIAL(SED, [AC_PROG_SED])
403 404 405 406 407 408 409 410 411

  # Always force rm.
  RM="$RM -f"

  # pwd behaves differently on various platforms and some don't support the -L flag.
  # Always use the bash builtin pwd to get uniform behavior.
  THEPWDCMD=pwd

  # These are not required on all platforms
412 413 414 415
  BASIC_PATH_PROGS(CYGPATH, cygpath)
  BASIC_PATH_PROGS(READLINK, [greadlink readlink])
  BASIC_PATH_PROGS(DF, df)
  BASIC_PATH_PROGS(SETFILE, SetFile)
416
])
417

418 419 420
# Setup basic configuration paths, and platform-specific stuff related to PATHs.
AC_DEFUN_ONCE([BASIC_SETUP_PATHS],
[
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
  # Locate the directory of this script.
  SCRIPT="[$]0"
  AUTOCONF_DIR=`cd \`$DIRNAME $SCRIPT\`; $THEPWDCMD -L`

  # Where is the source? It is located two levels above the configure script.
  CURDIR="$PWD"
  cd "$AUTOCONF_DIR/../.."
  SRC_ROOT="`$THEPWDCMD -L`"

  if test "x$OPENJDK_TARGET_OS" = "xwindows"; then
    PATH_SEP=";"
    BASIC_CHECK_PATHS_WINDOWS
  else
    PATH_SEP=":"
  fi

  AC_SUBST(SRC_ROOT)
  AC_SUBST(PATH_SEP)
  cd "$CURDIR"

  BASIC_FIXUP_PATH(SRC_ROOT)
  BASIC_FIXUP_PATH(CURDIR)

  if test "x$OPENJDK_BUILD_OS" = "xsolaris"; then
445 446
    # Add extra search paths on solaris for utilities like ar and as etc...
    PATH="$PATH:/usr/ccs/bin:/usr/sfw/bin:/opt/csw/bin"
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
  fi

  # You can force the sys-root if the sys-root encoded into the cross compiler tools
  # is not correct.
  AC_ARG_WITH(sys-root, [AS_HELP_STRING([--with-sys-root],
      [pass this sys-root to the compilers and tools (for cross-compiling)])])

  if test "x$with_sys_root" != x; then
    SYS_ROOT=$with_sys_root
  else
    SYS_ROOT=/
  fi
  AC_SUBST(SYS_ROOT)

  AC_ARG_WITH([tools-dir], [AS_HELP_STRING([--with-tools-dir],
      [search this directory for compilers and tools (for cross-compiling)])],
      [TOOLS_DIR=$with_tools_dir]
  )

466 467 468 469 470 471
  # Xcode version will be validated later
  AC_ARG_WITH([xcode-path], [AS_HELP_STRING([--with-xcode-path],
      [explicit path to Xcode 4 (generally for building on 10.9 and later)])],
      [XCODE_PATH=$with_xcode_path]
  )

472 473 474 475 476 477 478 479 480 481 482 483 484 485
  AC_ARG_WITH([devkit], [AS_HELP_STRING([--with-devkit],
      [use this directory as base for tools-dir and sys-root (for cross-compiling)])],
      [
        if test "x$with_sys_root" != x; then
          AC_MSG_ERROR([Cannot specify both --with-devkit and --with-sys-root at the same time])
        fi
        BASIC_FIXUP_PATH([with_devkit])
        BASIC_APPEND_TO_PATH([TOOLS_DIR],$with_devkit/bin)
        if test -d "$with_devkit/$host_alias/libc"; then
          SYS_ROOT=$with_devkit/$host_alias/libc
        elif test -d "$with_devkit/$host/sys-root"; then
          SYS_ROOT=$with_devkit/$host/sys-root
        fi
      ])
486 487 488 489 490
])

AC_DEFUN_ONCE([BASIC_SETUP_OUTPUT_DIR],
[

491 492 493
  AC_ARG_WITH(conf-name, [AS_HELP_STRING([--with-conf-name],
      [use this as the name of the configuration @<:@generated from important configuration options@:>@])],
      [ CONF_NAME=${with_conf_name} ])
494

495 496 497
  # Test from where we are running configure, in or outside of src root.
  if test "x$CURDIR" = "x$SRC_ROOT" || test "x$CURDIR" = "x$SRC_ROOT/common" \
      || test "x$CURDIR" = "x$SRC_ROOT/common/autoconf" \
I
ihse 已提交
498
      || test "x$CURDIR" = "x$SRC_ROOT/make" ; then
499 500 501
    # We are running configure from the src root.
    # Create a default ./build/target-variant-debuglevel output root.
    if test "x${CONF_NAME}" = x; then
502
      CONF_NAME="${OPENJDK_TARGET_OS}-${OPENJDK_TARGET_CPU}-${JDK_VARIANT}-${ANDED_JVM_VARIANTS}-${DEBUG_LEVEL}"
503 504
    fi
    OUTPUT_ROOT="$SRC_ROOT/build/${CONF_NAME}"
O
ohair 已提交
505
    $MKDIR -p "$OUTPUT_ROOT"
506
    if test ! -d "$OUTPUT_ROOT"; then
507
      AC_MSG_ERROR([Could not create build directory $OUTPUT_ROOT])
508
    fi
509
  else
510 511 512 513 514
    # We are running configure from outside of the src dir.
    # Then use the current directory as output dir!
    # If configuration is situated in normal build directory, just use the build
    # directory name as configuration name, otherwise use the complete path.
    if test "x${CONF_NAME}" = x; then
515
      CONF_NAME=`$ECHO $CURDIR | $SED -e "s!^${SRC_ROOT}/build/!!"`
516 517
    fi
    OUTPUT_ROOT="$CURDIR"
518 519 520 521 522 523 524 525

    # WARNING: This might be a bad thing to do. You need to be sure you want to
    # have a configuration in this directory. Do some sanity checks!

    if test ! -e "$OUTPUT_ROOT/spec.gmk"; then
      # If we have a spec.gmk, we have run here before and we are OK. Otherwise, check for
      # other files
      files_present=`$LS $OUTPUT_ROOT`
526
      # Configure has already touched config.log and confdefs.h in the current dir when this check
527 528
      # is performed.
      filtered_files=`$ECHO "$files_present" | $SED -e 's/config.log//g' -e 's/confdefs.h//g' -e 's/ //g' \
529
      | $TR -d '\n'`
530
      if test "x$filtered_files" != x; then
531 532 533 534 535 536 537 538 539 540
        AC_MSG_NOTICE([Current directory is $CURDIR.])
        AC_MSG_NOTICE([Since this is not the source root, configure will output the configuration here])
        AC_MSG_NOTICE([(as opposed to creating a configuration in <src_root>/build/<conf-name>).])
        AC_MSG_NOTICE([However, this directory is not empty. This is not allowed, since it could])
        AC_MSG_NOTICE([seriously mess up just about everything.])
        AC_MSG_NOTICE([Try 'cd $SRC_ROOT' and restart configure])
        AC_MSG_NOTICE([(or create a new empty directory and cd to it).])
        AC_MSG_ERROR([Will not continue creating configuration in $CURDIR])
      fi
    fi
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
  fi
  AC_MSG_CHECKING([what configuration name to use])
  AC_MSG_RESULT([$CONF_NAME])

  BASIC_FIXUP_PATH(OUTPUT_ROOT)

  AC_SUBST(SPEC, $OUTPUT_ROOT/spec.gmk)
  AC_SUBST(CONF_NAME, $CONF_NAME)
  AC_SUBST(OUTPUT_ROOT, $OUTPUT_ROOT)

  # Most of the probed defines are put into config.h
  AC_CONFIG_HEADERS([$OUTPUT_ROOT/config.h:$AUTOCONF_DIR/config.h.in])
  # The spec.gmk file contains all variables for the make system.
  AC_CONFIG_FILES([$OUTPUT_ROOT/spec.gmk:$AUTOCONF_DIR/spec.gmk.in])
  # The hotspot-spec.gmk file contains legacy variables for the hotspot make system.
  AC_CONFIG_FILES([$OUTPUT_ROOT/hotspot-spec.gmk:$AUTOCONF_DIR/hotspot-spec.gmk.in])
  # The bootcycle-spec.gmk file contains support for boot cycle builds.
  AC_CONFIG_FILES([$OUTPUT_ROOT/bootcycle-spec.gmk:$AUTOCONF_DIR/bootcycle-spec.gmk.in])
  # The compare.sh is used to compare the build output to other builds.
  AC_CONFIG_FILES([$OUTPUT_ROOT/compare.sh:$AUTOCONF_DIR/compare.sh.in])
  # Spec.sh is currently used by compare-objects.sh
  AC_CONFIG_FILES([$OUTPUT_ROOT/spec.sh:$AUTOCONF_DIR/spec.sh.in])
  # The generated Makefile knows where the spec.gmk is and where the source is.
  # You can run make from the OUTPUT_ROOT, or from the top-level Makefile
  # which will look for generated configurations
  AC_CONFIG_FILES([$OUTPUT_ROOT/Makefile:$AUTOCONF_DIR/Makefile.in])

  # Save the arguments given to us
  echo "$CONFIGURE_COMMAND_LINE" > $OUTPUT_ROOT/configure-arguments
570 571 572 573
])

AC_DEFUN_ONCE([BASIC_SETUP_LOGGING],
[
574 575 576 577 578 579 580
  # Setup default logging of stdout and stderr to build.log in the output root.
  BUILD_LOG='$(OUTPUT_ROOT)/build.log'
  BUILD_LOG_PREVIOUS='$(OUTPUT_ROOT)/build.log.old'
  BUILD_LOG_WRAPPER='$(BASH) $(SRC_ROOT)/common/bin/logger.sh $(BUILD_LOG)'
  AC_SUBST(BUILD_LOG)
  AC_SUBST(BUILD_LOG_PREVIOUS)
  AC_SUBST(BUILD_LOG_WRAPPER)
581 582 583 584 585
])


#%%% Simple tools %%%

586 587 588 589 590 591 592 593 594 595 596 597 598 599
# Check if we have found a usable version of make
# $1: the path to a potential make binary (or empty)
# $2: the description on how we found this
AC_DEFUN([BASIC_CHECK_MAKE_VERSION],
[
  MAKE_CANDIDATE="$1"
  DESCRIPTION="$2"
  if test "x$MAKE_CANDIDATE" != x; then
    AC_MSG_NOTICE([Testing potential make at $MAKE_CANDIDATE, found using $DESCRIPTION])
    MAKE_VERSION_STRING=`$MAKE_CANDIDATE --version | $HEAD -n 1`
    IS_GNU_MAKE=`$ECHO $MAKE_VERSION_STRING | $GREP 'GNU Make'`
    if test "x$IS_GNU_MAKE" = x; then
      AC_MSG_NOTICE([Found potential make at $MAKE_CANDIDATE, however, this is not GNU Make. Ignoring.])
    else
600
      IS_MODERN_MAKE=`$ECHO $MAKE_VERSION_STRING | $GREP -e '3\.8[[12]]' -e '4\.'`
601 602
      if test "x$IS_MODERN_MAKE" = x; then
        AC_MSG_NOTICE([Found GNU make at $MAKE_CANDIDATE, however this is not version 3.81 or later. (it is: $MAKE_VERSION_STRING). Ignoring.])
O
ohair 已提交
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
      else
        if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
          if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
            MAKE_EXPECTED_ENV='cygwin'
          elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
            MAKE_EXPECTED_ENV='msys'
          else
            AC_MSG_ERROR([Unknown Windows environment])
          fi
          MAKE_BUILT_FOR=`$MAKE_CANDIDATE --version | $GREP -i 'built for'`
          IS_MAKE_CORRECT_ENV=`$ECHO $MAKE_BUILT_FOR | $GREP $MAKE_EXPECTED_ENV`
        else
          # Not relevant for non-Windows
          IS_MAKE_CORRECT_ENV=true
        fi
        if test "x$IS_MAKE_CORRECT_ENV" = x; then
          AC_MSG_NOTICE([Found GNU make version $MAKE_VERSION_STRING at $MAKE_CANDIDATE, but it is not for $MAKE_EXPECTED_ENV (it says: $MAKE_BUILT_FOR). Ignoring.])
        else
          FOUND_MAKE=$MAKE_CANDIDATE
          BASIC_FIXUP_EXECUTABLE(FOUND_MAKE)
        fi
624 625 626 627 628 629 630 631 632 633 634 635 636 637
      fi
    fi
  fi
])

# Goes looking for a usable version of GNU make.
AC_DEFUN([BASIC_CHECK_GNU_MAKE],
[
  # We need to find a recent version of GNU make. Especially on Solaris, this can be tricky.
  if test "x$MAKE" != x; then
    # User has supplied a make, test it.
    if test ! -f "$MAKE"; then
      AC_MSG_ERROR([The specified make (by MAKE=$MAKE) is not found.])
    fi
O
ohair 已提交
638
    BASIC_CHECK_MAKE_VERSION("$MAKE", [user supplied MAKE=$MAKE])
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
    if test "x$FOUND_MAKE" = x; then
      AC_MSG_ERROR([The specified make (by MAKE=$MAKE) is not GNU make 3.81 or newer.])
    fi
  else
    # Try our hardest to locate a correct version of GNU make
    AC_PATH_PROGS(CHECK_GMAKE, gmake)
    BASIC_CHECK_MAKE_VERSION("$CHECK_GMAKE", [gmake in PATH])

    if test "x$FOUND_MAKE" = x; then
      AC_PATH_PROGS(CHECK_MAKE, make)
      BASIC_CHECK_MAKE_VERSION("$CHECK_MAKE", [make in PATH])
    fi

    if test "x$FOUND_MAKE" = x; then
      if test "x$TOOLS_DIR" != x; then
        # We have a tools-dir, check that as well before giving up.
        OLD_PATH=$PATH
        PATH=$TOOLS_DIR:$PATH
        AC_PATH_PROGS(CHECK_TOOLSDIR_GMAKE, gmake)
        BASIC_CHECK_MAKE_VERSION("$CHECK_TOOLSDIR_GMAKE", [gmake in tools-dir])
        if test "x$FOUND_MAKE" = x; then
          AC_PATH_PROGS(CHECK_TOOLSDIR_MAKE, make)
          BASIC_CHECK_MAKE_VERSION("$CHECK_TOOLSDIR_MAKE", [make in tools-dir])
        fi
        PATH=$OLD_PATH
      fi
    fi

    if test "x$FOUND_MAKE" = x; then
      AC_MSG_ERROR([Cannot find GNU make 3.81 or newer! Please put it in the path, or add e.g. MAKE=/opt/gmake3.81/make as argument to configure.])
    fi
  fi

  MAKE=$FOUND_MAKE
  AC_SUBST(MAKE)
  AC_MSG_NOTICE([Using GNU make 3.81 (or later) at $FOUND_MAKE (version: $MAKE_VERSION_STRING)])
])

677 678
AC_DEFUN([BASIC_CHECK_FIND_DELETE],
[
679 680 681
  # Test if find supports -delete
  AC_MSG_CHECKING([if find supports -delete])
  FIND_DELETE="-delete"
682

683
  DELETEDIR=`$MKTEMP -d tmp.XXXXXXXXXX` || (echo Could not create temporary directory!; exit $?)
684

685
  echo Hejsan > $DELETEDIR/TestIfFindSupportsDelete
686

687 688 689 690 691 692 693 694 695 696 697
  TEST_DELETE=`$FIND "$DELETEDIR" -name TestIfFindSupportsDelete $FIND_DELETE 2>&1`
  if test -f $DELETEDIR/TestIfFindSupportsDelete; then
    # No, it does not.
    rm $DELETEDIR/TestIfFindSupportsDelete
    FIND_DELETE="-exec rm \{\} \+"
    AC_MSG_RESULT([no])
  else
    AC_MSG_RESULT([yes])
  fi
  rmdir $DELETEDIR
  AC_SUBST(FIND_DELETE)
698 699
])

O
ohair 已提交
700
AC_DEFUN_ONCE([BASIC_SETUP_COMPLEX_TOOLS],
701
[
702
  BASIC_CHECK_GNU_MAKE
703

704
  BASIC_CHECK_FIND_DELETE
705

706 707
  # These tools might not be installed by default,
  # need hint on how to install them.
708 709
  BASIC_REQUIRE_PROGS(UNZIP, unzip)
  BASIC_REQUIRE_PROGS(ZIP, zip)
710

711
  # Non-required basic tools
712

713
  BASIC_PATH_PROGS(LDD, ldd)
714
  if test "x$LDD" = "x"; then
715 716 717 718
    # List shared lib dependencies is used for
    # debug output and checking for forbidden dependencies.
    # We can build without it.
    LDD="true"
719
  fi
720 721 722 723
  BASIC_PATH_PROGS(READELF, [readelf greadelf])
  BASIC_PATH_PROGS(HG, hg)
  BASIC_PATH_PROGS(STAT, stat)
  BASIC_PATH_PROGS(TIME, time)
724 725 726 727 728 729 730 731 732 733
  # Check if it's GNU time
  IS_GNU_TIME=`$TIME --version 2>&1 | $GREP 'GNU time'`
  if test "x$IS_GNU_TIME" != x; then
    IS_GNU_TIME=yes
  else
    IS_GNU_TIME=no
  fi
  AC_SUBST(IS_GNU_TIME)

  if test "x$OPENJDK_TARGET_OS" = "xwindows"; then
734
    BASIC_REQUIRE_PROGS(COMM, comm)
735 736 737
  fi

  if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
738 739 740
    BASIC_REQUIRE_PROGS(DSYMUTIL, dsymutil)
    BASIC_REQUIRE_PROGS(XATTR, xattr)
    BASIC_PATH_PROGS(CODESIGN, codesign)
741 742 743 744 745 746 747 748 749 750 751 752
    if test "x$CODESIGN" != "x"; then
      # Verify that the openjdk_codesign certificate is present
      AC_MSG_CHECKING([if openjdk_codesign certificate is present])
      rm -f codesign-testfile
      touch codesign-testfile
      codesign -s openjdk_codesign codesign-testfile 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD || CODESIGN=
      rm -f codesign-testfile
      if test "x$CODESIGN" = x; then
        AC_MSG_RESULT([no])
      else
        AC_MSG_RESULT([yes])
      fi
753 754
    fi
  fi
755 756
])

O
ohair 已提交
757 758
# Check if build directory is on local disk. If not possible to determine,
# we prefer to claim it's local.
759 760 761 762 763
# Argument 1: directory to test
# Argument 2: what to do if it is on local disk
# Argument 3: what to do otherwise (remote disk or failure)
AC_DEFUN([BASIC_CHECK_DIR_ON_LOCAL_DISK],
[
764 765
  # df -l lists only local disks; if the given directory is not found then
  # a non-zero exit code is given
O
ohair 已提交
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
  if test "x$DF" = x; then
    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
      # msys does not have df; use Windows "net use" instead.
      IS_NETWORK_DISK=`net use | grep \`pwd -W | cut -d ":" -f 1 | tr a-z A-Z\`:`
      if test "x$IS_NETWORK_DISK" = x; then
        $2
      else
        $3
      fi
    else
      # No df here, say it's local
      $2
    fi
  else
    if $DF -l $1 > /dev/null 2>&1; then
      $2
    else
      $3
    fi
  fi
786 787
])

788 789 790 791 792 793 794 795 796 797 798 799
# Check that source files have basic read permissions set. This might
# not be the case in cygwin in certain conditions.
AC_DEFUN_ONCE([BASIC_CHECK_SRC_PERMS],
[
  if test x"$OPENJDK_BUILD_OS" = xwindows; then
    file_to_test="$SRC_ROOT/LICENSE"
    if test `$STAT -c '%a' "$file_to_test"` -lt 400; then
      AC_MSG_ERROR([Bad file permissions on src files. This is usually caused by cloning the repositories with a non cygwin hg in a directory not created in cygwin.])
    fi
  fi
])

800 801
AC_DEFUN_ONCE([BASIC_TEST_USABILITY_ISSUES],
[
802 803 804
  # Did user specify any unknown variables?
  BASIC_CHECK_LEFTOVER_OVERRIDDEN

805 806 807 808 809 810 811 812 813 814
  AC_MSG_CHECKING([if build directory is on local disk])
  BASIC_CHECK_DIR_ON_LOCAL_DISK($OUTPUT_ROOT,
      [OUTPUT_DIR_IS_LOCAL="yes"],
      [OUTPUT_DIR_IS_LOCAL="no"])
  AC_MSG_RESULT($OUTPUT_DIR_IS_LOCAL)

  BASIC_CHECK_SRC_PERMS

  # Check if the user has any old-style ALT_ variables set.
  FOUND_ALT_VARIABLES=`env | grep ^ALT_`
815

816 817 818 819 820 821 822
  # Before generating output files, test if they exist. If they do, this is a reconfigure.
  # Since we can't properly handle the dependencies for this, warn the user about the situation
  if test -e $OUTPUT_ROOT/spec.gmk; then
    IS_RECONFIGURE=yes
  else
    IS_RECONFIGURE=no
  fi
823
])