basics.m4 revision 2458:1588d044d709
1214571Sdim#
2214571Sdim# Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
3214571Sdim# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4214571Sdim#
5214571Sdim# This code is free software; you can redistribute it and/or modify it
6214571Sdim# under the terms of the GNU General Public License version 2 only, as
7214571Sdim# published by the Free Software Foundation.  Oracle designates this
8214571Sdim# particular file as subject to the "Classpath" exception as provided
9214571Sdim# by Oracle in the LICENSE file that accompanied this code.
10214571Sdim#
11214571Sdim# This code is distributed in the hope that it will be useful, but WITHOUT
12214571Sdim# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13214571Sdim# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14214571Sdim# version 2 for more details (a copy is included in the LICENSE file that
15214571Sdim# accompanied this code).
16214571Sdim#
17214571Sdim# You should have received a copy of the GNU General Public License version
18214571Sdim# 2 along with this work; if not, write to the Free Software Foundation,
19214571Sdim# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20214571Sdim#
21214571Sdim# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22214571Sdim# or visit www.oracle.com if you need additional information or have any
23214571Sdim# questions.
24214571Sdim#
25214571Sdim
26214571Sdim# Create a function/macro that takes a series of named arguments. The call is
27214571Sdim# similar to AC_DEFUN, but the setup of the function looks like this:
28214571Sdim# BASIC_DEFUN_NAMED([MYFUNC], [FOO *BAR], [$@], [
29214571Sdim# ... do something
30214571Sdim#   AC_MSG_NOTICE([Value of BAR is ARG_BAR])
31214571Sdim# ])
32214571Sdim# A star (*) in front of a named argument means that it is required and it's
33214571Sdim# presence will be verified. To pass e.g. the first value as a normal indexed
34214571Sdim# argument, use [m4_shift($@)] as the third argument instead of [$@]. These
35214571Sdim# arguments are referenced in the function by their name prefixed by ARG_, e.g.
36214571Sdim# "ARG_FOO".
37214571Sdim#
38214571Sdim# The generated function can be called like this:
39214571Sdim# MYFUNC(FOO: [foo-val],
40214571Sdim#     BAR: [
41214571Sdim#         $ECHO hello world
42214571Sdim#     ])
43214571Sdim# Note that the argument value must start on the same line as the argument name.
44214571Sdim#
45214571Sdim# Argument 1: Name of the function to define
46214571Sdim# Argument 2: List of legal named arguments, with a * prefix for required arguments
47214571Sdim# Argument 3: Argument array to treat as named, typically $@
48214571Sdim# Argument 4: The main function body
49214571SdimAC_DEFUN([BASIC_DEFUN_NAMED],
50214571Sdim[
51214571Sdim  AC_DEFUN($1, [
52214571Sdim    m4_foreach(arg, m4_split($2), [
53214571Sdim      m4_if(m4_bregexp(arg, [^\*]), -1,
54214571Sdim        [
55214571Sdim          m4_set_add(legal_named_args, arg)
56214571Sdim        ],
57214571Sdim        [
58214571Sdim          m4_set_add(legal_named_args, m4_substr(arg, 1))
59214571Sdim          m4_set_add(required_named_args, m4_substr(arg, 1))
60214571Sdim        ]
61214571Sdim      )
62214571Sdim    ])
63214571Sdim
64214571Sdim    m4_foreach([arg], [$3], [
65214571Sdim      m4_define(arg_name, m4_substr(arg, 0, m4_bregexp(arg, [: ])))
66214571Sdim      m4_set_contains(legal_named_args, arg_name, [],[AC_MSG_ERROR([Internal error: arg_name is not a valid named argument to [$1]. Valid arguments are 'm4_set_contents(legal_named_args, [ ])'.])])
67214571Sdim      m4_set_remove(required_named_args, arg_name)
68214571Sdim      m4_set_remove(legal_named_args, arg_name)
69214571Sdim      m4_pushdef([ARG_][]arg_name, m4_substr(arg, m4_incr(m4_incr(m4_bregexp(arg, [: ])))))
70214571Sdim      m4_set_add(defined_args, arg_name)
71214571Sdim      m4_undefine([arg_name])
72214571Sdim    ])
73214571Sdim    m4_set_empty(required_named_args, [], [
74214571Sdim      AC_MSG_ERROR([Internal error: Required named arguments are missing for [$1]. Missing arguments: 'm4_set_contents(required_named_args, [ ])'])
75214571Sdim    ])
76214571Sdim    m4_foreach([arg], m4_indir([m4_dquote]m4_set_listc([legal_named_args])), [
77214571Sdim      m4_pushdef([ARG_][]arg, [])
78214571Sdim      m4_set_add(defined_args, arg)
79214571Sdim    ])
80214571Sdim    m4_set_delete(legal_named_args)
81214571Sdim    m4_set_delete(required_named_args)
82214571Sdim
83214571Sdim    # Execute function body
84214571Sdim    $4
85214571Sdim
86214571Sdim    m4_foreach([arg], m4_indir([m4_dquote]m4_set_listc([defined_args])), [
87214571Sdim      m4_popdef([ARG_][]arg)
88214571Sdim    ])
89214571Sdim
90214571Sdim    m4_set_delete(defined_args)
91214571Sdim  ])
92214571Sdim])
93214571Sdim
94214571Sdim# Test if $1 is a valid argument to $3 (often is $JAVA passed as $3)
95214571Sdim# If so, then append $1 to $2 \
96214571Sdim# Also set JVM_ARG_OK to true/false depending on outcome.
97214571SdimAC_DEFUN([ADD_JVM_ARG_IF_OK],
98214571Sdim[
99214571Sdim  $ECHO "Check if jvm arg is ok: $1" >&AS_MESSAGE_LOG_FD
100214571Sdim  $ECHO "Command: $3 $1 -version" >&AS_MESSAGE_LOG_FD
101214571Sdim  OUTPUT=`$3 $1 -version 2>&1`
102214571Sdim  FOUND_WARN=`$ECHO "$OUTPUT" | $GREP -i warn`
103214571Sdim  FOUND_VERSION=`$ECHO $OUTPUT | $GREP " version \""`
104214571Sdim  if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then
105214571Sdim    $2="[$]$2 $1"
106214571Sdim    JVM_ARG_OK=true
107214571Sdim  else
108214571Sdim    $ECHO "Arg failed:" >&AS_MESSAGE_LOG_FD
109214571Sdim    $ECHO "$OUTPUT" >&AS_MESSAGE_LOG_FD
110214571Sdim    JVM_ARG_OK=false
111214571Sdim  fi
112214571Sdim])
113214571Sdim
114214571Sdim# Appends a string to a path variable, only adding the : when needed.
115214571SdimAC_DEFUN([BASIC_APPEND_TO_PATH],
116214571Sdim[
117214571Sdim  if test "x$2" != x; then
118214571Sdim    if test "x[$]$1" = x; then
119214571Sdim      $1="$2"
120214571Sdim    else
121214571Sdim      $1="[$]$1:$2"
122214571Sdim    fi
123214571Sdim  fi
124214571Sdim])
125214571Sdim
126214571Sdim# Prepends a string to a path variable, only adding the : when needed.
127214571SdimAC_DEFUN([BASIC_PREPEND_TO_PATH],
128214571Sdim[
129214571Sdim  if test "x$2" != x; then
130214571Sdim    if test "x[$]$1" = x; then
131214571Sdim      $1="$2"
132214571Sdim    else
133214571Sdim      $1="$2:[$]$1"
134214571Sdim    fi
135214571Sdim  fi
136214571Sdim])
137214571Sdim
138214571Sdim# This will make sure the given variable points to a full and proper
139214571Sdim# path. This means:
140214571Sdim# 1) There will be no spaces in the path. On unix platforms,
141214571Sdim#    spaces in the path will result in an error. On Windows,
142214571Sdim#    the path will be rewritten using short-style to be space-free.
143214571Sdim# 2) The path will be absolute, and it will be in unix-style (on
144214571Sdim#     cygwin).
145214571Sdim# $1: The name of the variable to fix
146214571SdimAC_DEFUN([BASIC_FIXUP_PATH],
147214571Sdim[
148214571Sdim  # Only process if variable expands to non-empty
149214571Sdim
150214571Sdim  if test "x[$]$1" != x; then
151214571Sdim    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
152214571Sdim      BASIC_FIXUP_PATH_CYGWIN($1)
153214571Sdim    elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
154214571Sdim      BASIC_FIXUP_PATH_MSYS($1)
155214571Sdim    else
156214571Sdim      # We're on a unix platform. Hooray! :)
157214571Sdim      path="[$]$1"
158214571Sdim      has_space=`$ECHO "$path" | $GREP " "`
159214571Sdim      if test "x$has_space" != x; then
160214571Sdim        AC_MSG_NOTICE([The path of $1, which resolves as "$path", is invalid.])
161214571Sdim        AC_MSG_ERROR([Spaces are not allowed in this path.])
162214571Sdim      fi
163214571Sdim
164214571Sdim      # Use eval to expand a potential ~
165214571Sdim      eval path="$path"
166214571Sdim      if test ! -f "$path" && test ! -d "$path"; then
167214571Sdim        AC_MSG_ERROR([The path of $1, which resolves as "$path", is not found.])
168214571Sdim      fi
169214571Sdim
170214571Sdim      if test -d "$path"; then
171214571Sdim        $1="`cd "$path"; $THEPWDCMD -L`"
172214571Sdim      else
173214571Sdim        dir="`$DIRNAME "$path"`"
174214571Sdim        base="`$BASENAME "$path"`"
175214571Sdim        $1="`cd "$dir"; $THEPWDCMD -L`/$base"
176214571Sdim      fi
177214571Sdim    fi
178214571Sdim  fi
179214571Sdim])
180214571Sdim
181214571Sdim# This will make sure the given variable points to a executable
182214571Sdim# with a full and proper path. This means:
183214571Sdim# 1) There will be no spaces in the path. On unix platforms,
184214571Sdim#    spaces in the path will result in an error. On Windows,
185214571Sdim#    the path will be rewritten using short-style to be space-free.
186214571Sdim# 2) The path will be absolute, and it will be in unix-style (on
187214571Sdim#     cygwin).
188214571Sdim# Any arguments given to the executable is preserved.
189214571Sdim# If the input variable does not have a directory specification, then
190214571Sdim# it need to be in the PATH.
191214571Sdim# $1: The name of the variable to fix
192214571SdimAC_DEFUN([BASIC_FIXUP_EXECUTABLE],
193214571Sdim[
194214571Sdim  # Only process if variable expands to non-empty
195214571Sdim
196214571Sdim  if test "x[$]$1" != x; then
197214571Sdim    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
198214571Sdim      BASIC_FIXUP_EXECUTABLE_CYGWIN($1)
199214571Sdim    elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
200214571Sdim      BASIC_FIXUP_EXECUTABLE_MSYS($1)
201214571Sdim    else
202214571Sdim      # We're on a unix platform. Hooray! :)
203214571Sdim      # First separate the path from the arguments. This will split at the first
204214571Sdim      # space.
205214571Sdim      complete="[$]$1"
206214571Sdim      path="${complete%% *}"
207214571Sdim      tmp="$complete EOL"
208214571Sdim      arguments="${tmp#* }"
209214571Sdim
210214571Sdim      # Cannot rely on the command "which" here since it doesn't always work.
211214571Sdim      is_absolute_path=`$ECHO "$path" | $GREP ^/`
212214571Sdim      if test -z "$is_absolute_path"; then
213214571Sdim        # Path to executable is not absolute. Find it.
214214571Sdim        IFS_save="$IFS"
215214571Sdim        IFS=:
216214571Sdim        for p in $PATH; do
217214571Sdim          if test -f "$p/$path" && test -x "$p/$path"; then
218214571Sdim            new_path="$p/$path"
219214571Sdim            break
220214571Sdim          fi
221214571Sdim        done
222214571Sdim        IFS="$IFS_save"
223214571Sdim      else
224214571Sdim        # This is an absolute path, we can use it without further modifications.
225214571Sdim        new_path="$path"
226214571Sdim      fi
227214571Sdim
228214571Sdim      if test "x$new_path" = x; then
229214571Sdim        AC_MSG_NOTICE([The path of $1, which resolves as "$complete", is not found.])
230214571Sdim        has_space=`$ECHO "$complete" | $GREP " "`
231214571Sdim        if test "x$has_space" != x; then
232214571Sdim          AC_MSG_NOTICE([This might be caused by spaces in the path, which is not allowed.])
233214571Sdim        fi
234214571Sdim        AC_MSG_ERROR([Cannot locate the the path of $1])
235214571Sdim      fi
236214571Sdim    fi
237214571Sdim
238214571Sdim    # Now join together the path and the arguments once again
239214571Sdim    if test "x$arguments" != xEOL; then
240214571Sdim      new_complete="$new_path ${arguments% *}"
241214571Sdim    else
242214571Sdim      new_complete="$new_path"
243214571Sdim    fi
244214571Sdim
245214571Sdim    if test "x$complete" != "x$new_complete"; then
246214571Sdim      $1="$new_complete"
247214571Sdim      AC_MSG_NOTICE([Rewriting $1 to "$new_complete"])
248214571Sdim    fi
249214571Sdim  fi
250214571Sdim])
251214571Sdim
252214571SdimAC_DEFUN([BASIC_REMOVE_SYMBOLIC_LINKS],
253214571Sdim[
254214571Sdim  if test "x$OPENJDK_BUILD_OS" != xwindows; then
255214571Sdim    # Follow a chain of symbolic links. Use readlink
256214571Sdim    # where it exists, else fall back to horribly
257214571Sdim    # complicated shell code.
258214571Sdim    if test "x$READLINK_TESTED" != yes; then
259214571Sdim      # On MacOSX there is a readlink tool with a different
260214571Sdim      # purpose than the GNU readlink tool. Check the found readlink.
261214571Sdim      ISGNU=`$READLINK --version 2>&1 | $GREP GNU`
262214571Sdim      if test "x$ISGNU" = x; then
263214571Sdim        # A readlink that we do not know how to use.
264214571Sdim        # Are there other non-GNU readlinks out there?
265214571Sdim        READLINK_TESTED=yes
266214571Sdim        READLINK=
267214571Sdim      fi
268214571Sdim    fi
269214571Sdim
270214571Sdim    if test "x$READLINK" != x; then
271214571Sdim      $1=`$READLINK -f [$]$1`
272214571Sdim    else
273214571Sdim      # Save the current directory for restoring afterwards
274214571Sdim      STARTDIR=$PWD
275214571Sdim      COUNTER=0
276214571Sdim      sym_link_dir=`$DIRNAME [$]$1`
277214571Sdim      sym_link_file=`$BASENAME [$]$1`
278214571Sdim      cd $sym_link_dir
279214571Sdim      # Use -P flag to resolve symlinks in directories.
280214571Sdim      cd `$THEPWDCMD -P`
281214571Sdim      sym_link_dir=`$THEPWDCMD -P`
282214571Sdim      # Resolve file symlinks
283214571Sdim      while test $COUNTER -lt 20; do
284214571Sdim        ISLINK=`$LS -l $sym_link_dir/$sym_link_file | $GREP '\->' | $SED -e 's/.*-> \(.*\)/\1/'`
285214571Sdim        if test "x$ISLINK" == x; then
286214571Sdim          # This is not a symbolic link! We are done!
287214571Sdim          break
288214571Sdim        fi
289214571Sdim        # Again resolve directory symlinks since the target of the just found
290214571Sdim        # link could be in a different directory
291214571Sdim        cd `$DIRNAME $ISLINK`
292214571Sdim        sym_link_dir=`$THEPWDCMD -P`
293214571Sdim        sym_link_file=`$BASENAME $ISLINK`
294214571Sdim        let COUNTER=COUNTER+1
295214571Sdim      done
296214571Sdim      cd $STARTDIR
297214571Sdim      $1=$sym_link_dir/$sym_link_file
298214571Sdim    fi
299214571Sdim  fi
300214571Sdim])
301214571Sdim
302214571Sdim# Register a --with argument but mark it as deprecated
303214571Sdim# $1: The name of the with argument to deprecate, not including --with-
304214571SdimAC_DEFUN([BASIC_DEPRECATED_ARG_WITH],
305214571Sdim[
306214571Sdim  AC_ARG_WITH($1, [AS_HELP_STRING([--with-$1],
307214571Sdim      [Deprecated. Option is kept for backwards compatibility and is ignored])],
308214571Sdim      [AC_MSG_WARN([Option --with-$1 is deprecated and will be ignored.])])
309214571Sdim])
310214571Sdim
311214571Sdim# Register a --enable argument but mark it as deprecated
312214571Sdim# $1: The name of the with argument to deprecate, not including --enable-
313214571Sdim# $2: The name of the argument to deprecate, in shell variable style (i.e. with _ instead of -)
314214571Sdim# $3: Messages to user.
315214571SdimAC_DEFUN([BASIC_DEPRECATED_ARG_ENABLE],
316214571Sdim[
317214571Sdim  AC_ARG_ENABLE($1, [AS_HELP_STRING([--enable-$1],
318214571Sdim      [Deprecated. Option is kept for backwards compatibility and is ignored])])
319214571Sdim  if test "x$enable_$2" != x; then
320214571Sdim    AC_MSG_WARN([Option --enable-$1 is deprecated and will be ignored.])
321214571Sdim
322214571Sdim    if test "x$3" != x; then
323214571Sdim      AC_MSG_WARN([$3])
324214571Sdim    fi
325214571Sdim
326214571Sdim  fi
327214571Sdim])
328214571Sdim
329214571SdimAC_DEFUN_ONCE([BASIC_INIT],
330214571Sdim[
331214571Sdim  # Save the original command line. This is passed to us by the wrapper configure script.
332214571Sdim  AC_SUBST(CONFIGURE_COMMAND_LINE)
333214571Sdim  # Save the path variable before it gets changed
334214571Sdim  ORIGINAL_PATH="$PATH"
335214571Sdim  AC_SUBST(ORIGINAL_PATH)
336214571Sdim  DATE_WHEN_CONFIGURED=`LANG=C date`
337214571Sdim  AC_SUBST(DATE_WHEN_CONFIGURED)
338214571Sdim  AC_MSG_NOTICE([Configuration created at $DATE_WHEN_CONFIGURED.])
339214571Sdim  AC_MSG_NOTICE([configure script generated at timestamp $DATE_WHEN_GENERATED.])
340214571Sdim])
341214571Sdim
342214571Sdim# Test that variable $1 denoting a program is not empty. If empty, exit with an error.
343214571Sdim# $1: variable to check
344214571SdimAC_DEFUN([BASIC_CHECK_NONEMPTY],
345214571Sdim[
346214571Sdim  if test "x[$]$1" = x; then
347214571Sdim    AC_MSG_ERROR([Could not find required tool for $1])
348214571Sdim  fi
349214571Sdim])
350214571Sdim
351214571Sdim# Check that there are no unprocessed overridden variables left.
352214571Sdim# If so, they are an incorrect argument and we will exit with an error.
353214571SdimAC_DEFUN([BASIC_CHECK_LEFTOVER_OVERRIDDEN],
354214571Sdim[
355214571Sdim  if test "x$CONFIGURE_OVERRIDDEN_VARIABLES" != x; then
356214571Sdim    # Replace the separating ! with spaces before presenting for end user.
357214571Sdim    unknown_variables=${CONFIGURE_OVERRIDDEN_VARIABLES//!/ }
358214571Sdim    AC_MSG_WARN([The following variables might be unknown to configure: $unknown_variables])
359214571Sdim  fi
360214571Sdim])
361214571Sdim
362214571Sdim# Setup a tool for the given variable. If correctly specified by the user,
363214571Sdim# use that value, otherwise search for the tool using the supplied code snippet.
364214571Sdim# $1: variable to set
365214571Sdim# $2: code snippet to call to look for the tool
366214571Sdim# $3: code snippet to call if variable was used to find tool
367214571SdimAC_DEFUN([BASIC_SETUP_TOOL],
368214571Sdim[
369214571Sdim  # Publish this variable in the help.
370214571Sdim  AC_ARG_VAR($1, [Override default value for $1])
371214571Sdim
372214571Sdim  if [[ -z "${$1+x}" ]]; then
373214571Sdim    # The variable is not set by user, try to locate tool using the code snippet
374214571Sdim    $2
375214571Sdim  else
376214571Sdim    # The variable is set, but is it from the command line or the environment?
377214571Sdim
378214571Sdim    # Try to remove the string !$1! from our list.
379214571Sdim    try_remove_var=${CONFIGURE_OVERRIDDEN_VARIABLES//!$1!/}
380214571Sdim    if test "x$try_remove_var" = "x$CONFIGURE_OVERRIDDEN_VARIABLES"; then
381214571Sdim      # If it failed, the variable was not from the command line. Ignore it,
382214571Sdim      # but warn the user (except for BASH, which is always set by the calling BASH).
383214571Sdim      if test "x$1" != xBASH; then
384214571Sdim        AC_MSG_WARN([Ignoring value of $1 from the environment. Use command line variables instead.])
385214571Sdim      fi
386214571Sdim      # Try to locate tool using the code snippet
387214571Sdim      $2
388214571Sdim    else
389214571Sdim      # If it succeeded, then it was overridden by the user. We will use it
390214571Sdim      # for the tool.
391214571Sdim
392214571Sdim      # First remove it from the list of overridden variables, so we can test
393214571Sdim      # for unknown variables in the end.
394214571Sdim      CONFIGURE_OVERRIDDEN_VARIABLES="$try_remove_var"
395214571Sdim
396214571Sdim      # Check if we try to supply an empty value
397214571Sdim      if test "x[$]$1" = x; then
398214571Sdim        AC_MSG_NOTICE([Setting user supplied tool $1= (no value)])
399214571Sdim        AC_MSG_CHECKING([for $1])
400214571Sdim        AC_MSG_RESULT([disabled])
401214571Sdim      else
402214571Sdim        # Check if the provided tool contains a complete path.
403214571Sdim        tool_specified="[$]$1"
404214571Sdim        tool_basename="${tool_specified##*/}"
405214571Sdim        if test "x$tool_basename" = "x$tool_specified"; then
406214571Sdim          # A command without a complete path is provided, search $PATH.
407214571Sdim          AC_MSG_NOTICE([Will search for user supplied tool $1=$tool_basename])
408214571Sdim          AC_PATH_PROG($1, $tool_basename)
409214571Sdim          if test "x[$]$1" = x; then
410214571Sdim            AC_MSG_ERROR([User supplied tool $tool_basename could not be found])
411214571Sdim          fi
412214571Sdim        else
413214571Sdim          # Otherwise we believe it is a complete path. Use it as it is.
414214571Sdim          AC_MSG_NOTICE([Will use user supplied tool $1=$tool_specified])
415214571Sdim          AC_MSG_CHECKING([for $1])
416214571Sdim          if test ! -x "$tool_specified"; then
417214571Sdim            AC_MSG_RESULT([not found])
418214571Sdim            AC_MSG_ERROR([User supplied tool $1=$tool_specified does not exist or is not executable])
419214571Sdim          fi
420214571Sdim          AC_MSG_RESULT([$tool_specified])
421214571Sdim        fi
422214571Sdim      fi
423214571Sdim    fi
424214571Sdim    $3
425214571Sdim  fi
426214571Sdim])
427214571Sdim
428214571Sdim# Call BASIC_SETUP_TOOL with AC_PATH_PROGS to locate the tool
429214571Sdim# $1: variable to set
430214571Sdim# $2: executable name (or list of names) to look for
431214571Sdim# $3: [path]
432214571SdimAC_DEFUN([BASIC_PATH_PROGS],
433214571Sdim[
434214571Sdim  BASIC_SETUP_TOOL($1, [AC_PATH_PROGS($1, $2, , $3)])
435214571Sdim])
436214571Sdim
437214571Sdim# Call BASIC_SETUP_TOOL with AC_CHECK_TOOLS to locate the tool
438214571Sdim# $1: variable to set
439214571Sdim# $2: executable name (or list of names) to look for
440214571SdimAC_DEFUN([BASIC_CHECK_TOOLS],
441214571Sdim[
442214571Sdim  BASIC_SETUP_TOOL($1, [AC_CHECK_TOOLS($1, $2)])
443214571Sdim])
444214571Sdim
445214571Sdim# Like BASIC_PATH_PROGS but fails if no tool was found.
446214571Sdim# $1: variable to set
447214571Sdim# $2: executable name (or list of names) to look for
448214571Sdim# $3: [path]
449214571SdimAC_DEFUN([BASIC_REQUIRE_PROGS],
450214571Sdim[
451214571Sdim  BASIC_PATH_PROGS($1, $2, , $3)
452214571Sdim  BASIC_CHECK_NONEMPTY($1)
453214571Sdim])
454214571Sdim
455214571Sdim# Like BASIC_SETUP_TOOL but fails if no tool was found.
456214571Sdim# $1: variable to set
457214571Sdim# $2: autoconf macro to call to look for the special tool
458214571SdimAC_DEFUN([BASIC_REQUIRE_SPECIAL],
459214571Sdim[
460214571Sdim  BASIC_SETUP_TOOL($1, [$2])
461214571Sdim  BASIC_CHECK_NONEMPTY($1)
462214571Sdim])
463214571Sdim
464214571Sdim# Setup the most fundamental tools that relies on not much else to set up,
465214571Sdim# but is used by much of the early bootstrap code.
466214571SdimAC_DEFUN_ONCE([BASIC_SETUP_FUNDAMENTAL_TOOLS],
467214571Sdim[
468214571Sdim  # Start with tools that do not need have cross compilation support
469214571Sdim  # and can be expected to be found in the default PATH. These tools are
470214571Sdim  # used by configure.
471214571Sdim
472214571Sdim  # First are all the simple required tools.
473214571Sdim  BASIC_REQUIRE_PROGS(BASENAME, basename)
474214571Sdim  BASIC_REQUIRE_PROGS(BASH, bash)
475214571Sdim  BASIC_REQUIRE_PROGS(CAT, cat)
476214571Sdim  BASIC_REQUIRE_PROGS(CHMOD, chmod)
477214571Sdim  BASIC_REQUIRE_PROGS(CMP, cmp)
478214571Sdim  BASIC_REQUIRE_PROGS(COMM, comm)
479214571Sdim  BASIC_REQUIRE_PROGS(CP, cp)
480214571Sdim  BASIC_REQUIRE_PROGS(CUT, cut)
481214571Sdim  BASIC_REQUIRE_PROGS(DATE, date)
482214571Sdim  BASIC_REQUIRE_PROGS(DIFF, [gdiff diff])
483214571Sdim  BASIC_REQUIRE_PROGS(DIRNAME, dirname)
484214571Sdim  BASIC_REQUIRE_PROGS(ECHO, echo)
485214571Sdim  BASIC_REQUIRE_PROGS(EXPR, expr)
486214571Sdim  BASIC_REQUIRE_PROGS(FILE, file)
487214571Sdim  BASIC_REQUIRE_PROGS(FIND, find)
488214571Sdim  BASIC_REQUIRE_PROGS(HEAD, head)
489214571Sdim  BASIC_REQUIRE_PROGS(GUNZIP, gunzip)
490214571Sdim  BASIC_REQUIRE_PROGS(GZIP, pigz gzip)
491214571Sdim  BASIC_REQUIRE_PROGS(LN, ln)
492214571Sdim  BASIC_REQUIRE_PROGS(LS, ls)
493214571Sdim  BASIC_REQUIRE_PROGS(MKDIR, mkdir)
494214571Sdim  BASIC_REQUIRE_PROGS(MKTEMP, mktemp)
495214571Sdim  BASIC_REQUIRE_PROGS(MV, mv)
496214571Sdim  BASIC_REQUIRE_PROGS(NAWK, [nawk gawk awk])
497214571Sdim  BASIC_REQUIRE_PROGS(PRINTF, printf)
498214571Sdim  BASIC_REQUIRE_PROGS(RM, rm)
499214571Sdim  BASIC_REQUIRE_PROGS(RMDIR, rmdir)
500214571Sdim  BASIC_REQUIRE_PROGS(SH, sh)
501214571Sdim  BASIC_REQUIRE_PROGS(SORT, sort)
502214571Sdim  BASIC_REQUIRE_PROGS(TAIL, tail)
503214571Sdim  BASIC_REQUIRE_PROGS(TAR, gtar tar)
504214571Sdim  BASIC_REQUIRE_PROGS(TEE, tee)
505214571Sdim  BASIC_REQUIRE_PROGS(TOUCH, touch)
506214571Sdim  BASIC_REQUIRE_PROGS(TR, tr)
507214571Sdim  BASIC_REQUIRE_PROGS(UNAME, uname)
508214571Sdim  BASIC_REQUIRE_PROGS(UNIQ, uniq)
509214571Sdim  BASIC_REQUIRE_PROGS(WC, wc)
510214571Sdim  BASIC_REQUIRE_PROGS(WHICH, which)
511214571Sdim  BASIC_REQUIRE_PROGS(XARGS, xargs)
512214571Sdim
513214571Sdim  # Then required tools that require some special treatment.
514214571Sdim  BASIC_REQUIRE_SPECIAL(AWK, [AC_PROG_AWK])
515214571Sdim  BASIC_REQUIRE_SPECIAL(GREP, [AC_PROG_GREP])
516214571Sdim  BASIC_REQUIRE_SPECIAL(EGREP, [AC_PROG_EGREP])
517214571Sdim  BASIC_REQUIRE_SPECIAL(FGREP, [AC_PROG_FGREP])
518214571Sdim  BASIC_REQUIRE_SPECIAL(SED, [AC_PROG_SED])
519214571Sdim
520214571Sdim  # Always force rm.
521214571Sdim  RM="$RM -f"
522214571Sdim
523214571Sdim  # pwd behaves differently on various platforms and some don't support the -L flag.
524214571Sdim  # Always use the bash builtin pwd to get uniform behavior.
525214571Sdim  THEPWDCMD=pwd
526214571Sdim
527214571Sdim  # These are not required on all platforms
528214571Sdim  BASIC_PATH_PROGS(CYGPATH, cygpath)
529214571Sdim  BASIC_PATH_PROGS(READLINK, [greadlink readlink])
530214571Sdim  BASIC_PATH_PROGS(DF, df)
531214571Sdim  BASIC_PATH_PROGS(CPIO, [cpio bsdcpio])
532214571Sdim  BASIC_PATH_PROGS(NICE, nice)
533214571Sdim])
534214571Sdim
535214571Sdim# Setup basic configuration paths, and platform-specific stuff related to PATHs.
536214571SdimAC_DEFUN_ONCE([BASIC_SETUP_PATHS],
537214571Sdim[
538214571Sdim  # Save the current directory this script was started from
539214571Sdim  CURDIR="$PWD"
540214571Sdim
541214571Sdim  # We might need to rewrite ORIGINAL_PATH, if it includes "#", to quote them
542214571Sdim  # for make. We couldn't do this when we retrieved ORIGINAL_PATH, since SED
543214571Sdim  # was not available at that time.
544214571Sdim  REWRITTEN_PATH=`$ECHO "$ORIGINAL_PATH" | $SED -e 's/#/\\\\#/g'`
545214571Sdim  if test "x$REWRITTEN_PATH" != "x$ORIGINAL_PATH"; then
546214571Sdim    ORIGINAL_PATH="$REWRITTEN_PATH"
547214571Sdim    AC_MSG_NOTICE([Rewriting ORIGINAL_PATH to $REWRITTEN_PATH])
548214571Sdim  fi
549214571Sdim
550214571Sdim  if test "x$OPENJDK_TARGET_OS" = "xwindows"; then
551214571Sdim    PATH_SEP=";"
552214571Sdim    BASIC_CHECK_PATHS_WINDOWS
553214571Sdim  else
554214571Sdim    PATH_SEP=":"
555214571Sdim  fi
556214571Sdim  AC_SUBST(PATH_SEP)
557214571Sdim
558214571Sdim  # We get the top-level directory from the supporting wrappers.
559214571Sdim  AC_MSG_CHECKING([for top-level directory])
560214571Sdim  AC_MSG_RESULT([$TOPDIR])
561214571Sdim  AC_SUBST(TOPDIR)
562214571Sdim
563214571Sdim  # Save the original version of TOPDIR for string comparisons
564214571Sdim  ORIGINAL_TOPDIR="$TOPDIR"
565214571Sdim  AC_SUBST(ORIGINAL_TOPDIR)
566214571Sdim
567214571Sdim  # We can only call BASIC_FIXUP_PATH after BASIC_CHECK_PATHS_WINDOWS.
568214571Sdim  BASIC_FIXUP_PATH(CURDIR)
569214571Sdim  BASIC_FIXUP_PATH(TOPDIR)
570214571Sdim  # SRC_ROOT is a traditional alias for TOPDIR.
571214571Sdim  SRC_ROOT=$TOPDIR
572214571Sdim
573214571Sdim  # Calculate a canonical version of TOPDIR for string comparisons
574214571Sdim  CANONICAL_TOPDIR=$TOPDIR
575214571Sdim  BASIC_REMOVE_SYMBOLIC_LINKS([CANONICAL_TOPDIR])
576214571Sdim  AC_SUBST(CANONICAL_TOPDIR)
577214571Sdim
578214571Sdim  # Locate the directory of this script.
579214571Sdim  AUTOCONF_DIR=$TOPDIR/common/autoconf
580214571Sdim
581214571Sdim  # Setup username (for use in adhoc version strings etc)
582214571Sdim  # Outer [ ] to quote m4.
583214571Sdim  [ USERNAME=`$ECHO "$USER" | $TR -d -c '[a-z][A-Z][0-9]'` ]
584214571Sdim  AC_SUBST(USERNAME)
585214571Sdim])
586214571Sdim
587214571Sdim# Evaluates platform specific overrides for devkit variables.
588214571Sdim# $1: Name of variable
589214571SdimAC_DEFUN([BASIC_EVAL_DEVKIT_VARIABLE],
590214571Sdim[
591214571Sdim  if test "x[$]$1" = x; then
592214571Sdim    eval $1="\${$1_${OPENJDK_TARGET_CPU}}"
593214571Sdim  fi
594214571Sdim])
595214571Sdim
596214571SdimAC_DEFUN_ONCE([BASIC_SETUP_DEVKIT],
597214571Sdim[
598214571Sdim  AC_ARG_WITH([devkit], [AS_HELP_STRING([--with-devkit],
599214571Sdim      [use this devkit for compilers, tools and resources])],
600214571Sdim      [
601214571Sdim        BASIC_FIXUP_PATH([with_devkit])
602214571Sdim        DEVKIT_ROOT="$with_devkit"
603214571Sdim        # Check for a meta data info file in the root of the devkit
604214571Sdim        if test -f "$DEVKIT_ROOT/devkit.info"; then
605214571Sdim          . $DEVKIT_ROOT/devkit.info
606214571Sdim          # This potentially sets the following:
607214571Sdim          # A descriptive name of the devkit
608214571Sdim          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_NAME])
609214571Sdim          # Corresponds to --with-extra-path
610214571Sdim          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_EXTRA_PATH])
611214571Sdim          # Corresponds to --with-toolchain-path
612214571Sdim          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_TOOLCHAIN_PATH])
613214571Sdim          # Corresponds to --with-sysroot
614214571Sdim          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_SYSROOT])
615214571Sdim
616214571Sdim          # Identifies the Visual Studio version in the devkit
617214571Sdim          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_VS_VERSION])
618214571Sdim          # The Visual Studio include environment variable
619214571Sdim          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_VS_INCLUDE])
620214571Sdim          # The Visual Studio lib environment variable
621214571Sdim          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_VS_LIB])
622214571Sdim          # Corresponds to --with-msvcr-dll
623214571Sdim          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_MSVCR_DLL])
624214571Sdim          # Corresponds to --with-msvcp-dll
625214571Sdim          BASIC_EVAL_DEVKIT_VARIABLE([DEVKIT_MSVCP_DLL])
626214571Sdim        fi
627214571Sdim
628214571Sdim        AC_MSG_CHECKING([for devkit])
629214571Sdim        if test "x$DEVKIT_NAME" != x; then
630214571Sdim          AC_MSG_RESULT([$DEVKIT_NAME in $DEVKIT_ROOT])
631214571Sdim        else
632214571Sdim          AC_MSG_RESULT([$DEVKIT_ROOT])
633214571Sdim        fi
634214571Sdim
635214571Sdim        BASIC_PREPEND_TO_PATH([EXTRA_PATH],$DEVKIT_EXTRA_PATH)
636214571Sdim
637214571Sdim        # Fallback default of just /bin if DEVKIT_PATH is not defined
638214571Sdim        if test "x$DEVKIT_TOOLCHAIN_PATH" = x; then
639214571Sdim          DEVKIT_TOOLCHAIN_PATH="$DEVKIT_ROOT/bin"
640214571Sdim        fi
641214571Sdim        BASIC_PREPEND_TO_PATH([TOOLCHAIN_PATH],$DEVKIT_TOOLCHAIN_PATH)
642214571Sdim
643214571Sdim        # If DEVKIT_SYSROOT is set, use that, otherwise try a couple of known
644214571Sdim        # places for backwards compatiblity.
645214571Sdim        if test "x$DEVKIT_SYSROOT" != x; then
646214571Sdim          SYSROOT="$DEVKIT_SYSROOT"
647214571Sdim        elif test -d "$DEVKIT_ROOT/$host_alias/libc"; then
648214571Sdim          SYSROOT="$DEVKIT_ROOT/$host_alias/libc"
649214571Sdim        elif test -d "$DEVKIT_ROOT/$host/sys-root"; then
650214571Sdim          SYSROOT="$DEVKIT_ROOT/$host/sys-root"
651214571Sdim        fi
652214571Sdim      ]
653214571Sdim  )
654214571Sdim
655214571Sdim  # You can force the sysroot if the sysroot encoded into the compiler tools
656214571Sdim  # is not correct.
657214571Sdim  AC_ARG_WITH(sys-root, [AS_HELP_STRING([--with-sys-root],
658214571Sdim      [alias for --with-sysroot for backwards compatability])],
659214571Sdim      [SYSROOT=$with_sys_root]
660214571Sdim  )
661214571Sdim
662214571Sdim  AC_ARG_WITH(sysroot, [AS_HELP_STRING([--with-sysroot],
663214571Sdim      [use this directory as sysroot])],
664214571Sdim      [SYSROOT=$with_sysroot]
665214571Sdim  )
666214571Sdim
667214571Sdim  AC_ARG_WITH([tools-dir], [AS_HELP_STRING([--with-tools-dir],
668214571Sdim      [alias for --with-toolchain-path for backwards compatibility])],
669214571Sdim      [BASIC_PREPEND_TO_PATH([TOOLCHAIN_PATH],$with_tools_dir)]
670214571Sdim  )
671214571Sdim
672214571Sdim  AC_ARG_WITH([toolchain-path], [AS_HELP_STRING([--with-toolchain-path],
673214571Sdim      [prepend these directories when searching for toolchain binaries (compilers etc)])],
674214571Sdim      [BASIC_PREPEND_TO_PATH([TOOLCHAIN_PATH],$with_toolchain_path)]
675214571Sdim  )
676214571Sdim
677214571Sdim  AC_ARG_WITH([extra-path], [AS_HELP_STRING([--with-extra-path],
678214571Sdim      [prepend these directories to the default path])],
679214571Sdim      [BASIC_PREPEND_TO_PATH([EXTRA_PATH],$with_extra_path)]
680214571Sdim  )
681214571Sdim
682214571Sdim  if test "x$OPENJDK_BUILD_OS" = "xmacosx"; then
683214571Sdim    # If a devkit has been supplied, find xcodebuild in the toolchain_path.
684214571Sdim    # If not, detect if Xcode is installed by running xcodebuild -version
685214571Sdim    # if no Xcode installed, xcodebuild exits with 1
686214571Sdim    # if Xcode is installed, even if xcode-select is misconfigured, then it exits with 0
687214571Sdim    if test "x$DEVKIT_ROOT" != x || /usr/bin/xcodebuild -version >/dev/null 2>&1; then
688214571Sdim      # We need to use xcodebuild in the toolchain dir provided by the user, this will
689214571Sdim      # fall back on the stub binary in /usr/bin/xcodebuild
690214571Sdim      AC_PATH_PROG([XCODEBUILD], [xcodebuild], [/usr/bin/xcodebuild], [$TOOLCHAIN_PATH])
691214571Sdim    else
692214571Sdim      # this should result in SYSROOT being empty, unless --with-sysroot is provided
693214571Sdim      # when only the command line tools are installed there are no SDKs, so headers
694214571Sdim      # are copied into the system frameworks
695214571Sdim      XCODEBUILD=
696214571Sdim      AC_SUBST(XCODEBUILD)
697214571Sdim    fi
698214571Sdim
699214571Sdim    AC_MSG_CHECKING([for sdk name])
700214571Sdim    AC_ARG_WITH([sdk-name], [AS_HELP_STRING([--with-sdk-name],
701214571Sdim        [use the platform SDK of the given name. @<:@macosx@:>@])],
702214571Sdim        [SDKNAME=$with_sdk_name]
703214571Sdim    )
704214571Sdim    AC_MSG_RESULT([$SDKNAME])
705214571Sdim
706214571Sdim    # if toolchain path is specified then don't rely on system headers, they may not compile
707214571Sdim    HAVE_SYSTEM_FRAMEWORK_HEADERS=0
708214571Sdim    test -z "$TOOLCHAIN_PATH" && \
709214571Sdim      HAVE_SYSTEM_FRAMEWORK_HEADERS=`test ! -f /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h; echo $?`
710214571Sdim
711214571Sdim    if test -z "$SYSROOT"; then
712214571Sdim      if test -n "$XCODEBUILD"; then
713214571Sdim        # if we don't have system headers, use default SDK name (last resort)
714214571Sdim        if test -z "$SDKNAME" -a $HAVE_SYSTEM_FRAMEWORK_HEADERS -eq 0; then
715214571Sdim          SDKNAME=${SDKNAME:-macosx}
716214571Sdim        fi
717214571Sdim
718214571Sdim        if test -n "$SDKNAME"; then
719214571Sdim          # Call xcodebuild to determine SYSROOT
720214571Sdim          SYSROOT=`"$XCODEBUILD" -sdk $SDKNAME -version | $GREP '^Path: ' | $SED 's/Path: //'`
721214571Sdim        fi
722214571Sdim      else
723214571Sdim        if test $HAVE_SYSTEM_FRAMEWORK_HEADERS -eq 0; then
724214571Sdim          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])
725214571Sdim        fi
726214571Sdim      fi
727214571Sdim    else
728214571Sdim      # warn user if --with-sdk-name was also set
729214571Sdim      if test -n "$with_sdk_name"; then
730214571Sdim        AC_MSG_WARN([Both SYSROOT and --with-sdk-name are set, only SYSROOT will be used])
731214571Sdim      fi
732214571Sdim    fi
733214571Sdim
734214571Sdim    if test $HAVE_SYSTEM_FRAMEWORK_HEADERS -eq 0 -a -z "$SYSROOT"; then
735214571Sdim      # If no system framework headers, then SYSROOT must be set, or we won't build
736214571Sdim      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.])
737214571Sdim    fi
738214571Sdim
739214571Sdim    # Perform a basic sanity test
740214571Sdim    if test ! -f "$SYSROOT/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h"; then
741214571Sdim      if test -z "$SYSROOT"; then
742214571Sdim        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])
743214571Sdim      else
744214571Sdim        AC_MSG_ERROR([Invalid SDK or SYSROOT path, dependent framework headers not found])
745214571Sdim      fi
746214571Sdim    fi
747214571Sdim
748214571Sdim    # set SDKROOT too, Xcode tools will pick it up
749214571Sdim    SDKROOT="$SYSROOT"
750214571Sdim    AC_SUBST(SDKROOT)
751214571Sdim  fi
752214571Sdim
753214571Sdim  # Prepend the extra path to the global path
754214571Sdim  BASIC_PREPEND_TO_PATH([PATH],$EXTRA_PATH)
755214571Sdim
756214571Sdim  AC_MSG_CHECKING([for sysroot])
757214571Sdim  AC_MSG_RESULT([$SYSROOT])
758214571Sdim  AC_MSG_CHECKING([for toolchain path])
759214571Sdim  AC_MSG_RESULT([$TOOLCHAIN_PATH])
760214571Sdim  AC_MSG_CHECKING([for extra path])
761214571Sdim  AC_MSG_RESULT([$EXTRA_PATH])
762214571Sdim])
763214571Sdim
764214571SdimAC_DEFUN_ONCE([BASIC_SETUP_OUTPUT_DIR],
765214571Sdim[
766214571Sdim
767214571Sdim  AC_ARG_WITH(conf-name, [AS_HELP_STRING([--with-conf-name],
768214571Sdim      [use this as the name of the configuration @<:@generated from important configuration options@:>@])],
769214571Sdim      [ CONF_NAME=${with_conf_name} ])
770214571Sdim
771214571Sdim  # Test from where we are running configure, in or outside of src root.
772214571Sdim  AC_MSG_CHECKING([where to store configuration])
773214571Sdim  if test "x$CURDIR" = "x$SRC_ROOT" || test "x$CURDIR" = "x$SRC_ROOT/common" \
774214571Sdim      || test "x$CURDIR" = "x$SRC_ROOT/common/autoconf" \
775214571Sdim      || test "x$CURDIR" = "x$SRC_ROOT/make" ; then
776214571Sdim    # We are running configure from the src root.
777214571Sdim    # Create a default ./build/target-variant-debuglevel output root.
778214571Sdim    if test "x${CONF_NAME}" = x; then
779214571Sdim      AC_MSG_RESULT([in default location])
780214571Sdim      CONF_NAME="${OPENJDK_TARGET_OS}-${OPENJDK_TARGET_CPU}-${JDK_VARIANT}-${JVM_VARIANTS_WITH_AND}-${DEBUG_LEVEL}"
781214571Sdim    else
782214571Sdim      AC_MSG_RESULT([in build directory with custom name])
783214571Sdim    fi
784214571Sdim    OUTPUT_ROOT="$SRC_ROOT/build/${CONF_NAME}"
785214571Sdim    $MKDIR -p "$OUTPUT_ROOT"
786214571Sdim    if test ! -d "$OUTPUT_ROOT"; then
787214571Sdim      AC_MSG_ERROR([Could not create build directory $OUTPUT_ROOT])
788214571Sdim    fi
789214571Sdim  else
790214571Sdim    # We are running configure from outside of the src dir.
791214571Sdim    # Then use the current directory as output dir!
792214571Sdim    # If configuration is situated in normal build directory, just use the build
793214571Sdim    # directory name as configuration name, otherwise use the complete path.
794214571Sdim    if test "x${CONF_NAME}" = x; then
795214571Sdim      CONF_NAME=`$ECHO $CURDIR | $SED -e "s!^${SRC_ROOT}/build/!!"`
796214571Sdim    fi
797214571Sdim    OUTPUT_ROOT="$CURDIR"
798214571Sdim    AC_MSG_RESULT([in current directory])
799214571Sdim
800214571Sdim    # WARNING: This might be a bad thing to do. You need to be sure you want to
801214571Sdim    # have a configuration in this directory. Do some sanity checks!
802214571Sdim
803214571Sdim    if test ! -e "$OUTPUT_ROOT/spec.gmk"; then
804214571Sdim      # If we have a spec.gmk, we have run here before and we are OK. Otherwise, check for
805214571Sdim      # other files
806214571Sdim      files_present=`$LS $OUTPUT_ROOT`
807214571Sdim      # Configure has already touched config.log and confdefs.h in the current dir when this check
808214571Sdim      # is performed.
809214571Sdim      filtered_files=`$ECHO "$files_present" \
810214571Sdim          | $SED -e 's/config.log//g' \
811214571Sdim              -e 's/configure.log//g' \
812214571Sdim              -e 's/confdefs.h//g' \
813214571Sdim              -e 's/ //g' \
814214571Sdim          | $TR -d '\n'`
815214571Sdim      if test "x$filtered_files" != x; then
816214571Sdim        AC_MSG_NOTICE([Current directory is $CURDIR.])
817214571Sdim        AC_MSG_NOTICE([Since this is not the source root, configure will output the configuration here])
818214571Sdim        AC_MSG_NOTICE([(as opposed to creating a configuration in <src_root>/build/<conf-name>).])
819214571Sdim        AC_MSG_NOTICE([However, this directory is not empty. This is not allowed, since it could])
820214571Sdim        AC_MSG_NOTICE([seriously mess up just about everything.])
821214571Sdim        AC_MSG_NOTICE([Try 'cd $SRC_ROOT' and restart configure])
822214571Sdim        AC_MSG_NOTICE([(or create a new empty directory and cd to it).])
823214571Sdim        AC_MSG_ERROR([Will not continue creating configuration in $CURDIR])
824214571Sdim      fi
825214571Sdim    fi
826214571Sdim  fi
827214571Sdim  AC_MSG_CHECKING([what configuration name to use])
828214571Sdim  AC_MSG_RESULT([$CONF_NAME])
829214571Sdim
830214571Sdim  BASIC_FIXUP_PATH(OUTPUT_ROOT)
831214571Sdim
832214571Sdim  CONFIGURESUPPORT_OUTPUTDIR="$OUTPUT_ROOT/configure-support"
833214571Sdim  $MKDIR -p "$CONFIGURESUPPORT_OUTPUTDIR"
834214571Sdim
835214571Sdim  SPEC="$OUTPUT_ROOT/spec.gmk"
836214571Sdim  AC_SUBST(SPEC)
837214571Sdim  AC_SUBST(CONF_NAME)
838214571Sdim  AC_SUBST(OUTPUT_ROOT)
839214571Sdim  AC_SUBST(CONFIGURESUPPORT_OUTPUTDIR)
840214571Sdim
841214571Sdim  # The spec.gmk file contains all variables for the make system.
842214571Sdim  AC_CONFIG_FILES([$OUTPUT_ROOT/spec.gmk:$AUTOCONF_DIR/spec.gmk.in])
843214571Sdim  # The bootcycle-spec.gmk file contains support for boot cycle builds.
844214571Sdim  AC_CONFIG_FILES([$OUTPUT_ROOT/bootcycle-spec.gmk:$AUTOCONF_DIR/bootcycle-spec.gmk.in])
845214571Sdim  # The buildjdk-spec.gmk file contains support for building a buildjdk when cross compiling.
846214571Sdim  AC_CONFIG_FILES([$OUTPUT_ROOT/buildjdk-spec.gmk:$AUTOCONF_DIR/buildjdk-spec.gmk.in])
847214571Sdim  # The compare.sh is used to compare the build output to other builds.
848214571Sdim  AC_CONFIG_FILES([$OUTPUT_ROOT/compare.sh:$AUTOCONF_DIR/compare.sh.in])
849214571Sdim  # The generated Makefile knows where the spec.gmk is and where the source is.
850214571Sdim  # You can run make from the OUTPUT_ROOT, or from the top-level Makefile
851214571Sdim  # which will look for generated configurations
852214571Sdim  AC_CONFIG_FILES([$OUTPUT_ROOT/Makefile:$AUTOCONF_DIR/Makefile.in])
853214571Sdim])
854214571Sdim
855214571Sdim#%%% Simple tools %%%
856214571Sdim
857214571Sdim# Check if we have found a usable version of make
858214571Sdim# $1: the path to a potential make binary (or empty)
859214571Sdim# $2: the description on how we found this
860214571SdimAC_DEFUN([BASIC_CHECK_MAKE_VERSION],
861214571Sdim[
862214571Sdim  MAKE_CANDIDATE="$1"
863214571Sdim  DESCRIPTION="$2"
864214571Sdim
865214571Sdim  # On Cygwin, we require a newer version of make than on other platforms
866214571Sdim  if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
867214571Sdim    MAKE_VERSION_EXPR="-e 4\."
868214571Sdim    MAKE_REQUIRED_VERSION="4.0"
869214571Sdim   else
870214571Sdim    MAKE_VERSION_EXPR="-e 3\.8[[12]] -e 4\."
871214571Sdim    MAKE_REQUIRED_VERSION="3.81"
872214571Sdim  fi
873214571Sdim
874214571Sdim  if test "x$MAKE_CANDIDATE" != x; then
875214571Sdim    AC_MSG_NOTICE([Testing potential make at $MAKE_CANDIDATE, found using $DESCRIPTION])
876214571Sdim    MAKE_VERSION_STRING=`$MAKE_CANDIDATE --version | $HEAD -n 1`
877214571Sdim    IS_GNU_MAKE=`$ECHO $MAKE_VERSION_STRING | $GREP 'GNU Make'`
878214571Sdim    if test "x$IS_GNU_MAKE" = x; then
879214571Sdim      AC_MSG_NOTICE([Found potential make at $MAKE_CANDIDATE, however, this is not GNU Make. Ignoring.])
880214571Sdim    else
881214571Sdim      IS_MODERN_MAKE=`$ECHO $MAKE_VERSION_STRING | $GREP $MAKE_VERSION_EXPR`
882214571Sdim      if test "x$IS_MODERN_MAKE" = x; then
883214571Sdim        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.])
884214571Sdim      else
885214571Sdim        if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
886214571Sdim          if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
887214571Sdim            MAKE_EXPECTED_ENV='cygwin'
888214571Sdim          elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
889214571Sdim            MAKE_EXPECTED_ENV='msys'
890214571Sdim          else
891214571Sdim            AC_MSG_ERROR([Unknown Windows environment])
892214571Sdim          fi
893214571Sdim          MAKE_BUILT_FOR=`$MAKE_CANDIDATE --version | $GREP -i 'built for'`
894214571Sdim          IS_MAKE_CORRECT_ENV=`$ECHO $MAKE_BUILT_FOR | $GREP $MAKE_EXPECTED_ENV`
895214571Sdim        else
896214571Sdim          # Not relevant for non-Windows
897214571Sdim          IS_MAKE_CORRECT_ENV=true
898214571Sdim        fi
899214571Sdim        if test "x$IS_MAKE_CORRECT_ENV" = x; then
900214571Sdim          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.])
901214571Sdim        else
902214571Sdim          FOUND_MAKE=$MAKE_CANDIDATE
903214571Sdim          BASIC_FIXUP_EXECUTABLE(FOUND_MAKE)
904214571Sdim        fi
905214571Sdim      fi
906214571Sdim    fi
907214571Sdim  fi
908214571Sdim])
909214571Sdim
910214571SdimAC_DEFUN([BASIC_CHECK_MAKE_OUTPUT_SYNC],
911214571Sdim[
912214571Sdim  # Check if make supports the output sync option and if so, setup using it.
913214571Sdim  AC_MSG_CHECKING([if make --output-sync is supported])
914214571Sdim  if $MAKE --version -O > /dev/null 2>&1; then
915214571Sdim    OUTPUT_SYNC_SUPPORTED=true
916214571Sdim    AC_MSG_RESULT([yes])
917214571Sdim    AC_MSG_CHECKING([for output-sync value])
918214571Sdim    AC_ARG_WITH([output-sync], [AS_HELP_STRING([--with-output-sync],
919214571Sdim      [set make output sync type if supported by make. @<:@recurse@:>@])],
920214571Sdim      [OUTPUT_SYNC=$with_output_sync])
921214571Sdim    if test "x$OUTPUT_SYNC" = "x"; then
922214571Sdim      OUTPUT_SYNC=none
923214571Sdim    fi
924214571Sdim    AC_MSG_RESULT([$OUTPUT_SYNC])
925214571Sdim    if ! $MAKE --version -O$OUTPUT_SYNC > /dev/null 2>&1; then
926214571Sdim      AC_MSG_ERROR([Make did not the support the value $OUTPUT_SYNC as output sync type.])
927214571Sdim    fi
928214571Sdim  else
929214571Sdim    OUTPUT_SYNC_SUPPORTED=false
930214571Sdim    AC_MSG_RESULT([no])
931214571Sdim  fi
932214571Sdim  AC_SUBST(OUTPUT_SYNC_SUPPORTED)
933214571Sdim  AC_SUBST(OUTPUT_SYNC)
934214571Sdim])
935214571Sdim
936214571Sdim# Goes looking for a usable version of GNU make.
937214571SdimAC_DEFUN([BASIC_CHECK_GNU_MAKE],
938214571Sdim[
939214571Sdim  BASIC_SETUP_TOOL([MAKE],
940214571Sdim  [
941214571Sdim    # Try our hardest to locate a correct version of GNU make
942214571Sdim    AC_PATH_PROGS(CHECK_GMAKE, gmake)
943214571Sdim    BASIC_CHECK_MAKE_VERSION("$CHECK_GMAKE", [gmake in PATH])
944214571Sdim
945214571Sdim    if test "x$FOUND_MAKE" = x; then
946214571Sdim      AC_PATH_PROGS(CHECK_MAKE, make)
947214571Sdim      BASIC_CHECK_MAKE_VERSION("$CHECK_MAKE", [make in PATH])
948214571Sdim    fi
949214571Sdim
950214571Sdim    if test "x$FOUND_MAKE" = x; then
951214571Sdim      if test "x$TOOLCHAIN_PATH" != x; then
952214571Sdim        # We have a toolchain path, check that as well before giving up.
953214571Sdim        OLD_PATH=$PATH
954214571Sdim        PATH=$TOOLCHAIN_PATH:$PATH
955214571Sdim        AC_PATH_PROGS(CHECK_TOOLSDIR_GMAKE, gmake)
956214571Sdim        BASIC_CHECK_MAKE_VERSION("$CHECK_TOOLSDIR_GMAKE", [gmake in tools-dir])
957214571Sdim        if test "x$FOUND_MAKE" = x; then
958214571Sdim          AC_PATH_PROGS(CHECK_TOOLSDIR_MAKE, make)
959214571Sdim          BASIC_CHECK_MAKE_VERSION("$CHECK_TOOLSDIR_MAKE", [make in tools-dir])
960214571Sdim        fi
961214571Sdim        PATH=$OLD_PATH
962214571Sdim      fi
963214571Sdim    fi
964214571Sdim
965214571Sdim    if test "x$FOUND_MAKE" = x; then
966214571Sdim      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.])
967214571Sdim    fi
968214571Sdim  ],[
969214571Sdim    # If MAKE was set by user, verify the version
970214571Sdim    BASIC_CHECK_MAKE_VERSION("$MAKE", [user supplied MAKE=$MAKE])
971214571Sdim    if test "x$FOUND_MAKE" = x; then
972214571Sdim      AC_MSG_ERROR([The specified make (by MAKE=$MAKE) is not GNU make $MAKE_REQUIRED_VERSION or newer.])
973214571Sdim    fi
974214571Sdim  ])
975214571Sdim
976214571Sdim  MAKE=$FOUND_MAKE
977214571Sdim  AC_SUBST(MAKE)
978214571Sdim  AC_MSG_NOTICE([Using GNU make at $FOUND_MAKE (version: $MAKE_VERSION_STRING)])
979214571Sdim
980214571Sdim  BASIC_CHECK_MAKE_OUTPUT_SYNC
981214571Sdim])
982214571Sdim
983214571SdimAC_DEFUN([BASIC_CHECK_FIND_DELETE],
984214571Sdim[
985214571Sdim  # Test if find supports -delete
986214571Sdim  AC_MSG_CHECKING([if find supports -delete])
987214571Sdim  FIND_DELETE="-delete"
988214571Sdim
989214571Sdim  DELETEDIR=`$MKTEMP -d tmp.XXXXXXXXXX` || (echo Could not create temporary directory!; exit $?)
990214571Sdim
991214571Sdim  echo Hejsan > $DELETEDIR/TestIfFindSupportsDelete
992214571Sdim
993214571Sdim  TEST_DELETE=`$FIND "$DELETEDIR" -name TestIfFindSupportsDelete $FIND_DELETE 2>&1`
994214571Sdim  if test -f $DELETEDIR/TestIfFindSupportsDelete; then
995214571Sdim    # No, it does not.
996214571Sdim    $RM $DELETEDIR/TestIfFindSupportsDelete
997214571Sdim    if test "x$OPENJDK_TARGET_OS" = "xaix"; then
998214571Sdim      # AIX 'find' is buggy if called with '-exec {} \+' and an empty file list
999214571Sdim      FIND_DELETE="-print | $XARGS $RM"
1000214571Sdim    else
1001214571Sdim      FIND_DELETE="-exec $RM \{\} \+"
1002214571Sdim    fi
1003214571Sdim    AC_MSG_RESULT([no])
1004214571Sdim  else
1005214571Sdim    AC_MSG_RESULT([yes])
1006214571Sdim  fi
1007214571Sdim  $RMDIR $DELETEDIR
1008214571Sdim  AC_SUBST(FIND_DELETE)
1009214571Sdim])
1010214571Sdim
1011214571SdimAC_DEFUN([BASIC_CHECK_TAR],
1012214571Sdim[
1013214571Sdim  # Test which kind of tar was found
1014214571Sdim  if test "x$($TAR --version | $GREP "GNU tar")" != "x"; then
1015214571Sdim    TAR_TYPE="gnu"
1016214571Sdim  elif test "x$($TAR --version | $GREP "bsdtar")" != "x"; then
1017214571Sdim    TAR_TYPE="bsd"
1018214571Sdim  elif test "x$($TAR -v | $GREP "bsdtar")" != "x"; then
1019214571Sdim    TAR_TYPE="bsd"
1020214571Sdim  elif test "x$OPENJDK_BUILD_OS" = "xsolaris"; then
1021214571Sdim    TAR_TYPE="solaris"
1022214571Sdim  fi
1023214571Sdim  AC_MSG_CHECKING([what type of tar was found])
1024214571Sdim  AC_MSG_RESULT([$TAR_TYPE])
1025214571Sdim
1026214571Sdim  TAR_CREATE_FILE_PARAM=""
1027214571Sdim
1028214571Sdim  if test "x$TAR_TYPE" = "xgnu"; then
1029214571Sdim    TAR_INCLUDE_PARAM="T"
1030214571Sdim    TAR_SUPPORTS_TRANSFORM="true"
1031214571Sdim    if test "x$OPENJDK_TARGET_OS" = "xsolaris"; then
1032214571Sdim      # When using gnu tar for Solaris targets, need to use compatibility mode
1033214571Sdim      TAR_CREATE_EXTRA_PARAM="--format=ustar"
1034214571Sdim    fi
1035214571Sdim  else
1036214571Sdim    TAR_INCLUDE_PARAM="I"
1037214571Sdim    TAR_SUPPORTS_TRANSFORM="false"
1038214571Sdim  fi
1039214571Sdim  AC_SUBST(TAR_TYPE)
1040214571Sdim  AC_SUBST(TAR_CREATE_EXTRA_PARAM)
1041214571Sdim  AC_SUBST(TAR_INCLUDE_PARAM)
1042214571Sdim  AC_SUBST(TAR_SUPPORTS_TRANSFORM)
1043214571Sdim])
1044214571Sdim
1045214571SdimAC_DEFUN([BASIC_CHECK_GREP],
1046214571Sdim[
1047214571Sdim  # Test that grep supports -Fx with a list of pattern which includes null pattern.
1048214571Sdim  # This is a problem for the grep resident on AIX.
1049214571Sdim  AC_MSG_CHECKING([that grep ($GREP) -Fx handles empty lines in the pattern list correctly])
1050214571Sdim  # Multiple subsequent spaces..
1051214571Sdim  STACK_SPACES='aaa   bbb   ccc'
1052214571Sdim  # ..converted to subsequent newlines, causes STACK_LIST to be a list with some empty
1053214571Sdim  # patterns in it.
1054214571Sdim  STACK_LIST=${STACK_SPACES// /$'\n'}
1055214571Sdim  NEEDLE_SPACES='ccc bbb aaa'
1056214571Sdim  NEEDLE_LIST=${NEEDLE_SPACES// /$'\n'}
1057214571Sdim  RESULT="$($GREP -Fvx "$STACK_LIST" <<< "$NEEDLE_LIST")"
1058214571Sdim  if test "x$RESULT" == "x"; then
1059214571Sdim    AC_MSG_RESULT([yes])
1060214571Sdim  else
1061214571Sdim    if test "x$OPENJDK_TARGET_OS" = "xaix"; then
1062214571Sdim      ADDINFO="Please make sure you use GNU grep, usually found at /opt/freeware/bin."
1063214571Sdim    fi
1064214571Sdim    AC_MSG_ERROR([grep does not handle -Fx correctly. ${ADDINFO}])
1065214571Sdim  fi
1066214571Sdim])
1067214571Sdim
1068214571SdimAC_DEFUN_ONCE([BASIC_SETUP_COMPLEX_TOOLS],
1069214571Sdim[
1070214571Sdim  BASIC_CHECK_GNU_MAKE
1071214571Sdim
1072214571Sdim  BASIC_CHECK_FIND_DELETE
1073214571Sdim  BASIC_CHECK_TAR
1074214571Sdim  BASIC_CHECK_GREP
1075214571Sdim
1076214571Sdim  # These tools might not be installed by default,
1077214571Sdim  # need hint on how to install them.
1078214571Sdim  BASIC_REQUIRE_PROGS(UNZIP, unzip)
1079214571Sdim  # Since zip uses "ZIP" as a environment variable for passing options, we need
1080214571Sdim  # to name our variable differently, hence ZIPEXE.
1081214571Sdim  BASIC_REQUIRE_PROGS(ZIPEXE, zip)
1082214571Sdim
1083214571Sdim  # Non-required basic tools
1084214571Sdim
1085214571Sdim  BASIC_PATH_PROGS(LDD, ldd)
1086214571Sdim  if test "x$LDD" = "x"; then
1087214571Sdim    # List shared lib dependencies is used for
1088214571Sdim    # debug output and checking for forbidden dependencies.
1089214571Sdim    # We can build without it.
1090214571Sdim    LDD="true"
1091214571Sdim  fi
1092214571Sdim  BASIC_PATH_PROGS(OTOOL, otool)
1093214571Sdim  if test "x$OTOOL" = "x"; then
1094214571Sdim    OTOOL="true"
1095214571Sdim  fi
1096214571Sdim  BASIC_PATH_PROGS(READELF, [greadelf readelf])
1097214571Sdim  BASIC_PATH_PROGS(HG, hg)
1098214571Sdim  BASIC_PATH_PROGS(STAT, stat)
1099214571Sdim  BASIC_PATH_PROGS(TIME, time)
1100214571Sdim  # Dtrace is usually found in /usr/sbin on Solaris, but that directory may not
1101214571Sdim  # be in the user path.
1102214571Sdim  BASIC_PATH_PROGS(DTRACE, dtrace, $PATH:/usr/sbin)
1103214571Sdim  BASIC_PATH_PROGS(PATCH, [gpatch patch])
1104214571Sdim  # Check if it's GNU time
1105214571Sdim  IS_GNU_TIME=`$TIME --version 2>&1 | $GREP 'GNU time'`
1106214571Sdim  if test "x$IS_GNU_TIME" != x; then
1107214571Sdim    IS_GNU_TIME=yes
1108214571Sdim  else
1109214571Sdim    IS_GNU_TIME=no
1110214571Sdim  fi
1111214571Sdim  AC_SUBST(IS_GNU_TIME)
1112214571Sdim
1113214571Sdim  if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
1114214571Sdim    BASIC_REQUIRE_PROGS(DSYMUTIL, dsymutil)
1115214571Sdim    BASIC_REQUIRE_PROGS(XATTR, xattr)
1116214571Sdim    BASIC_PATH_PROGS(CODESIGN, codesign)
1117214571Sdim    if test "x$CODESIGN" != "x"; then
1118214571Sdim      # Verify that the openjdk_codesign certificate is present
1119214571Sdim      AC_MSG_CHECKING([if openjdk_codesign certificate is present])
1120214571Sdim      $RM codesign-testfile
1121214571Sdim      $TOUCH codesign-testfile
1122214571Sdim      $CODESIGN -s openjdk_codesign codesign-testfile 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD || CODESIGN=
1123214571Sdim      $RM codesign-testfile
1124214571Sdim      if test "x$CODESIGN" = x; then
1125214571Sdim        AC_MSG_RESULT([no])
1126214571Sdim      else
1127214571Sdim        AC_MSG_RESULT([yes])
1128214571Sdim      fi
1129214571Sdim    fi
1130214571Sdim    BASIC_REQUIRE_PROGS(SETFILE, SetFile)
1131214571Sdim  fi
1132214571Sdim])
1133214571Sdim
1134214571Sdim# Check if build directory is on local disk. If not possible to determine,
1135214571Sdim# we prefer to claim it's local.
1136214571Sdim# Argument 1: directory to test
1137214571Sdim# Argument 2: what to do if it is on local disk
1138214571Sdim# Argument 3: what to do otherwise (remote disk or failure)
1139214571SdimAC_DEFUN([BASIC_CHECK_DIR_ON_LOCAL_DISK],
1140214571Sdim[
1141214571Sdim  # df -l lists only local disks; if the given directory is not found then
1142214571Sdim  # a non-zero exit code is given
1143214571Sdim  if test "x$DF" = x; then
1144214571Sdim    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
1145214571Sdim      # msys does not have df; use Windows "net use" instead.
1146214571Sdim      IS_NETWORK_DISK=`net use | grep \`pwd -W | cut -d ":" -f 1 | tr a-z A-Z\`:`
1147214571Sdim      if test "x$IS_NETWORK_DISK" = x; then
1148214571Sdim        $2
1149214571Sdim      else
1150214571Sdim        $3
1151214571Sdim      fi
1152214571Sdim    else
1153214571Sdim      # No df here, say it's local
1154214571Sdim      $2
1155214571Sdim    fi
1156214571Sdim  else
1157214571Sdim    if $DF -l $1 > /dev/null 2>&1; then
1158214571Sdim      $2
1159214571Sdim    else
1160214571Sdim      $3
1161214571Sdim    fi
1162214571Sdim  fi
1163214571Sdim])
1164214571Sdim
1165214571Sdim# Check that source files have basic read permissions set. This might
1166214571Sdim# not be the case in cygwin in certain conditions.
1167214571SdimAC_DEFUN_ONCE([BASIC_CHECK_SRC_PERMS],
1168214571Sdim[
1169214571Sdim  if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
1170214571Sdim    file_to_test="$SRC_ROOT/LICENSE"
1171214571Sdim    if test `$STAT -c '%a' "$file_to_test"` -lt 400; then
1172214571Sdim      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.])
1173214571Sdim    fi
1174214571Sdim  fi
1175214571Sdim])
1176214571Sdim
1177214571SdimAC_DEFUN_ONCE([BASIC_TEST_USABILITY_ISSUES],
1178214571Sdim[
1179214571Sdim  # Did user specify any unknown variables?
1180214571Sdim  BASIC_CHECK_LEFTOVER_OVERRIDDEN
1181214571Sdim
1182214571Sdim  AC_MSG_CHECKING([if build directory is on local disk])
1183214571Sdim  BASIC_CHECK_DIR_ON_LOCAL_DISK($OUTPUT_ROOT,
1184214571Sdim      [OUTPUT_DIR_IS_LOCAL="yes"],
1185214571Sdim      [OUTPUT_DIR_IS_LOCAL="no"])
1186214571Sdim  AC_MSG_RESULT($OUTPUT_DIR_IS_LOCAL)
1187214571Sdim
1188214571Sdim  BASIC_CHECK_SRC_PERMS
1189214571Sdim
1190214571Sdim  # Check if the user has any old-style ALT_ variables set.
1191214571Sdim  FOUND_ALT_VARIABLES=`env | grep ^ALT_`
1192214571Sdim
1193214571Sdim  # Before generating output files, test if they exist. If they do, this is a reconfigure.
1194214571Sdim  # Since we can't properly handle the dependencies for this, warn the user about the situation
1195214571Sdim  if test -e $OUTPUT_ROOT/spec.gmk; then
1196214571Sdim    IS_RECONFIGURE=yes
1197214571Sdim  else
1198214571Sdim    IS_RECONFIGURE=no
1199214571Sdim  fi
1200214571Sdim])
1201214571Sdim
1202214571Sdim# Check for support for specific options in bash
1203214571SdimAC_DEFUN_ONCE([BASIC_CHECK_BASH_OPTIONS],
1204214571Sdim[
1205214571Sdim  # Test if bash supports pipefail.
1206214571Sdim  AC_MSG_CHECKING([if bash supports pipefail])
1207214571Sdim  if ${BASH} -c 'set -o pipefail'; then
1208214571Sdim    BASH_ARGS="$BASH_ARGS -o pipefail"
1209214571Sdim    AC_MSG_RESULT([yes])
1210214571Sdim  else
1211214571Sdim    AC_MSG_RESULT([no])
1212214571Sdim  fi
1213214571Sdim
1214214571Sdim  AC_MSG_CHECKING([if bash supports errexit (-e)])
1215214571Sdim  if ${BASH} -e -c 'true'; then
1216214571Sdim    BASH_ARGS="$BASH_ARGS -e"
1217214571Sdim    AC_MSG_RESULT([yes])
1218214571Sdim  else
1219214571Sdim    AC_MSG_RESULT([no])
1220214571Sdim  fi
1221214571Sdim
1222214571Sdim  AC_SUBST(BASH_ARGS)
1223214571Sdim])
1224214571Sdim
1225214571Sdim################################################################################
1226214571Sdim#
1227214571Sdim# Default make target
1228214571Sdim#
1229214571SdimAC_DEFUN_ONCE([BASIC_SETUP_DEFAULT_MAKE_TARGET],
1230214571Sdim[
1231214571Sdim  AC_ARG_WITH(default-make-target, [AS_HELP_STRING([--with-default-make-target],
1232214571Sdim      [set the default make target @<:@exploded-image@:>@])])
1233214571Sdim  if test "x$with_default_make_target" = "x" \
1234214571Sdim      || test "x$with_default_make_target" = "xyes"; then
1235214571Sdim    DEFAULT_MAKE_TARGET="exploded-image"
1236214571Sdim  elif test "x$with_default_make_target" = "xno"; then
1237214571Sdim    AC_MSG_ERROR([--without-default-make-target is not a valid option])
1238214571Sdim  else
1239214571Sdim    DEFAULT_MAKE_TARGET="$with_default_make_target"
1240214571Sdim  fi
1241214571Sdim
1242214571Sdim  AC_SUBST(DEFAULT_MAKE_TARGET)
1243214571Sdim])
1244214571Sdim
1245214571Sdim# Code to run after AC_OUTPUT
1246214571SdimAC_DEFUN_ONCE([BASIC_POST_CONFIG_OUTPUT],
1247214571Sdim[
1248214571Sdim  # Try to move config.log (generated by autoconf) to the configure-support directory.
1249214571Sdim  if test -e ./config.log; then
1250214571Sdim    $MV -f ./config.log "$CONFIGURESUPPORT_OUTPUTDIR/config.log" 2> /dev/null
1251214571Sdim  fi
1252214571Sdim
1253214571Sdim  # Rotate our log file (configure.log)
1254214571Sdim  if test -e "$OUTPUT_ROOT/configure.log.old"; then
1255214571Sdim    $RM -f "$OUTPUT_ROOT/configure.log.old"
1256214571Sdim  fi
1257214571Sdim  if test -e "$OUTPUT_ROOT/configure.log"; then
1258214571Sdim    $MV -f "$OUTPUT_ROOT/configure.log" "$OUTPUT_ROOT/configure.log.old" 2> /dev/null
1259214571Sdim  fi
1260214571Sdim
1261214571Sdim  # Move configure.log from current directory to the build output root
1262214571Sdim  if test -e ./configure.log; then
1263214571Sdim    $MV -f ./configure.log "$OUTPUT_ROOT/configure.log" 2> /dev/null
1264214571Sdim  fi
1265214571Sdim
1266214571Sdim  # Make the compare script executable
1267214571Sdim  $CHMOD +x $OUTPUT_ROOT/compare.sh
1268214571Sdim])
1269214571Sdim