basics.m4 revision 1715:d7c06f4e28b2
139212Sgibbs#
239212Sgibbs# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
339212Sgibbs# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
439212Sgibbs#
539212Sgibbs# This code is free software; you can redistribute it and/or modify it
639212Sgibbs# under the terms of the GNU General Public License version 2 only, as
739212Sgibbs# published by the Free Software Foundation.  Oracle designates this
839212Sgibbs# particular file as subject to the "Classpath" exception as provided
939212Sgibbs# by Oracle in the LICENSE file that accompanied this code.
1039212Sgibbs#
1139212Sgibbs# This code is distributed in the hope that it will be useful, but WITHOUT
1239212Sgibbs# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1339212Sgibbs# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1439212Sgibbs# version 2 for more details (a copy is included in the LICENSE file that
1539212Sgibbs# accompanied this code).
1639212Sgibbs#
1739212Sgibbs# You should have received a copy of the GNU General Public License version
1839212Sgibbs# 2 along with this work; if not, write to the Free Software Foundation,
1939212Sgibbs# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2039212Sgibbs#
2139212Sgibbs# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2239212Sgibbs# or visit www.oracle.com if you need additional information or have any
2339212Sgibbs# questions.
2439212Sgibbs#
2539212Sgibbs
2639212Sgibbs# Test if $1 is a valid argument to $3 (often is $JAVA passed as $3)
2739212Sgibbs# If so, then append $1 to $2 \
2839212Sgibbs# Also set JVM_ARG_OK to true/false depending on outcome.
2939460SkenAC_DEFUN([ADD_JVM_ARG_IF_OK],
3039212Sgibbs[
3139212Sgibbs  $ECHO "Check if jvm arg is ok: $1" >&AS_MESSAGE_LOG_FD
3239212Sgibbs  $ECHO "Command: $3 $1 -version" >&AS_MESSAGE_LOG_FD
3339212Sgibbs  OUTPUT=`$3 $1 -version 2>&1`
3439212Sgibbs  FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn`
3539212Sgibbs  FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""`
3639212Sgibbs  if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then
3739212Sgibbs    $2="[$]$2 $1"
3839212Sgibbs    JVM_ARG_OK=true
3939212Sgibbs  else
4039212Sgibbs    $ECHO "Arg failed:" >&AS_MESSAGE_LOG_FD
4139212Sgibbs    $ECHO "$OUTPUT" >&AS_MESSAGE_LOG_FD
4239212Sgibbs    JVM_ARG_OK=false
4339212Sgibbs  fi
4439212Sgibbs])
4539212Sgibbs
4639212Sgibbs# Appends a string to a path variable, only adding the : when needed.
4739212SgibbsAC_DEFUN([BASIC_APPEND_TO_PATH],
4839212Sgibbs[
4939212Sgibbs  if test "x$2" != x; then
5039212Sgibbs    if test "x[$]$1" = x; then
5139212Sgibbs      $1="$2"
5239212Sgibbs    else
5339212Sgibbs      $1="[$]$1:$2"
5439212Sgibbs    fi
5539212Sgibbs  fi
5639212Sgibbs])
5739212Sgibbs
5839212Sgibbs# Prepends a string to a path variable, only adding the : when needed.
5939212SgibbsAC_DEFUN([BASIC_PREPEND_TO_PATH],
6039212Sgibbs[
6139212Sgibbs  if test "x$2" != x; then
6239212Sgibbs    if test "x[$]$1" = x; then
6339212Sgibbs      $1="$2"
6439212Sgibbs    else
6539212Sgibbs      $1="$2:[$]$1"
6639212Sgibbs    fi
6739212Sgibbs  fi
6839212Sgibbs])
6939212Sgibbs
7039212Sgibbs# This will make sure the given variable points to a full and proper
7139212Sgibbs# path. This means:
7239212Sgibbs# 1) There will be no spaces in the path. On unix platforms,
7339212Sgibbs#    spaces in the path will result in an error. On Windows,
7439212Sgibbs#    the path will be rewritten using short-style to be space-free.
7539212Sgibbs# 2) The path will be absolute, and it will be in unix-style (on
7639212Sgibbs#     cygwin).
7739212Sgibbs# $1: The name of the variable to fix
7839212SgibbsAC_DEFUN([BASIC_FIXUP_PATH],
7939212Sgibbs[
8039212Sgibbs  # Only process if variable expands to non-empty
8139212Sgibbs
8239212Sgibbs  if test "x[$]$1" != x; then
8339212Sgibbs    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
8439212Sgibbs      BASIC_FIXUP_PATH_CYGWIN($1)
8539212Sgibbs    elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
8639212Sgibbs      BASIC_FIXUP_PATH_MSYS($1)
8739212Sgibbs    else
8839212Sgibbs      # We're on a unix platform. Hooray! :)
8939212Sgibbs      path="[$]$1"
9039212Sgibbs      has_space=`$ECHO "$path" | $GREP " "`
9139212Sgibbs      if test "x$has_space" != x; then
9239212Sgibbs        AC_MSG_NOTICE([The path of $1, which resolves as "$path", is invalid.])
9339212Sgibbs        AC_MSG_ERROR([Spaces are not allowed in this path.])
9439212Sgibbs      fi
9539212Sgibbs
9639212Sgibbs      # Use eval to expand a potential ~
9739212Sgibbs      eval path="$path"
9839212Sgibbs      if test ! -f "$path" && test ! -d "$path"; then
9939212Sgibbs        AC_MSG_ERROR([The path of $1, which resolves as "$path", is not found.])
10039442Sken      fi
10139442Sken
10239442Sken      $1="`cd "$path"; $THEPWDCMD -L`"
10339442Sken    fi
10439442Sken  fi
10539442Sken])
10639442Sken
10739442Sken# This will make sure the given variable points to a executable
10839442Sken# with a full and proper path. This means:
10939442Sken# 1) There will be no spaces in the path. On unix platforms,
11039442Sken#    spaces in the path will result in an error. On Windows,
11139442Sken#    the path will be rewritten using short-style to be space-free.
11239442Sken# 2) The path will be absolute, and it will be in unix-style (on
11339212Sgibbs#     cygwin).
11439212Sgibbs# Any arguments given to the executable is preserved.
11539212Sgibbs# If the input variable does not have a directory specification, then
11639212Sgibbs# it need to be in the PATH.
11739212Sgibbs# $1: The name of the variable to fix
11839212SgibbsAC_DEFUN([BASIC_FIXUP_EXECUTABLE],
11939212Sgibbs[
12039212Sgibbs  # Only process if variable expands to non-empty
12139212Sgibbs
12239212Sgibbs  if test "x[$]$1" != x; then
12339212Sgibbs    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
12439212Sgibbs      BASIC_FIXUP_EXECUTABLE_CYGWIN($1)
12539212Sgibbs    elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
12639212Sgibbs      BASIC_FIXUP_EXECUTABLE_MSYS($1)
12739212Sgibbs    else
12839212Sgibbs      # We're on a unix platform. Hooray! :)
12939212Sgibbs      # First separate the path from the arguments. This will split at the first
13039212Sgibbs      # space.
13139212Sgibbs      complete="[$]$1"
13239212Sgibbs      path="${complete%% *}"
13339212Sgibbs      tmp="$complete EOL"
13439212Sgibbs      arguments="${tmp#* }"
13539212Sgibbs
13639212Sgibbs      # Cannot rely on the command "which" here since it doesn't always work.
13739212Sgibbs      is_absolute_path=`$ECHO "$path" | $GREP ^/`
13839212Sgibbs      if test -z "$is_absolute_path"; then
13939212Sgibbs        # Path to executable is not absolute. Find it.
14039212Sgibbs        IFS_save="$IFS"
14139212Sgibbs        IFS=:
14239212Sgibbs        for p in $PATH; do
14339212Sgibbs          if test -f "$p/$path" && test -x "$p/$path"; then
14439212Sgibbs            new_path="$p/$path"
14539212Sgibbs            break
14639212Sgibbs          fi
14739212Sgibbs        done
14839212Sgibbs        IFS="$IFS_save"
14939212Sgibbs      else
15039212Sgibbs        # This is an absolute path, we can use it without further modifications.
15139212Sgibbs        new_path="$path"
15239212Sgibbs      fi
15339212Sgibbs
15439212Sgibbs      if test "x$new_path" = x; then
15539212Sgibbs        AC_MSG_NOTICE([The path of $1, which resolves as "$complete", is not found.])
15639212Sgibbs        has_space=`$ECHO "$complete" | $GREP " "`
15739212Sgibbs        if test "x$has_space" != x; then
15839212Sgibbs          AC_MSG_NOTICE([This might be caused by spaces in the path, which is not allowed.])
15939212Sgibbs        fi
16039212Sgibbs        AC_MSG_ERROR([Cannot locate the the path of $1])
16139212Sgibbs      fi
16239212Sgibbs    fi
16339212Sgibbs
16439212Sgibbs    # Now join together the path and the arguments once again
16539212Sgibbs    if test "x$arguments" != xEOL; then
16639212Sgibbs      new_complete="$new_path ${arguments% *}"
16739212Sgibbs    else
16839212Sgibbs      new_complete="$new_path"
16939212Sgibbs    fi
17039212Sgibbs
17139212Sgibbs    if test "x$complete" != "x$new_complete"; then
17239212Sgibbs      $1="$new_complete"
17339212Sgibbs      AC_MSG_NOTICE([Rewriting $1 to "$new_complete"])
17439212Sgibbs    fi
17539212Sgibbs  fi
17639212Sgibbs])
17739212Sgibbs
17839212SgibbsAC_DEFUN([BASIC_REMOVE_SYMBOLIC_LINKS],
17939212Sgibbs[
18039212Sgibbs  if test "x$OPENJDK_BUILD_OS" != xwindows; then
18139212Sgibbs    # Follow a chain of symbolic links. Use readlink
18239212Sgibbs    # where it exists, else fall back to horribly
18339212Sgibbs    # complicated shell code.
18439212Sgibbs    if test "x$READLINK_TESTED" != yes; then
18539212Sgibbs      # On MacOSX there is a readlink tool with a different
18639212Sgibbs      # purpose than the GNU readlink tool. Check the found readlink.
18739212Sgibbs      ISGNU=`$READLINK --version 2>&1 | $GREP GNU`
18839212Sgibbs      if test "x$ISGNU" = x; then
18939212Sgibbs        # A readlink that we do not know how to use.
19039212Sgibbs        # Are there other non-GNU readlinks out there?
19139212Sgibbs        READLINK_TESTED=yes
19239212Sgibbs        READLINK=
19339212Sgibbs      fi
19439212Sgibbs    fi
19539212Sgibbs
19639212Sgibbs    if test "x$READLINK" != x; then
19739212Sgibbs      $1=`$READLINK -f [$]$1`
19839212Sgibbs    else
19939212Sgibbs      # Save the current directory for restoring afterwards
20039212Sgibbs      STARTDIR=$PWD
20139212Sgibbs      COUNTER=0
20239212Sgibbs      sym_link_dir=`$DIRNAME [$]$1`
20339212Sgibbs      sym_link_file=`$BASENAME [$]$1`
20439212Sgibbs      cd $sym_link_dir
20539212Sgibbs      # Use -P flag to resolve symlinks in directories.
20639212Sgibbs      cd `$THEPWDCMD -P`
20739212Sgibbs      sym_link_dir=`$THEPWDCMD -P`
20839212Sgibbs      # Resolve file symlinks
20939212Sgibbs      while test $COUNTER -lt 20; do
21039212Sgibbs        ISLINK=`$LS -l $sym_link_dir/$sym_link_file | $GREP '\->' | $SED -e 's/.*-> \(.*\)/\1/'`
21139212Sgibbs        if test "x$ISLINK" == x; then
21239212Sgibbs          # This is not a symbolic link! We are done!
21339212Sgibbs          break
21439212Sgibbs        fi
21539212Sgibbs        # Again resolve directory symlinks since the target of the just found
21639212Sgibbs        # link could be in a different directory
21739212Sgibbs        cd `$DIRNAME $ISLINK`
21839212Sgibbs        sym_link_dir=`$THEPWDCMD -P`
21939212Sgibbs        sym_link_file=`$BASENAME $ISLINK`
22039212Sgibbs        let COUNTER=COUNTER+1
22139212Sgibbs      done
22239212Sgibbs      cd $STARTDIR
22339212Sgibbs      $1=$sym_link_dir/$sym_link_file
22439212Sgibbs    fi
22539212Sgibbs  fi
22639212Sgibbs])
22739212Sgibbs
22839212Sgibbs# Register a --with argument but mark it as deprecated
22939212Sgibbs# $1: The name of the with argument to deprecate, not including --with-
23039212SgibbsAC_DEFUN([BASIC_DEPRECATED_ARG_WITH],
23139212Sgibbs[
23239212Sgibbs  AC_ARG_WITH($1, [AS_HELP_STRING([--with-$1],
23339212Sgibbs      [Deprecated. Option is kept for backwards compatibility and is ignored])],
23439212Sgibbs      [AC_MSG_WARN([Option --with-$1 is deprecated and will be ignored.])])
23539212Sgibbs])
23639212Sgibbs
23739212Sgibbs# Register a --enable argument but mark it as deprecated
23839212Sgibbs# $1: The name of the with argument to deprecate, not including --enable-
23939460Sken# $2: The name of the argument to deprecate, in shell variable style (i.e. with _ instead of -)
24039212SgibbsAC_DEFUN([BASIC_DEPRECATED_ARG_ENABLE],
24139212Sgibbs[
24239212Sgibbs  AC_ARG_ENABLE($1, [AS_HELP_STRING([--enable-$1],
24339212Sgibbs      [Deprecated. Option is kept for backwards compatibility and is ignored])])
24439460Sken  if test "x$enable_$2" != x; then
24539212Sgibbs    AC_MSG_WARN([Option --enable-$1 is deprecated and will be ignored.])
24639212Sgibbs  fi
24739212Sgibbs])
24839460Sken
24939460SkenAC_DEFUN_ONCE([BASIC_INIT],
25039460Sken[
25139460Sken  # Save the original command line. This is passed to us by the wrapper configure script.
25239460Sken  AC_SUBST(CONFIGURE_COMMAND_LINE)
25339212Sgibbs  # Save the path variable before it gets changed
25439212Sgibbs  ORIGINAL_PATH="$PATH"
25539212Sgibbs  AC_SUBST(ORIGINAL_PATH)
25639212Sgibbs  DATE_WHEN_CONFIGURED=`LANG=C date`
25739212Sgibbs  AC_SUBST(DATE_WHEN_CONFIGURED)
25839212Sgibbs  AC_MSG_NOTICE([Configuration created at $DATE_WHEN_CONFIGURED.])
25939212Sgibbs  AC_MSG_NOTICE([configure script generated at timestamp $DATE_WHEN_GENERATED.])
26039212Sgibbs])
26139212Sgibbs
26239212Sgibbs# Test that variable $1 denoting a program is not empty. If empty, exit with an error.
26339212Sgibbs# $1: variable to check
26439212SgibbsAC_DEFUN([BASIC_CHECK_NONEMPTY],
26539212Sgibbs[
26639212Sgibbs  if test "x[$]$1" = x; then
26739212Sgibbs    AC_MSG_ERROR([Could not find required tool for $1])
26839212Sgibbs  fi
26939212Sgibbs])
27039212Sgibbs
27139212Sgibbs# Check that there are no unprocessed overridden variables left.
27239212Sgibbs# If so, they are an incorrect argument and we will exit with an error.
27339212SgibbsAC_DEFUN([BASIC_CHECK_LEFTOVER_OVERRIDDEN],
27439212Sgibbs[
27539212Sgibbs  if test "x$CONFIGURE_OVERRIDDEN_VARIABLES" != x; then
27639212Sgibbs    # Replace the separating ! with spaces before presenting for end user.
27739212Sgibbs    unknown_variables=${CONFIGURE_OVERRIDDEN_VARIABLES//!/ }
27839212Sgibbs    AC_MSG_WARN([The following variables might be unknown to configure: $unknown_variables])
27939212Sgibbs  fi
28039212Sgibbs])
28139212Sgibbs
28239212Sgibbs# Setup a tool for the given variable. If correctly specified by the user,
28339212Sgibbs# use that value, otherwise search for the tool using the supplied code snippet.
28439212Sgibbs# $1: variable to set
28539212Sgibbs# $2: code snippet to call to look for the tool
28639212Sgibbs# $3: code snippet to call if variable was used to find tool
28739212SgibbsAC_DEFUN([BASIC_SETUP_TOOL],
28839212Sgibbs[
28939442Sken  # Publish this variable in the help.
29039212Sgibbs  AC_ARG_VAR($1, [Override default value for $1])
29139442Sken
29239442Sken  if [[ -z "${$1+x}" ]]; then
29339212Sgibbs    # The variable is not set by user, try to locate tool using the code snippet
29439212Sgibbs    $2
29539212Sgibbs  else
29639212Sgibbs    # The variable is set, but is it from the command line or the environment?
29739212Sgibbs
29839212Sgibbs    # Try to remove the string !$1! from our list.
29939212Sgibbs    try_remove_var=${CONFIGURE_OVERRIDDEN_VARIABLES//!$1!/}
30039212Sgibbs    if test "x$try_remove_var" = "x$CONFIGURE_OVERRIDDEN_VARIABLES"; then
30139212Sgibbs      # If it failed, the variable was not from the command line. Ignore it,
30239212Sgibbs      # but warn the user (except for BASH, which is always set by the calling BASH).
30339212Sgibbs      if test "x$1" != xBASH; then
30439212Sgibbs        AC_MSG_WARN([Ignoring value of $1 from the environment. Use command line variables instead.])
30539212Sgibbs      fi
30639212Sgibbs      # Try to locate tool using the code snippet
30739212Sgibbs      $2
30839212Sgibbs    else
30939212Sgibbs      # If it succeeded, then it was overridden by the user. We will use it
31039212Sgibbs      # for the tool.
31139212Sgibbs
31239212Sgibbs      # First remove it from the list of overridden variables, so we can test
31339212Sgibbs      # for unknown variables in the end.
31439212Sgibbs      CONFIGURE_OVERRIDDEN_VARIABLES="$try_remove_var"
31539212Sgibbs
31639212Sgibbs      # Check if we try to supply an empty value
31739212Sgibbs      if test "x[$]$1" = x; then
31839212Sgibbs        AC_MSG_NOTICE([Setting user supplied tool $1= (no value)])
31939212Sgibbs        AC_MSG_CHECKING([for $1])
32039212Sgibbs        AC_MSG_RESULT([disabled])
32139212Sgibbs      else
32239212Sgibbs        # Check if the provided tool contains a complete path.
32339212Sgibbs        tool_specified="[$]$1"
32439212Sgibbs        tool_basename="${tool_specified##*/}"
32539212Sgibbs        if test "x$tool_basename" = "x$tool_specified"; then
32639212Sgibbs          # A command without a complete path is provided, search $PATH.
32739212Sgibbs          AC_MSG_NOTICE([Will search for user supplied tool $1=$tool_basename])
32839212Sgibbs          AC_PATH_PROG($1, $tool_basename)
32939212Sgibbs          if test "x[$]$1" = x; then
33039212Sgibbs            AC_MSG_ERROR([User supplied tool $tool_basename could not be found])
33139212Sgibbs          fi
33239212Sgibbs        else
33339212Sgibbs          # Otherwise we believe it is a complete path. Use it as it is.
33439212Sgibbs          AC_MSG_NOTICE([Will use user supplied tool $1=$tool_specified])
33539212Sgibbs          AC_MSG_CHECKING([for $1])
33639212Sgibbs          if test ! -x "$tool_specified"; then
33739212Sgibbs            AC_MSG_RESULT([not found])
33839212Sgibbs            AC_MSG_ERROR([User supplied tool $1=$tool_specified does not exist or is not executable])
33939212Sgibbs          fi
34039212Sgibbs          AC_MSG_RESULT([$tool_specified])
34139212Sgibbs        fi
34239212Sgibbs      fi
34339212Sgibbs    fi
34439212Sgibbs    $3
34539212Sgibbs  fi
34639212Sgibbs])
34739212Sgibbs
34839212Sgibbs# Call BASIC_SETUP_TOOL with AC_PATH_PROGS to locate the tool
34939212Sgibbs# $1: variable to set
35039212Sgibbs# $2: executable name (or list of names) to look for
35139212SgibbsAC_DEFUN([BASIC_PATH_PROGS],
35239212Sgibbs[
35339212Sgibbs  BASIC_SETUP_TOOL($1, [AC_PATH_PROGS($1, $2)])
35439212Sgibbs])
35539212Sgibbs
35639212Sgibbs# Call BASIC_SETUP_TOOL with AC_CHECK_TOOLS to locate the tool
35739212Sgibbs# $1: variable to set
35839212Sgibbs# $2: executable name (or list of names) to look for
35939212SgibbsAC_DEFUN([BASIC_CHECK_TOOLS],
36039212Sgibbs[
36139212Sgibbs  BASIC_SETUP_TOOL($1, [AC_CHECK_TOOLS($1, $2)])
36239212Sgibbs])
36339212Sgibbs
36439212Sgibbs# Like BASIC_PATH_PROGS but fails if no tool was found.
36539212Sgibbs# $1: variable to set
36639212Sgibbs# $2: executable name (or list of names) to look for
36739212SgibbsAC_DEFUN([BASIC_REQUIRE_PROGS],
36839212Sgibbs[
36939212Sgibbs  BASIC_PATH_PROGS($1, $2)
37039212Sgibbs  BASIC_CHECK_NONEMPTY($1)
37139212Sgibbs])
37239212Sgibbs
37339212Sgibbs# Like BASIC_SETUP_TOOL but fails if no tool was found.
37439212Sgibbs# $1: variable to set
37539212Sgibbs# $2: autoconf macro to call to look for the special tool
37639212SgibbsAC_DEFUN([BASIC_REQUIRE_SPECIAL],
37739212Sgibbs[
37839212Sgibbs  BASIC_SETUP_TOOL($1, [$2])
37939212Sgibbs  BASIC_CHECK_NONEMPTY($1)
38039212Sgibbs])
38139212Sgibbs
38239212Sgibbs# Setup the most fundamental tools that relies on not much else to set up,
38339212Sgibbs# but is used by much of the early bootstrap code.
38439212SgibbsAC_DEFUN_ONCE([BASIC_SETUP_FUNDAMENTAL_TOOLS],
38539212Sgibbs[
38639212Sgibbs  # Start with tools that do not need have cross compilation support
38739212Sgibbs  # and can be expected to be found in the default PATH. These tools are
38839212Sgibbs  # used by configure.
38939212Sgibbs
39039212Sgibbs  # First are all the simple required tools.
39139212Sgibbs  BASIC_REQUIRE_PROGS(BASENAME, basename)
39239212Sgibbs  BASIC_REQUIRE_PROGS(BASH, bash)
39339212Sgibbs  BASIC_REQUIRE_PROGS(CAT, cat)
39439212Sgibbs  BASIC_REQUIRE_PROGS(CHMOD, chmod)
39539212Sgibbs  BASIC_REQUIRE_PROGS(CMP, cmp)
39639212Sgibbs  BASIC_REQUIRE_PROGS(COMM, comm)
39739212Sgibbs  BASIC_REQUIRE_PROGS(CP, cp)
39839212Sgibbs  BASIC_REQUIRE_PROGS(CUT, cut)
39939212Sgibbs  BASIC_REQUIRE_PROGS(DATE, date)
40039212Sgibbs  BASIC_REQUIRE_PROGS(DIFF, [gdiff diff])
40139212Sgibbs  BASIC_REQUIRE_PROGS(DIRNAME, dirname)
40239212Sgibbs  BASIC_REQUIRE_PROGS(ECHO, echo)
40339212Sgibbs  BASIC_REQUIRE_PROGS(EXPR, expr)
40439212Sgibbs  BASIC_REQUIRE_PROGS(FILE, file)
40539212Sgibbs  BASIC_REQUIRE_PROGS(FIND, find)
40639212Sgibbs  BASIC_REQUIRE_PROGS(HEAD, head)
40739212Sgibbs  BASIC_REQUIRE_PROGS(LN, ln)
40839212Sgibbs  BASIC_REQUIRE_PROGS(LS, ls)
40939212Sgibbs  BASIC_REQUIRE_PROGS(MKDIR, mkdir)
41039212Sgibbs  BASIC_REQUIRE_PROGS(MKTEMP, mktemp)
41139212Sgibbs  BASIC_REQUIRE_PROGS(MV, mv)
41239212Sgibbs  BASIC_REQUIRE_PROGS(NAWK, [nawk gawk awk])
41339212Sgibbs  BASIC_REQUIRE_PROGS(PRINTF, printf)
41439212Sgibbs  BASIC_REQUIRE_PROGS(RM, rm)
41539212Sgibbs  BASIC_REQUIRE_PROGS(RMDIR, rmdir)
41639212Sgibbs  BASIC_REQUIRE_PROGS(SH, sh)
41739212Sgibbs  BASIC_REQUIRE_PROGS(SORT, sort)
41839212Sgibbs  BASIC_REQUIRE_PROGS(TAIL, tail)
41939212Sgibbs  BASIC_REQUIRE_PROGS(TAR, tar)
42039212Sgibbs  BASIC_REQUIRE_PROGS(TEE, tee)
42139212Sgibbs  BASIC_REQUIRE_PROGS(TOUCH, touch)
42239212Sgibbs  BASIC_REQUIRE_PROGS(TR, tr)
42339212Sgibbs  BASIC_REQUIRE_PROGS(UNAME, uname)
42439212Sgibbs  BASIC_REQUIRE_PROGS(UNIQ, uniq)
42539212Sgibbs  BASIC_REQUIRE_PROGS(WC, wc)
42639212Sgibbs  BASIC_REQUIRE_PROGS(WHICH, which)
42739212Sgibbs  BASIC_REQUIRE_PROGS(XARGS, xargs)
42839212Sgibbs
42939212Sgibbs  # Then required tools that require some special treatment.
43039212Sgibbs  BASIC_REQUIRE_SPECIAL(AWK, [AC_PROG_AWK])
43139212Sgibbs  BASIC_REQUIRE_SPECIAL(GREP, [AC_PROG_GREP])
43239212Sgibbs  BASIC_REQUIRE_SPECIAL(EGREP, [AC_PROG_EGREP])
43339212Sgibbs  BASIC_REQUIRE_SPECIAL(FGREP, [AC_PROG_FGREP])
43439212Sgibbs  BASIC_REQUIRE_SPECIAL(SED, [AC_PROG_SED])
43539212Sgibbs
43639212Sgibbs  # Always force rm.
43739212Sgibbs  RM="$RM -f"
43839212Sgibbs
43939212Sgibbs  # pwd behaves differently on various platforms and some don't support the -L flag.
44039212Sgibbs  # Always use the bash builtin pwd to get uniform behavior.
44139212Sgibbs  THEPWDCMD=pwd
44239212Sgibbs
44339212Sgibbs  # These are not required on all platforms
44439212Sgibbs  BASIC_PATH_PROGS(CYGPATH, cygpath)
44539212Sgibbs  BASIC_PATH_PROGS(READLINK, [greadlink readlink])
44639212Sgibbs  BASIC_PATH_PROGS(DF, df)
44739212Sgibbs  BASIC_PATH_PROGS(CPIO, [cpio bsdcpio])
44839212Sgibbs  BASIC_PATH_PROGS(NICE, nice)
44939212Sgibbs])
45039212Sgibbs
45139212Sgibbs# Setup basic configuration paths, and platform-specific stuff related to PATHs.
45239212SgibbsAC_DEFUN_ONCE([BASIC_SETUP_PATHS],
45339212Sgibbs[
45439212Sgibbs  # Save the current directory this script was started from
45539212Sgibbs  CURDIR="$PWD"
45639212Sgibbs
45739212Sgibbs  # We might need to rewrite ORIGINAL_PATH, if it includes "#", to quote them
45839212Sgibbs  # for make. We couldn't do this when we retrieved ORIGINAL_PATH, since SED
45939212Sgibbs  # was not available at that time.
46039212Sgibbs  REWRITTEN_PATH=`$ECHO "$ORIGINAL_PATH" | $SED -e 's/#/\\\\#/g'`
46139212Sgibbs  if test "x$REWRITTEN_PATH" != "x$ORIGINAL_PATH"; then
46239212Sgibbs    ORIGINAL_PATH="$REWRITTEN_PATH"
46339212Sgibbs    AC_MSG_NOTICE([Rewriting ORIGINAL_PATH to $REWRITTEN_PATH])
46439212Sgibbs  fi
46539212Sgibbs
46639212Sgibbs  if test "x$OPENJDK_TARGET_OS" = "xwindows"; then
46739212Sgibbs    PATH_SEP=";"
46839212Sgibbs    BASIC_CHECK_PATHS_WINDOWS
46939212Sgibbs  else
47039212Sgibbs    PATH_SEP=":"
47139212Sgibbs  fi
47239212Sgibbs  AC_SUBST(PATH_SEP)
47339212Sgibbs
47439212Sgibbs  # We get the top-level directory from the supporting wrappers.
47539212Sgibbs  AC_MSG_CHECKING([for top-level directory])
47639212Sgibbs  AC_MSG_RESULT([$TOPDIR])
47739212Sgibbs  AC_SUBST(TOPDIR)
47839212Sgibbs
47939212Sgibbs  # Save the original version of TOPDIR for string comparisons
48039212Sgibbs  ORIGINAL_TOPDIR="$TOPDIR"
48139212Sgibbs  AC_SUBST(ORIGINAL_TOPDIR)
48239212Sgibbs
48339212Sgibbs  # We can only call BASIC_FIXUP_PATH after BASIC_CHECK_PATHS_WINDOWS.
48439212Sgibbs  BASIC_FIXUP_PATH(CURDIR)
48539212Sgibbs  BASIC_FIXUP_PATH(TOPDIR)
48639212Sgibbs  # SRC_ROOT is a traditional alias for TOPDIR.
48739212Sgibbs  SRC_ROOT=$TOPDIR
48839212Sgibbs
48939212Sgibbs  # Calculate a canonical version of TOPDIR for string comparisons
49039212Sgibbs  CANONICAL_TOPDIR=$TOPDIR
49139212Sgibbs  BASIC_REMOVE_SYMBOLIC_LINKS([CANONICAL_TOPDIR])
49239212Sgibbs  AC_SUBST(CANONICAL_TOPDIR)
49339212Sgibbs
49439212Sgibbs  # Locate the directory of this script.
49539212Sgibbs  AUTOCONF_DIR=$TOPDIR/common/autoconf
49639212Sgibbs])
49739212Sgibbs
49839212Sgibbs# Evaluates platform specific overrides for devkit variables.
49939212Sgibbs# $1: Name of variable
50039212SgibbsAC_DEFUN([BASIC_EVAL_DEVKIT_VARIABLE],
50139212Sgibbs[
50239212Sgibbs  if test "x[$]$1" = x; then
50339212Sgibbs    eval $1="\${$1_${OPENJDK_TARGET_CPU}}"
50439212Sgibbs  fi
50539212Sgibbs])
50639212Sgibbs
50739212SgibbsAC_DEFUN_ONCE([BASIC_SETUP_DEVKIT],
50839212Sgibbs[
50939212Sgibbs  AC_ARG_WITH([devkit], [AS_HELP_STRING([--with-devkit],
51039212Sgibbs      [use this devkit for compilers, tools and resources])],
51139212Sgibbs      [
51239212Sgibbs        BASIC_FIXUP_PATH([with_devkit])
51339212Sgibbs        DEVKIT_ROOT="$with_devkit"
51439212Sgibbs        # Check for a meta data info file in the root of the devkit
51539212Sgibbs        if test -f "$DEVKIT_ROOT/devkit.info"; then
51639212Sgibbs          . $DEVKIT_ROOT/devkit.info
51739212Sgibbs          # This potentially sets the following:
51839212Sgibbs          # A descriptive name of the devkit
51939212Sgibbs          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_NAME])
52039212Sgibbs          # Corresponds to --with-extra-path
52139212Sgibbs          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_EXTRA_PATH])
52239212Sgibbs          # Corresponds to --with-toolchain-path
52339212Sgibbs          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_TOOLCHAIN_PATH])
52439212Sgibbs          # Corresponds to --with-sysroot
52539212Sgibbs          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_SYSROOT])
52639212Sgibbs
52739212Sgibbs          # Identifies the Visual Studio version in the devkit
52839212Sgibbs          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_VS_VERSION])
52939212Sgibbs          # The Visual Studio include environment variable
53039212Sgibbs          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_VS_INCLUDE])
53139212Sgibbs          # The Visual Studio lib environment variable
53239212Sgibbs          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_VS_LIB])
53339212Sgibbs          # Corresponds to --with-msvcr-dll
53439212Sgibbs          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_MSVCR_DLL])
53539212Sgibbs          # Corresponds to --with-msvcp-dll
53639212Sgibbs          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_MSVCP_DLL])
53739212Sgibbs        fi
53839212Sgibbs
53939212Sgibbs        AC_MSG_CHECKING([for devkit])
54039212Sgibbs        if test "x$DEVKIT_NAME" != x; then
54139212Sgibbs          AC_MSG_RESULT([$DEVKIT_NAME in $DEVKIT_ROOT])
54239212Sgibbs        else
54339212Sgibbs          AC_MSG_RESULT([$DEVKIT_ROOT])
54439212Sgibbs        fi
54539212Sgibbs
54639212Sgibbs        BASIC_PREPEND_TO_PATH([EXTRA_PATH],$DEVKIT_EXTRA_PATH)
54739212Sgibbs
54839212Sgibbs        # Fallback default of just /bin if DEVKIT_PATH is not defined
54939212Sgibbs        if test "x$DEVKIT_TOOLCHAIN_PATH" = x; then
55039212Sgibbs          DEVKIT_TOOLCHAIN_PATH="$DEVKIT_ROOT/bin"
55139212Sgibbs        fi
55239212Sgibbs        BASIC_PREPEND_TO_PATH([TOOLCHAIN_PATH],$DEVKIT_TOOLCHAIN_PATH)
55339212Sgibbs
55439212Sgibbs        # If DEVKIT_SYSROOT is set, use that, otherwise try a couple of known
55539212Sgibbs        # places for backwards compatiblity.
55639212Sgibbs        if test "x$DEVKIT_SYSROOT" != x; then
55739212Sgibbs          SYSROOT="$DEVKIT_SYSROOT"
55839212Sgibbs        elif test -d "$DEVKIT_ROOT/$host_alias/libc"; then
55939212Sgibbs          SYSROOT="$DEVKIT_ROOT/$host_alias/libc"
56039212Sgibbs        elif test -d "$DEVKIT_ROOT/$host/sys-root"; then
56139212Sgibbs          SYSROOT="$DEVKIT_ROOT/$host/sys-root"
56239212Sgibbs        fi
56339212Sgibbs      ]
56439212Sgibbs  )
56539212Sgibbs
56639212Sgibbs  # You can force the sysroot if the sysroot encoded into the compiler tools
56739212Sgibbs  # is not correct.
56839212Sgibbs  AC_ARG_WITH(sys-root, [AS_HELP_STRING([--with-sys-root],
56939212Sgibbs      [alias for --with-sysroot for backwards compatability])],
57039212Sgibbs      [SYSROOT=$with_sys_root]
57139212Sgibbs  )
57239212Sgibbs
57339212Sgibbs  AC_ARG_WITH(sysroot, [AS_HELP_STRING([--with-sysroot],
57439212Sgibbs      [use this directory as sysroot])],
57539212Sgibbs      [SYSROOT=$with_sysroot]
57639212Sgibbs  )
57739212Sgibbs
57839212Sgibbs  AC_ARG_WITH([tools-dir], [AS_HELP_STRING([--with-tools-dir],
57939212Sgibbs      [alias for --with-toolchain-path for backwards compatibility])],
58039212Sgibbs      [BASIC_PREPEND_TO_PATH([TOOLCHAIN_PATH],$with_tools_dir)]
58139212Sgibbs  )
58239212Sgibbs
58339212Sgibbs  AC_ARG_WITH([toolchain-path], [AS_HELP_STRING([--with-toolchain-path],
58439212Sgibbs      [prepend these directories when searching for toolchain binaries (compilers etc)])],
58539212Sgibbs      [BASIC_PREPEND_TO_PATH([TOOLCHAIN_PATH],$with_toolchain_path)]
58639212Sgibbs  )
58739212Sgibbs
58839212Sgibbs  AC_ARG_WITH([extra-path], [AS_HELP_STRING([--with-extra-path],
58939212Sgibbs      [prepend these directories to the default path])],
59039212Sgibbs      [BASIC_PREPEND_TO_PATH([EXTRA_PATH],$with_extra_path)]
59139212Sgibbs  )
59239212Sgibbs
59339212Sgibbs  if test "x$OPENJDK_BUILD_OS" = "xmacosx"; then
59439212Sgibbs    # If a devkit has been supplied, find xcodebuild in the toolchain_path.
59539212Sgibbs    # If not, detect if Xcode is installed by running xcodebuild -version
59639212Sgibbs    # if no Xcode installed, xcodebuild exits with 1
59739212Sgibbs    # if Xcode is installed, even if xcode-select is misconfigured, then it exits with 0
59839212Sgibbs    if test "x$DEVKIT_ROOT" != x || /usr/bin/xcodebuild -version >/dev/null 2>&1; then
59939212Sgibbs      # We need to use xcodebuild in the toolchain dir provided by the user, this will
60039212Sgibbs      # fall back on the stub binary in /usr/bin/xcodebuild
60139212Sgibbs      AC_PATH_PROG([XCODEBUILD], [xcodebuild], [/usr/bin/xcodebuild], [$TOOLCHAIN_PATH])
60239212Sgibbs    else
60339212Sgibbs      # this should result in SYSROOT being empty, unless --with-sysroot is provided
60439212Sgibbs      # when only the command line tools are installed there are no SDKs, so headers
60539212Sgibbs      # are copied into the system frameworks
60639212Sgibbs      XCODEBUILD=
60739212Sgibbs      AC_SUBST(XCODEBUILD)
60839212Sgibbs    fi
60939212Sgibbs
61039212Sgibbs    AC_MSG_CHECKING([for sdk name])
61139212Sgibbs    AC_ARG_WITH([sdk-name], [AS_HELP_STRING([--with-sdk-name],
61239212Sgibbs        [use the platform SDK of the given name. @<:@macosx@:>@])],
61339212Sgibbs        [SDKNAME=$with_sdk_name]
61439212Sgibbs    )
61539212Sgibbs    AC_MSG_RESULT([$SDKNAME])
61639212Sgibbs
61739212Sgibbs    # if toolchain path is specified then don't rely on system headers, they may not compile
61839212Sgibbs    HAVE_SYSTEM_FRAMEWORK_HEADERS=0
61939212Sgibbs    test -z "$TOOLCHAIN_PATH" && \
62039212Sgibbs      HAVE_SYSTEM_FRAMEWORK_HEADERS=`test ! -f /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h; echo $?`
62139212Sgibbs
62239212Sgibbs    if test -z "$SYSROOT"; then
62339212Sgibbs      if test -n "$XCODEBUILD"; then
62439212Sgibbs        # if we don't have system headers, use default SDK name (last resort)
62539212Sgibbs        if test -z "$SDKNAME" -a $HAVE_SYSTEM_FRAMEWORK_HEADERS -eq 0; then
62639212Sgibbs          SDKNAME=${SDKNAME:-macosx}
62739212Sgibbs        fi
62839212Sgibbs
62939212Sgibbs        if test -n "$SDKNAME"; then
63039212Sgibbs          # Call xcodebuild to determine SYSROOT
63139212Sgibbs          SYSROOT=`"$XCODEBUILD" -sdk $SDKNAME -version | grep '^Path: ' | sed 's/Path: //'`
63239212Sgibbs        fi
63339212Sgibbs      else
63439212Sgibbs        if test $HAVE_SYSTEM_FRAMEWORK_HEADERS -eq 0; then
63539212Sgibbs          AC_MSG_ERROR([No xcodebuild tool and no system framework headers found, use --with-sysroot or --with-sdk-name to provide a path to a valid SDK])
63639212Sgibbs        fi
63739212Sgibbs      fi
63839212Sgibbs    else
63939212Sgibbs      # warn user if --with-sdk-name was also set
64039212Sgibbs      if test -n "$with_sdk_name"; then
64139212Sgibbs        AC_MSG_WARN([Both SYSROOT and --with-sdk-name are set, only SYSROOT will be used])
64239212Sgibbs      fi
64339212Sgibbs    fi
64439212Sgibbs
64539212Sgibbs    if test $HAVE_SYSTEM_FRAMEWORK_HEADERS -eq 0 -a -z "$SYSROOT"; then
64639212Sgibbs      # If no system framework headers, then SYSROOT must be set, or we won't build
64739212Sgibbs      AC_MSG_ERROR([Unable to determine SYSROOT and no headers found in /System/Library/Frameworks. Check Xcode configuration, --with-sysroot or --with-sdk-name arguments.])
64839212Sgibbs    fi
64939212Sgibbs
65039212Sgibbs    # Perform a basic sanity test
65139212Sgibbs    if test ! -f "$SYSROOT/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h"; then
65239212Sgibbs      if test -z "$SYSROOT"; then
65339212Sgibbs        AC_MSG_ERROR([Unable to find required framework headers, provide a path to an SDK via --with-sysroot or --with-sdk-name and be sure Xcode is installed properly])
65439212Sgibbs      else
65539317Sken        AC_MSG_ERROR([Invalid SDK or SYSROOT path, dependent framework headers not found])
65639317Sken      fi
65739317Sken    fi
65839317Sken
65939317Sken    # set SDKROOT too, Xcode tools will pick it up
66039317Sken    AC_SUBST(SDKROOT,$SYSROOT)
66139212Sgibbs  fi
66239212Sgibbs
66339212Sgibbs  # Prepend the extra path to the global path
66439212Sgibbs  BASIC_PREPEND_TO_PATH([PATH],$EXTRA_PATH)
66539212Sgibbs
66639212Sgibbs  if test "x$OPENJDK_BUILD_OS" = "xsolaris"; then
66739212Sgibbs    # Add extra search paths on solaris for utilities like ar and as etc...
66839212Sgibbs    PATH="$PATH:/usr/ccs/bin:/usr/sfw/bin:/opt/csw/bin"
66939212Sgibbs  fi
67039212Sgibbs
67139212Sgibbs  AC_MSG_CHECKING([for sysroot])
67239212Sgibbs  AC_MSG_RESULT([$SYSROOT])
67339212Sgibbs  AC_MSG_CHECKING([for toolchain path])
67439212Sgibbs  AC_MSG_RESULT([$TOOLCHAIN_PATH])
67539212Sgibbs  AC_MSG_CHECKING([for extra path])
67639212Sgibbs  AC_MSG_RESULT([$EXTRA_PATH])
67739212Sgibbs])
67839212Sgibbs
67939212SgibbsAC_DEFUN_ONCE([BASIC_SETUP_OUTPUT_DIR],
68039212Sgibbs[
68139212Sgibbs
68239212Sgibbs  AC_ARG_WITH(conf-name, [AS_HELP_STRING([--with-conf-name],
68339212Sgibbs      [use this as the name of the configuration @<:@generated from important configuration options@:>@])],
68439212Sgibbs      [ CONF_NAME=${with_conf_name} ])
68539212Sgibbs
68639212Sgibbs  # Test from where we are running configure, in or outside of src root.
68739212Sgibbs  AC_MSG_CHECKING([where to store configuration])
68839212Sgibbs  if test "x$CURDIR" = "x$SRC_ROOT" || test "x$CURDIR" = "x$SRC_ROOT/common" \
68939212Sgibbs      || test "x$CURDIR" = "x$SRC_ROOT/common/autoconf" \
69039212Sgibbs      || test "x$CURDIR" = "x$SRC_ROOT/make" ; then
69139212Sgibbs    # We are running configure from the src root.
69239212Sgibbs    # Create a default ./build/target-variant-debuglevel output root.
69339212Sgibbs    if test "x${CONF_NAME}" = x; then
69439212Sgibbs      AC_MSG_RESULT([in default location])
69539212Sgibbs      CONF_NAME="${OPENJDK_TARGET_OS}-${OPENJDK_TARGET_CPU}-${JDK_VARIANT}-${ANDED_JVM_VARIANTS}-${DEBUG_LEVEL}"
69639212Sgibbs    else
69739212Sgibbs      AC_MSG_RESULT([in build directory with custom name])
69839212Sgibbs    fi
69939212Sgibbs    OUTPUT_ROOT="$SRC_ROOT/build/${CONF_NAME}"
70039212Sgibbs    $MKDIR -p "$OUTPUT_ROOT"
70139212Sgibbs    if test ! -d "$OUTPUT_ROOT"; then
70239212Sgibbs      AC_MSG_ERROR([Could not create build directory $OUTPUT_ROOT])
70339212Sgibbs    fi
70439212Sgibbs  else
70539212Sgibbs    # We are running configure from outside of the src dir.
70639212Sgibbs    # Then use the current directory as output dir!
70739212Sgibbs    # If configuration is situated in normal build directory, just use the build
70839212Sgibbs    # directory name as configuration name, otherwise use the complete path.
70939212Sgibbs    if test "x${CONF_NAME}" = x; then
71039212Sgibbs      CONF_NAME=`$ECHO $CURDIR | $SED -e "s!^${SRC_ROOT}/build/!!"`
71139212Sgibbs    fi
71239212Sgibbs    OUTPUT_ROOT="$CURDIR"
71339212Sgibbs    AC_MSG_RESULT([in current directory])
71439212Sgibbs
71539212Sgibbs    # WARNING: This might be a bad thing to do. You need to be sure you want to
71639212Sgibbs    # have a configuration in this directory. Do some sanity checks!
71739212Sgibbs
71839212Sgibbs    if test ! -e "$OUTPUT_ROOT/spec.gmk"; then
71939212Sgibbs      # If we have a spec.gmk, we have run here before and we are OK. Otherwise, check for
72039212Sgibbs      # other files
72139212Sgibbs      files_present=`$LS $OUTPUT_ROOT`
72239212Sgibbs      # Configure has already touched config.log and confdefs.h in the current dir when this check
72339212Sgibbs      # is performed.
72439212Sgibbs      filtered_files=`$ECHO "$files_present" \
72539212Sgibbs          | $SED -e 's/config.log//g' \
72639212Sgibbs              -e 's/configure.log//g' \
72739212Sgibbs              -e 's/confdefs.h//g' \
72839212Sgibbs              -e 's/ //g' \
72939212Sgibbs          | $TR -d '\n'`
73039212Sgibbs      if test "x$filtered_files" != x; then
73139212Sgibbs        AC_MSG_NOTICE([Current directory is $CURDIR.])
73239212Sgibbs        AC_MSG_NOTICE([Since this is not the source root, configure will output the configuration here])
73339212Sgibbs        AC_MSG_NOTICE([(as opposed to creating a configuration in <src_root>/build/<conf-name>).])
73439212Sgibbs        AC_MSG_NOTICE([However, this directory is not empty. This is not allowed, since it could])
73539212Sgibbs        AC_MSG_NOTICE([seriously mess up just about everything.])
73639212Sgibbs        AC_MSG_NOTICE([Try 'cd $SRC_ROOT' and restart configure])
73739212Sgibbs        AC_MSG_NOTICE([(or create a new empty directory and cd to it).])
73839212Sgibbs        AC_MSG_ERROR([Will not continue creating configuration in $CURDIR])
73939212Sgibbs      fi
74039212Sgibbs    fi
74139212Sgibbs  fi
74239212Sgibbs  AC_MSG_CHECKING([what configuration name to use])
74339212Sgibbs  AC_MSG_RESULT([$CONF_NAME])
74439212Sgibbs
74539212Sgibbs  BASIC_FIXUP_PATH(OUTPUT_ROOT)
74639212Sgibbs
74739212Sgibbs  CONFIGURESUPPORT_OUTPUTDIR="$OUTPUT_ROOT/configure-support"
74839212Sgibbs  $MKDIR -p "$CONFIGURESUPPORT_OUTPUTDIR"
74939212Sgibbs
75039212Sgibbs  AC_SUBST(SPEC, $OUTPUT_ROOT/spec.gmk)
75139212Sgibbs  AC_SUBST(CONF_NAME, $CONF_NAME)
75239212Sgibbs  AC_SUBST(OUTPUT_ROOT, $OUTPUT_ROOT)
75339212Sgibbs  AC_SUBST(CONFIGURESUPPORT_OUTPUTDIR)
75439212Sgibbs
75539212Sgibbs  # The spec.gmk file contains all variables for the make system.
75639212Sgibbs  AC_CONFIG_FILES([$OUTPUT_ROOT/spec.gmk:$AUTOCONF_DIR/spec.gmk.in])
75739212Sgibbs  # The hotspot-spec.gmk file contains legacy variables for the hotspot make system.
75839212Sgibbs  AC_CONFIG_FILES([$OUTPUT_ROOT/hotspot-spec.gmk:$AUTOCONF_DIR/hotspot-spec.gmk.in])
75939212Sgibbs  # The bootcycle-spec.gmk file contains support for boot cycle builds.
76039212Sgibbs  AC_CONFIG_FILES([$OUTPUT_ROOT/bootcycle-spec.gmk:$AUTOCONF_DIR/bootcycle-spec.gmk.in])
76139212Sgibbs  # The compare.sh is used to compare the build output to other builds.
76239212Sgibbs  AC_CONFIG_FILES([$OUTPUT_ROOT/compare.sh:$AUTOCONF_DIR/compare.sh.in])
76339212Sgibbs  # The generated Makefile knows where the spec.gmk is and where the source is.
76439212Sgibbs  # You can run make from the OUTPUT_ROOT, or from the top-level Makefile
76539212Sgibbs  # which will look for generated configurations
76639212Sgibbs  AC_CONFIG_FILES([$OUTPUT_ROOT/Makefile:$AUTOCONF_DIR/Makefile.in])
76739212Sgibbs])
76839212Sgibbs
76939212Sgibbs#%%% Simple tools %%%
77039212Sgibbs
77139212Sgibbs# Check if we have found a usable version of make
77239212Sgibbs# $1: the path to a potential make binary (or empty)
77339212Sgibbs# $2: the description on how we found this
77439212SgibbsAC_DEFUN([BASIC_CHECK_MAKE_VERSION],
77539212Sgibbs[
77639212Sgibbs  MAKE_CANDIDATE="$1"
77739212Sgibbs  DESCRIPTION="$2"
77839212Sgibbs
77939212Sgibbs  # On Cygwin, we require a newer version of make than on other platforms
78039212Sgibbs  if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
78139212Sgibbs    MAKE_VERSION_EXPR="-e 4\."
78239212Sgibbs    MAKE_REQUIRED_VERSION="4.0"
78339212Sgibbs   else
78439212Sgibbs    MAKE_VERSION_EXPR="-e 3\.8[[12]] -e 4\."
78539212Sgibbs    MAKE_REQUIRED_VERSION="3.81"
78639212Sgibbs  fi
78739212Sgibbs
78839212Sgibbs  if test "x$MAKE_CANDIDATE" != x; then
78939212Sgibbs    AC_MSG_NOTICE([Testing potential make at $MAKE_CANDIDATE, found using $DESCRIPTION])
79039212Sgibbs    MAKE_VERSION_STRING=`$MAKE_CANDIDATE --version | $HEAD -n 1`
79139212Sgibbs    IS_GNU_MAKE=`$ECHO $MAKE_VERSION_STRING | $GREP 'GNU Make'`
79239212Sgibbs    if test "x$IS_GNU_MAKE" = x; then
79339212Sgibbs      AC_MSG_NOTICE([Found potential make at $MAKE_CANDIDATE, however, this is not GNU Make. Ignoring.])
79439212Sgibbs    else
79539212Sgibbs      IS_MODERN_MAKE=`$ECHO $MAKE_VERSION_STRING | $GREP $MAKE_VERSION_EXPR`
79639212Sgibbs      if test "x$IS_MODERN_MAKE" = x; then
79739212Sgibbs        AC_MSG_NOTICE([Found GNU make at $MAKE_CANDIDATE, however this is not version $MAKE_REQUIRED_VERSION or later. (it is: $MAKE_VERSION_STRING). Ignoring.])
79839212Sgibbs      else
79939212Sgibbs        if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
80039212Sgibbs          if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
80139212Sgibbs            MAKE_EXPECTED_ENV='cygwin'
80239212Sgibbs          elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
80339212Sgibbs            MAKE_EXPECTED_ENV='msys'
80439212Sgibbs          else
80539212Sgibbs            AC_MSG_ERROR([Unknown Windows environment])
80639212Sgibbs          fi
80739212Sgibbs          MAKE_BUILT_FOR=`$MAKE_CANDIDATE --version | $GREP -i 'built for'`
80839212Sgibbs          IS_MAKE_CORRECT_ENV=`$ECHO $MAKE_BUILT_FOR | $GREP $MAKE_EXPECTED_ENV`
80939212Sgibbs        else
81039212Sgibbs          # Not relevant for non-Windows
81139212Sgibbs          IS_MAKE_CORRECT_ENV=true
81239212Sgibbs        fi
81339212Sgibbs        if test "x$IS_MAKE_CORRECT_ENV" = x; then
81439212Sgibbs          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.])
81539212Sgibbs        else
81639212Sgibbs          FOUND_MAKE=$MAKE_CANDIDATE
81739212Sgibbs          BASIC_FIXUP_EXECUTABLE(FOUND_MAKE)
81839212Sgibbs        fi
81939212Sgibbs      fi
82039212Sgibbs    fi
82139212Sgibbs  fi
82239212Sgibbs])
82339212Sgibbs
82439212SgibbsAC_DEFUN([BASIC_CHECK_MAKE_OUTPUT_SYNC],
82539212Sgibbs[
82639212Sgibbs  # Check if make supports the output sync option and if so, setup using it.
82739212Sgibbs  AC_MSG_CHECKING([if make --output-sync is supported])
82839212Sgibbs  if $MAKE --version -O > /dev/null 2>&1; then
82939212Sgibbs    OUTPUT_SYNC_SUPPORTED=true
83039212Sgibbs    AC_MSG_RESULT([yes])
83139212Sgibbs    AC_MSG_CHECKING([for output-sync value])
83239212Sgibbs    AC_ARG_WITH([output-sync], [AS_HELP_STRING([--with-output-sync],
83339212Sgibbs      [set make output sync type if supported by make. @<:@recurse@:>@])],
83439212Sgibbs      [OUTPUT_SYNC=$with_output_sync])
83539212Sgibbs    if test "x$OUTPUT_SYNC" = "x"; then
83639212Sgibbs      OUTPUT_SYNC=none
83739212Sgibbs    fi
83839212Sgibbs    AC_MSG_RESULT([$OUTPUT_SYNC])
83939212Sgibbs    if ! $MAKE --version -O$OUTPUT_SYNC > /dev/null 2>&1; then
84039212Sgibbs      AC_MSG_ERROR([Make did not the support the value $OUTPUT_SYNC as output sync type.])
84139212Sgibbs    fi
84239212Sgibbs  else
84339212Sgibbs    OUTPUT_SYNC_SUPPORTED=false
84439212Sgibbs    AC_MSG_RESULT([no])
84539212Sgibbs  fi
84639212Sgibbs  AC_SUBST(OUTPUT_SYNC_SUPPORTED)
84739212Sgibbs  AC_SUBST(OUTPUT_SYNC)
84839212Sgibbs])
84939212Sgibbs
85039212Sgibbs# Goes looking for a usable version of GNU make.
85139212SgibbsAC_DEFUN([BASIC_CHECK_GNU_MAKE],
85239212Sgibbs[
85339212Sgibbs  BASIC_SETUP_TOOL([MAKE],
85439212Sgibbs  [
85539212Sgibbs    # Try our hardest to locate a correct version of GNU make
85639212Sgibbs    AC_PATH_PROGS(CHECK_GMAKE, gmake)
85739212Sgibbs    BASIC_CHECK_MAKE_VERSION("$CHECK_GMAKE", [gmake in PATH])
85839212Sgibbs
85939212Sgibbs    if test "x$FOUND_MAKE" = x; then
86039212Sgibbs      AC_PATH_PROGS(CHECK_MAKE, make)
86139212Sgibbs      BASIC_CHECK_MAKE_VERSION("$CHECK_MAKE", [make in PATH])
86239212Sgibbs    fi
86339212Sgibbs
86439212Sgibbs    if test "x$FOUND_MAKE" = x; then
86539212Sgibbs      if test "x$TOOLCHAIN_PATH" != x; then
86639212Sgibbs        # We have a toolchain path, check that as well before giving up.
86739212Sgibbs        OLD_PATH=$PATH
86839212Sgibbs        PATH=$TOOLCHAIN_PATH:$PATH
86939212Sgibbs        AC_PATH_PROGS(CHECK_TOOLSDIR_GMAKE, gmake)
87039212Sgibbs        BASIC_CHECK_MAKE_VERSION("$CHECK_TOOLSDIR_GMAKE", [gmake in tools-dir])
87139212Sgibbs        if test "x$FOUND_MAKE" = x; then
87239212Sgibbs          AC_PATH_PROGS(CHECK_TOOLSDIR_MAKE, make)
87339212Sgibbs          BASIC_CHECK_MAKE_VERSION("$CHECK_TOOLSDIR_MAKE", [make in tools-dir])
87439212Sgibbs        fi
87539212Sgibbs        PATH=$OLD_PATH
87639212Sgibbs      fi
87739212Sgibbs    fi
87839212Sgibbs
87939212Sgibbs    if test "x$FOUND_MAKE" = x; then
88039212Sgibbs      AC_MSG_ERROR([Cannot find GNU make $MAKE_REQUIRED_VERSION or newer! Please put it in the path, or add e.g. MAKE=/opt/gmake3.81/make as argument to configure.])
88139212Sgibbs    fi
88239212Sgibbs  ],[
88339212Sgibbs    # If MAKE was set by user, verify the version
88439212Sgibbs    BASIC_CHECK_MAKE_VERSION("$MAKE", [user supplied MAKE=$MAKE])
88539212Sgibbs    if test "x$FOUND_MAKE" = x; then
88639212Sgibbs      AC_MSG_ERROR([The specified make (by MAKE=$MAKE) is not GNU make $MAKE_REQUIRED_VERSION or newer.])
88739212Sgibbs    fi
88839212Sgibbs  ])
88939212Sgibbs
89039212Sgibbs  MAKE=$FOUND_MAKE
89139212Sgibbs  AC_SUBST(MAKE)
89239212Sgibbs  AC_MSG_NOTICE([Using GNU make at $FOUND_MAKE (version: $MAKE_VERSION_STRING)])
89339212Sgibbs
89439212Sgibbs  BASIC_CHECK_MAKE_OUTPUT_SYNC
89539212Sgibbs])
89639212Sgibbs
89739212SgibbsAC_DEFUN([BASIC_CHECK_FIND_DELETE],
89839212Sgibbs[
89939212Sgibbs  # Test if find supports -delete
90039212Sgibbs  AC_MSG_CHECKING([if find supports -delete])
90139212Sgibbs  FIND_DELETE="-delete"
90239212Sgibbs
90339212Sgibbs  DELETEDIR=`$MKTEMP -d tmp.XXXXXXXXXX` || (echo Could not create temporary directory!; exit $?)
90439212Sgibbs
90539212Sgibbs  echo Hejsan > $DELETEDIR/TestIfFindSupportsDelete
90639212Sgibbs
90739212Sgibbs  TEST_DELETE=`$FIND "$DELETEDIR" -name TestIfFindSupportsDelete $FIND_DELETE 2>&1`
90839212Sgibbs  if test -f $DELETEDIR/TestIfFindSupportsDelete; then
90939212Sgibbs    # No, it does not.
91039212Sgibbs    rm $DELETEDIR/TestIfFindSupportsDelete
91139212Sgibbs    if test "x$OPENJDK_TARGET_OS" = "xaix"; then
91239212Sgibbs      # AIX 'find' is buggy if called with '-exec {} \+' and an empty file list
91339212Sgibbs      FIND_DELETE="-print | xargs rm"
91439212Sgibbs    else
91539212Sgibbs      FIND_DELETE="-exec rm \{\} \+"
91639212Sgibbs    fi
91739212Sgibbs    AC_MSG_RESULT([no])
91839212Sgibbs  else
91939212Sgibbs    AC_MSG_RESULT([yes])
92039212Sgibbs  fi
92139212Sgibbs  rmdir $DELETEDIR
92239212Sgibbs  AC_SUBST(FIND_DELETE)
92339212Sgibbs])
92439212Sgibbs
92539212SgibbsAC_DEFUN_ONCE([BASIC_SETUP_COMPLEX_TOOLS],
92639212Sgibbs[
92739212Sgibbs  BASIC_CHECK_GNU_MAKE
92839212Sgibbs
92939212Sgibbs  BASIC_CHECK_FIND_DELETE
93039212Sgibbs
93139212Sgibbs  # These tools might not be installed by default,
93239212Sgibbs  # need hint on how to install them.
93339212Sgibbs  BASIC_REQUIRE_PROGS(UNZIP, unzip)
93439212Sgibbs  BASIC_REQUIRE_PROGS(ZIP, zip)
93539212Sgibbs
93639212Sgibbs  # Non-required basic tools
93739212Sgibbs
93839212Sgibbs  BASIC_PATH_PROGS(LDD, ldd)
93939212Sgibbs  if test "x$LDD" = "x"; then
94039212Sgibbs    # List shared lib dependencies is used for
94139212Sgibbs    # debug output and checking for forbidden dependencies.
94239212Sgibbs    # We can build without it.
94339212Sgibbs    LDD="true"
94439212Sgibbs  fi
94539212Sgibbs  BASIC_PATH_PROGS(OTOOL, otool)
94639212Sgibbs  if test "x$OTOOL" = "x"; then
94739212Sgibbs    OTOOL="true"
94839212Sgibbs  fi
94939212Sgibbs  BASIC_PATH_PROGS(READELF, [greadelf readelf])
95039212Sgibbs  BASIC_PATH_PROGS(HG, hg)
95139212Sgibbs  BASIC_PATH_PROGS(STAT, stat)
95239212Sgibbs  BASIC_PATH_PROGS(TIME, time)
95339212Sgibbs  BASIC_PATH_PROGS(PATCH, [gpatch patch])
95439212Sgibbs  # Check if it's GNU time
95539212Sgibbs  IS_GNU_TIME=`$TIME --version 2>&1 | $GREP 'GNU time'`
95639212Sgibbs  if test "x$IS_GNU_TIME" != x; then
95739212Sgibbs    IS_GNU_TIME=yes
95839212Sgibbs  else
95939212Sgibbs    IS_GNU_TIME=no
96039212Sgibbs  fi
96139212Sgibbs  AC_SUBST(IS_GNU_TIME)
96239212Sgibbs
96339212Sgibbs  if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
96439212Sgibbs    BASIC_REQUIRE_PROGS(DSYMUTIL, dsymutil)
96539212Sgibbs    BASIC_REQUIRE_PROGS(XATTR, xattr)
96639212Sgibbs    BASIC_PATH_PROGS(CODESIGN, codesign)
96739212Sgibbs    if test "x$CODESIGN" != "x"; then
96839212Sgibbs      # Verify that the openjdk_codesign certificate is present
96939212Sgibbs      AC_MSG_CHECKING([if openjdk_codesign certificate is present])
97039212Sgibbs      rm -f codesign-testfile
97139212Sgibbs      touch codesign-testfile
97239212Sgibbs      codesign -s openjdk_codesign codesign-testfile 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD || CODESIGN=
97339212Sgibbs      rm -f codesign-testfile
97439212Sgibbs      if test "x$CODESIGN" = x; then
97539212Sgibbs        AC_MSG_RESULT([no])
97639212Sgibbs      else
97739212Sgibbs        AC_MSG_RESULT([yes])
97839212Sgibbs      fi
97939212Sgibbs    fi
98039212Sgibbs    BASIC_REQUIRE_PROGS(SETFILE, SetFile)
98139212Sgibbs  fi
98239212Sgibbs])
98339212Sgibbs
98439212Sgibbs# Check if build directory is on local disk. If not possible to determine,
98539212Sgibbs# we prefer to claim it's local.
98639212Sgibbs# Argument 1: directory to test
98739212Sgibbs# Argument 2: what to do if it is on local disk
98839212Sgibbs# Argument 3: what to do otherwise (remote disk or failure)
98939212SgibbsAC_DEFUN([BASIC_CHECK_DIR_ON_LOCAL_DISK],
99039212Sgibbs[
99139212Sgibbs  # df -l lists only local disks; if the given directory is not found then
99239212Sgibbs  # a non-zero exit code is given
99339212Sgibbs  if test "x$DF" = x; then
99439212Sgibbs    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
99539212Sgibbs      # msys does not have df; use Windows "net use" instead.
99639212Sgibbs      IS_NETWORK_DISK=`net use | grep \`pwd -W | cut -d ":" -f 1 | tr a-z A-Z\`:`
99739212Sgibbs      if test "x$IS_NETWORK_DISK" = x; then
99839212Sgibbs        $2
99939212Sgibbs      else
100039212Sgibbs        $3
100139212Sgibbs      fi
100239212Sgibbs    else
100339212Sgibbs      # No df here, say it's local
100439212Sgibbs      $2
100539212Sgibbs    fi
100639212Sgibbs  else
100739212Sgibbs    if $DF -l $1 > /dev/null 2>&1; then
100839212Sgibbs      $2
100939212Sgibbs    else
101039212Sgibbs      $3
101139212Sgibbs    fi
101239212Sgibbs  fi
101339212Sgibbs])
101439212Sgibbs
101539212Sgibbs# Check that source files have basic read permissions set. This might
101639212Sgibbs# not be the case in cygwin in certain conditions.
101739212SgibbsAC_DEFUN_ONCE([BASIC_CHECK_SRC_PERMS],
101839212Sgibbs[
101939212Sgibbs  if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
102039212Sgibbs    file_to_test="$SRC_ROOT/LICENSE"
102139212Sgibbs    if test `$STAT -c '%a' "$file_to_test"` -lt 400; then
102239212Sgibbs      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.])
102339212Sgibbs    fi
102439212Sgibbs  fi
102539212Sgibbs])
102639212Sgibbs
102739212SgibbsAC_DEFUN_ONCE([BASIC_TEST_USABILITY_ISSUES],
102839212Sgibbs[
102939212Sgibbs  # Did user specify any unknown variables?
103039212Sgibbs  BASIC_CHECK_LEFTOVER_OVERRIDDEN
103139212Sgibbs
103239212Sgibbs  AC_MSG_CHECKING([if build directory is on local disk])
103339212Sgibbs  BASIC_CHECK_DIR_ON_LOCAL_DISK($OUTPUT_ROOT,
103439212Sgibbs      [OUTPUT_DIR_IS_LOCAL="yes"],
103539212Sgibbs      [OUTPUT_DIR_IS_LOCAL="no"])
103639212Sgibbs  AC_MSG_RESULT($OUTPUT_DIR_IS_LOCAL)
103739212Sgibbs
103839212Sgibbs  BASIC_CHECK_SRC_PERMS
103939212Sgibbs
104039212Sgibbs  # Check if the user has any old-style ALT_ variables set.
104139212Sgibbs  FOUND_ALT_VARIABLES=`env | grep ^ALT_`
104239212Sgibbs
104339212Sgibbs  # Before generating output files, test if they exist. If they do, this is a reconfigure.
104439212Sgibbs  # Since we can't properly handle the dependencies for this, warn the user about the situation
104539212Sgibbs  if test -e $OUTPUT_ROOT/spec.gmk; then
104639212Sgibbs    IS_RECONFIGURE=yes
104739212Sgibbs  else
104839212Sgibbs    IS_RECONFIGURE=no
104939212Sgibbs  fi
105039212Sgibbs])
105139212Sgibbs
105239212Sgibbs# Check for support for specific options in bash
105339212SgibbsAC_DEFUN_ONCE([BASIC_CHECK_BASH_OPTIONS],
105439212Sgibbs[
105539212Sgibbs  # Test if bash supports pipefail.
105639212Sgibbs  AC_MSG_CHECKING([if bash supports pipefail])
105739212Sgibbs  if ${BASH} -c 'set -o pipefail'; then
105839212Sgibbs    BASH_ARGS="$BASH_ARGS -o pipefail"
105939212Sgibbs    AC_MSG_RESULT([yes])
106039212Sgibbs  else
106139212Sgibbs    AC_MSG_RESULT([no])
106239212Sgibbs  fi
106339212Sgibbs
106439212Sgibbs  AC_MSG_CHECKING([if bash supports errexit (-e)])
106539212Sgibbs  if ${BASH} -e -c 'true'; then
106639212Sgibbs    BASH_ARGS="$BASH_ARGS -e"
106739212Sgibbs    AC_MSG_RESULT([yes])
106839212Sgibbs  else
106939212Sgibbs    AC_MSG_RESULT([no])
107039212Sgibbs  fi
107139212Sgibbs
107239212Sgibbs  AC_SUBST(BASH_ARGS)
107339212Sgibbs])
107439212Sgibbs
107539212Sgibbs# Code to run after AC_OUTPUT
107639212SgibbsAC_DEFUN_ONCE([BASIC_POST_CONFIG_OUTPUT],
107739212Sgibbs[
107839212Sgibbs  # Try to move config.log (generated by autoconf) to the configure-support directory.
107939212Sgibbs  if test -e ./config.log; then
108039212Sgibbs    $MV -f ./config.log "$CONFIGURESUPPORT_OUTPUTDIR/config.log" 2> /dev/null
108139212Sgibbs  fi
108239212Sgibbs
108339212Sgibbs  # Rotate our log file (configure.log)
108439212Sgibbs  if test -e "$OUTPUT_ROOT/configure.log.old"; then
108539212Sgibbs    $RM -f "$OUTPUT_ROOT/configure.log.old"
108639212Sgibbs  fi
108739212Sgibbs  if test -e "$OUTPUT_ROOT/configure.log"; then
108839212Sgibbs    $MV -f "$OUTPUT_ROOT/configure.log" "$OUTPUT_ROOT/configure.log.old" 2> /dev/null
108939212Sgibbs  fi
109039212Sgibbs
109139212Sgibbs  # Move configure.log from current directory to the build output root
109239388Sken  if test -e ./configure.log; then
109339212Sgibbs    echo found it
109439212Sgibbs    $MV -f ./configure.log "$OUTPUT_ROOT/configure.log" 2> /dev/null
109539388Sken  fi
109639212Sgibbs
109739212Sgibbs  # Make the compare script executable
109839212Sgibbs  $CHMOD +x $OUTPUT_ROOT/compare.sh
109939212Sgibbs])
110039212Sgibbs