basics.m4 revision 1430:76a5150b802b
1#
2# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# This code is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 2 only, as
7# published by the Free Software Foundation.  Oracle designates this
8# particular file as subject to the "Classpath" exception as provided
9# by Oracle in the LICENSE file that accompanied this code.
10#
11# This code is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14# version 2 for more details (a copy is included in the LICENSE file that
15# accompanied this code).
16#
17# You should have received a copy of the GNU General Public License version
18# 2 along with this work; if not, write to the Free Software Foundation,
19# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22# or visit www.oracle.com if you need additional information or have any
23# questions.
24#
25
26# Test if $1 is a valid argument to $3 (often is $JAVA passed as $3)
27# If so, then append $1 to $2 \
28# Also set JVM_ARG_OK to true/false depending on outcome.
29AC_DEFUN([ADD_JVM_ARG_IF_OK],
30[
31  $ECHO "Check if jvm arg is ok: $1" >&AS_MESSAGE_LOG_FD
32  $ECHO "Command: $3 $1 -version" >&AS_MESSAGE_LOG_FD
33  OUTPUT=`$3 $1 -version 2>&1`
34  FOUND_WARN=`$ECHO "$OUTPUT" | grep -i warn`
35  FOUND_VERSION=`$ECHO $OUTPUT | grep " version \""`
36  if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then
37    $2="[$]$2 $1"
38    JVM_ARG_OK=true
39  else
40    $ECHO "Arg failed:" >&AS_MESSAGE_LOG_FD
41    $ECHO "$OUTPUT" >&AS_MESSAGE_LOG_FD
42    JVM_ARG_OK=false
43  fi
44])
45
46# Appends a string to a path variable, only adding the : when needed.
47AC_DEFUN([BASIC_APPEND_TO_PATH],
48[
49  if test "x$2" != x; then
50    if test "x[$]$1" = x; then
51      $1="$2"
52    else
53      $1="[$]$1:$2"
54    fi
55  fi
56])
57
58# Prepends a string to a path variable, only adding the : when needed.
59AC_DEFUN([BASIC_PREPEND_TO_PATH],
60[
61  if test "x$2" != x; then
62    if test "x[$]$1" = x; then
63      $1="$2"
64    else
65      $1="$2:[$]$1"
66    fi
67  fi
68])
69
70# This will make sure the given variable points to a full and proper
71# path. This means:
72# 1) There will be no spaces in the path. On unix platforms,
73#    spaces in the path will result in an error. On Windows,
74#    the path will be rewritten using short-style to be space-free.
75# 2) The path will be absolute, and it will be in unix-style (on
76#     cygwin).
77# $1: The name of the variable to fix
78AC_DEFUN([BASIC_FIXUP_PATH],
79[
80  # Only process if variable expands to non-empty
81
82  if test "x[$]$1" != x; then
83    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
84      BASIC_FIXUP_PATH_CYGWIN($1)
85    elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
86      BASIC_FIXUP_PATH_MSYS($1)
87    else
88      # We're on a unix platform. Hooray! :)
89      path="[$]$1"
90      has_space=`$ECHO "$path" | $GREP " "`
91      if test "x$has_space" != x; then
92        AC_MSG_NOTICE([The path of $1, which resolves as "$path", is invalid.])
93        AC_MSG_ERROR([Spaces are not allowed in this path.])
94      fi
95
96      # Use eval to expand a potential ~
97      eval path="$path"
98      if test ! -f "$path" && test ! -d "$path"; then
99        AC_MSG_ERROR([The path of $1, which resolves as "$path", is not found.])
100      fi
101
102      $1="`cd "$path"; $THEPWDCMD -L`"
103    fi
104  fi
105])
106
107# This will make sure the given variable points to a executable
108# with a full and proper path. This means:
109# 1) There will be no spaces in the path. On unix platforms,
110#    spaces in the path will result in an error. On Windows,
111#    the path will be rewritten using short-style to be space-free.
112# 2) The path will be absolute, and it will be in unix-style (on
113#     cygwin).
114# Any arguments given to the executable is preserved.
115# If the input variable does not have a directory specification, then
116# it need to be in the PATH.
117# $1: The name of the variable to fix
118AC_DEFUN([BASIC_FIXUP_EXECUTABLE],
119[
120  # Only process if variable expands to non-empty
121
122  if test "x[$]$1" != x; then
123    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
124      BASIC_FIXUP_EXECUTABLE_CYGWIN($1)
125    elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
126      BASIC_FIXUP_EXECUTABLE_MSYS($1)
127    else
128      # We're on a unix platform. Hooray! :)
129      # First separate the path from the arguments. This will split at the first
130      # space.
131      complete="[$]$1"
132      path="${complete%% *}"
133      tmp="$complete EOL"
134      arguments="${tmp#* }"
135
136      # Cannot rely on the command "which" here since it doesn't always work.
137      is_absolute_path=`$ECHO "$path" | $GREP ^/`
138      if test -z "$is_absolute_path"; then
139        # Path to executable is not absolute. Find it.
140        IFS_save="$IFS"
141        IFS=:
142        for p in $PATH; do
143          if test -f "$p/$path" && test -x "$p/$path"; then
144            new_path="$p/$path"
145            break
146          fi
147        done
148        IFS="$IFS_save"
149      else
150        # This is an absolute path, we can use it without further modifications.
151        new_path="$path"
152      fi
153
154      if test "x$new_path" = x; then
155        AC_MSG_NOTICE([The path of $1, which resolves as "$complete", is not found.])
156        has_space=`$ECHO "$complete" | $GREP " "`
157        if test "x$has_space" != x; then
158          AC_MSG_NOTICE([This might be caused by spaces in the path, which is not allowed.])
159        fi
160        AC_MSG_ERROR([Cannot locate the the path of $1])
161      fi
162    fi
163
164    # Now join together the path and the arguments once again
165    if test "x$arguments" != xEOL; then
166      new_complete="$new_path ${arguments% *}"
167    else
168      new_complete="$new_path"
169    fi
170
171    if test "x$complete" != "x$new_complete"; then
172      $1="$new_complete"
173      AC_MSG_NOTICE([Rewriting $1 to "$new_complete"])
174    fi
175  fi
176])
177
178AC_DEFUN([BASIC_REMOVE_SYMBOLIC_LINKS],
179[
180  if test "x$OPENJDK_BUILD_OS" != xwindows; then
181    # Follow a chain of symbolic links. Use readlink
182    # where it exists, else fall back to horribly
183    # complicated shell code.
184    if test "x$READLINK_TESTED" != yes; then
185      # On MacOSX there is a readlink tool with a different
186      # purpose than the GNU readlink tool. Check the found readlink.
187      ISGNU=`$READLINK --version 2>&1 | $GREP GNU`
188      if test "x$ISGNU" = x; then
189        # A readlink that we do not know how to use.
190        # Are there other non-GNU readlinks out there?
191        READLINK_TESTED=yes
192        READLINK=
193      fi
194    fi
195
196    if test "x$READLINK" != x; then
197      $1=`$READLINK -f [$]$1`
198    else
199      # Save the current directory for restoring afterwards
200      STARTDIR=$PWD
201      COUNTER=0
202      sym_link_dir=`$DIRNAME [$]$1`
203      sym_link_file=`$BASENAME [$]$1`
204      cd $sym_link_dir
205      # Use -P flag to resolve symlinks in directories.
206      cd `$THEPWDCMD -P`
207      sym_link_dir=`$THEPWDCMD -P`
208      # Resolve file symlinks
209      while test $COUNTER -lt 20; do
210        ISLINK=`$LS -l $sym_link_dir/$sym_link_file | $GREP '\->' | $SED -e 's/.*-> \(.*\)/\1/'`
211        if test "x$ISLINK" == x; then
212          # This is not a symbolic link! We are done!
213          break
214        fi
215        # Again resolve directory symlinks since the target of the just found
216        # link could be in a different directory
217        cd `$DIRNAME $ISLINK`
218        sym_link_dir=`$THEPWDCMD -P`
219        sym_link_file=`$BASENAME $ISLINK`
220        let COUNTER=COUNTER+1
221      done
222      cd $STARTDIR
223      $1=$sym_link_dir/$sym_link_file
224    fi
225  fi
226])
227
228# Register a --with argument but mark it as deprecated
229# $1: The name of the with argument to deprecate, not including --with-
230AC_DEFUN([BASIC_DEPRECATED_ARG_WITH],
231[
232  AC_ARG_WITH($1, [AS_HELP_STRING([--with-$1],
233      [Deprecated. Option is kept for backwards compatibility and is ignored])],
234      [AC_MSG_WARN([Option --with-$1 is deprecated and will be ignored.])])
235])
236
237# Register a --enable argument but mark it as deprecated
238# $1: The name of the with argument to deprecate, not including --enable-
239# $2: The name of the argument to deprecate, in shell variable style (i.e. with _ instead of -)
240AC_DEFUN([BASIC_DEPRECATED_ARG_ENABLE],
241[
242  AC_ARG_ENABLE($1, [AS_HELP_STRING([--enable-$1],
243      [Deprecated. Option is kept for backwards compatibility and is ignored])])
244  if test "x$enable_$2" != x; then
245    AC_MSG_WARN([Option --enable-$1 is deprecated and will be ignored.])
246  fi
247])
248
249AC_DEFUN_ONCE([BASIC_INIT],
250[
251  # Save the original command line. This is passed to us by the wrapper configure script.
252  AC_SUBST(CONFIGURE_COMMAND_LINE)
253  # Save the path variable before it gets changed
254  ORIGINAL_PATH="$PATH"
255  AC_SUBST(ORIGINAL_PATH)
256  DATE_WHEN_CONFIGURED=`LANG=C date`
257  AC_SUBST(DATE_WHEN_CONFIGURED)
258  AC_MSG_NOTICE([Configuration created at $DATE_WHEN_CONFIGURED.])
259  AC_MSG_NOTICE([configure script generated at timestamp $DATE_WHEN_GENERATED.])
260])
261
262# Test that variable $1 denoting a program is not empty. If empty, exit with an error.
263# $1: variable to check
264AC_DEFUN([BASIC_CHECK_NONEMPTY],
265[
266  if test "x[$]$1" = x; then
267    AC_MSG_ERROR([Could not find required tool for $1])
268  fi
269])
270
271# Check that there are no unprocessed overridden variables left.
272# If so, they are an incorrect argument and we will exit with an error.
273AC_DEFUN([BASIC_CHECK_LEFTOVER_OVERRIDDEN],
274[
275  if test "x$CONFIGURE_OVERRIDDEN_VARIABLES" != x; then
276    # Replace the separating ! with spaces before presenting for end user.
277    unknown_variables=${CONFIGURE_OVERRIDDEN_VARIABLES//!/ }
278    AC_MSG_WARN([The following variables might be unknown to configure: $unknown_variables])
279  fi
280])
281
282# Setup a tool for the given variable. If correctly specified by the user,
283# use that value, otherwise search for the tool using the supplied code snippet.
284# $1: variable to set
285# $2: code snippet to call to look for the tool
286AC_DEFUN([BASIC_SETUP_TOOL],
287[
288  # Publish this variable in the help.
289  AC_ARG_VAR($1, [Override default value for $1])
290
291  if test "x[$]$1" = x; then
292    # The variable is not set by user, try to locate tool using the code snippet
293    $2
294  else
295    # The variable is set, but is it from the command line or the environment?
296
297    # Try to remove the string !$1! from our list.
298    try_remove_var=${CONFIGURE_OVERRIDDEN_VARIABLES//!$1!/}
299    if test "x$try_remove_var" = "x$CONFIGURE_OVERRIDDEN_VARIABLES"; then
300      # If it failed, the variable was not from the command line. Ignore it,
301      # but warn the user (except for BASH, which is always set by the calling BASH).
302      if test "x$1" != xBASH; then
303        AC_MSG_WARN([Ignoring value of $1 from the environment. Use command line variables instead.])
304      fi
305      # Try to locate tool using the code snippet
306      $2
307    else
308      # If it succeeded, then it was overridden by the user. We will use it
309      # for the tool.
310
311      # First remove it from the list of overridden variables, so we can test
312      # for unknown variables in the end.
313      CONFIGURE_OVERRIDDEN_VARIABLES="$try_remove_var"
314
315      # Check if the provided tool contains a complete path.
316      tool_specified="[$]$1"
317      tool_basename="${tool_specified##*/}"
318      if test "x$tool_basename" = "x$tool_specified"; then
319        # A command without a complete path is provided, search $PATH.
320        AC_MSG_NOTICE([Will search for user supplied tool $1=$tool_basename])
321        AC_PATH_PROG($1, $tool_basename)
322        if test "x[$]$1" = x; then
323          AC_MSG_ERROR([User supplied tool $tool_basename could not be found])
324        fi
325      else
326        # Otherwise we believe it is a complete path. Use it as it is.
327        AC_MSG_NOTICE([Will use user supplied tool $1=$tool_specified])
328        AC_MSG_CHECKING([for $1])
329        if test ! -x "$tool_specified"; then
330          AC_MSG_RESULT([not found])
331          AC_MSG_ERROR([User supplied tool $1=$tool_specified does not exist or is not executable])
332        fi
333        AC_MSG_RESULT([$tool_specified])
334      fi
335    fi
336  fi
337])
338
339# Call BASIC_SETUP_TOOL with AC_PATH_PROGS to locate the tool
340# $1: variable to set
341# $2: executable name (or list of names) to look for
342AC_DEFUN([BASIC_PATH_PROGS],
343[
344  BASIC_SETUP_TOOL($1, [AC_PATH_PROGS($1, $2)])
345])
346
347# Call BASIC_SETUP_TOOL with AC_CHECK_TOOLS to locate the tool
348# $1: variable to set
349# $2: executable name (or list of names) to look for
350AC_DEFUN([BASIC_CHECK_TOOLS],
351[
352  BASIC_SETUP_TOOL($1, [AC_CHECK_TOOLS($1, $2)])
353])
354
355# Like BASIC_PATH_PROGS but fails if no tool was found.
356# $1: variable to set
357# $2: executable name (or list of names) to look for
358AC_DEFUN([BASIC_REQUIRE_PROGS],
359[
360  BASIC_PATH_PROGS($1, $2)
361  BASIC_CHECK_NONEMPTY($1)
362])
363
364# Like BASIC_SETUP_TOOL but fails if no tool was found.
365# $1: variable to set
366# $2: autoconf macro to call to look for the special tool
367AC_DEFUN([BASIC_REQUIRE_SPECIAL],
368[
369  BASIC_SETUP_TOOL($1, [$2])
370  BASIC_CHECK_NONEMPTY($1)
371])
372
373# Setup the most fundamental tools that relies on not much else to set up,
374# but is used by much of the early bootstrap code.
375AC_DEFUN_ONCE([BASIC_SETUP_FUNDAMENTAL_TOOLS],
376[
377  # Start with tools that do not need have cross compilation support
378  # and can be expected to be found in the default PATH. These tools are
379  # used by configure. Nor are these tools expected to be found in the
380  # devkit from the builddeps server either, since they are
381  # needed to download the devkit.
382
383  # First are all the simple required tools.
384  BASIC_REQUIRE_PROGS(BASENAME, basename)
385  BASIC_REQUIRE_PROGS(BASH, bash)
386  BASIC_REQUIRE_PROGS(CAT, cat)
387  BASIC_REQUIRE_PROGS(CHMOD, chmod)
388  BASIC_REQUIRE_PROGS(CMP, cmp)
389  BASIC_REQUIRE_PROGS(COMM, comm)
390  BASIC_REQUIRE_PROGS(CP, cp)
391  BASIC_REQUIRE_PROGS(CUT, cut)
392  BASIC_REQUIRE_PROGS(DATE, date)
393  BASIC_REQUIRE_PROGS(DIFF, [gdiff diff])
394  BASIC_REQUIRE_PROGS(DIRNAME, dirname)
395  BASIC_REQUIRE_PROGS(ECHO, echo)
396  BASIC_REQUIRE_PROGS(EXPR, expr)
397  BASIC_REQUIRE_PROGS(FILE, file)
398  BASIC_REQUIRE_PROGS(FIND, find)
399  BASIC_REQUIRE_PROGS(HEAD, head)
400  BASIC_REQUIRE_PROGS(LN, ln)
401  BASIC_REQUIRE_PROGS(LS, ls)
402  BASIC_REQUIRE_PROGS(MKDIR, mkdir)
403  BASIC_REQUIRE_PROGS(MKTEMP, mktemp)
404  BASIC_REQUIRE_PROGS(MV, mv)
405  BASIC_REQUIRE_PROGS(NAWK, [nawk gawk awk])
406  BASIC_REQUIRE_PROGS(PRINTF, printf)
407  BASIC_REQUIRE_PROGS(RM, rm)
408  BASIC_REQUIRE_PROGS(SH, sh)
409  BASIC_REQUIRE_PROGS(SORT, sort)
410  BASIC_REQUIRE_PROGS(TAIL, tail)
411  BASIC_REQUIRE_PROGS(TAR, tar)
412  BASIC_REQUIRE_PROGS(TEE, tee)
413  BASIC_REQUIRE_PROGS(TOUCH, touch)
414  BASIC_REQUIRE_PROGS(TR, tr)
415  BASIC_REQUIRE_PROGS(UNAME, uname)
416  BASIC_REQUIRE_PROGS(UNIQ, uniq)
417  BASIC_REQUIRE_PROGS(WC, wc)
418  BASIC_REQUIRE_PROGS(WHICH, which)
419  BASIC_REQUIRE_PROGS(XARGS, xargs)
420
421  # Then required tools that require some special treatment.
422  BASIC_REQUIRE_SPECIAL(AWK, [AC_PROG_AWK])
423  BASIC_REQUIRE_SPECIAL(GREP, [AC_PROG_GREP])
424  BASIC_REQUIRE_SPECIAL(EGREP, [AC_PROG_EGREP])
425  BASIC_REQUIRE_SPECIAL(FGREP, [AC_PROG_FGREP])
426  BASIC_REQUIRE_SPECIAL(SED, [AC_PROG_SED])
427
428  # Always force rm.
429  RM="$RM -f"
430
431  # pwd behaves differently on various platforms and some don't support the -L flag.
432  # Always use the bash builtin pwd to get uniform behavior.
433  THEPWDCMD=pwd
434
435  # These are not required on all platforms
436  BASIC_PATH_PROGS(CYGPATH, cygpath)
437  BASIC_PATH_PROGS(READLINK, [greadlink readlink])
438  BASIC_PATH_PROGS(DF, df)
439  BASIC_PATH_PROGS(SETFILE, SetFile)
440  BASIC_PATH_PROGS(CPIO, [cpio bsdcpio])
441])
442
443# Setup basic configuration paths, and platform-specific stuff related to PATHs.
444AC_DEFUN_ONCE([BASIC_SETUP_PATHS],
445[
446  # Save the current directory this script was started from
447  CURDIR="$PWD"
448
449  if test "x$OPENJDK_TARGET_OS" = "xwindows"; then
450    PATH_SEP=";"
451    BASIC_CHECK_PATHS_WINDOWS
452  else
453    PATH_SEP=":"
454  fi
455  AC_SUBST(PATH_SEP)
456
457  # We get the top-level directory from the supporting wrappers.
458  AC_MSG_CHECKING([for top-level directory])
459  AC_MSG_RESULT([$TOPDIR])
460  AC_SUBST(TOPDIR)
461
462  # Save the original version of TOPDIR for string comparisons
463  ORIGINAL_TOPDIR="$TOPDIR"
464  AC_SUBST(ORIGINAL_TOPDIR)
465
466  # We can only call BASIC_FIXUP_PATH after BASIC_CHECK_PATHS_WINDOWS.
467  BASIC_FIXUP_PATH(CURDIR)
468  BASIC_FIXUP_PATH(TOPDIR)
469  # SRC_ROOT is a traditional alias for TOPDIR.
470  SRC_ROOT=$TOPDIR
471
472  # Calculate a canonical version of TOPDIR for string comparisons
473  CANONICAL_TOPDIR=$TOPDIR
474  BASIC_REMOVE_SYMBOLIC_LINKS([CANONICAL_TOPDIR])
475  AC_SUBST(CANONICAL_TOPDIR)
476
477  # Locate the directory of this script.
478  AUTOCONF_DIR=$TOPDIR/common/autoconf
479])
480
481AC_DEFUN_ONCE([BASIC_SETUP_DEVKIT],
482[
483  AC_ARG_WITH([devkit], [AS_HELP_STRING([--with-devkit],
484      [use this devkit for compilers, tools and resources])],
485      [
486        BASIC_FIXUP_PATH([with_devkit])
487        DEVKIT_ROOT="$with_devkit"
488        # Check for a meta data info file in the root of the devkit
489        if test -f "$DEVKIT_ROOT/devkit.info"; then
490          # This potentially sets the following:
491          # DEVKIT_NAME: A descriptive name of the devkit
492          # DEVKIT_TOOLCHAIN_PATH: Corresponds to --with-toolchain-path
493          # DEVKIT_EXTRA_PATH: Corresponds to --with-extra-path
494          # DEVKIT_SYSROOT: Corresponds to --with-sysroot
495          . $DEVKIT_ROOT/devkit.info
496        fi
497
498        AC_MSG_CHECKING([for devkit])
499        if test "x$DEVKIT_NAME" != x; then
500          AC_MSG_RESULT([$DEVKIT_NAME in $DEVKIT_ROOT])
501        else
502          AC_MSG_RESULT([$DEVKIT_ROOT])
503        fi
504
505        if test "x$DEVKIT_EXTRA_PATH" != x; then
506          BASIC_PREPEND_TO_PATH([EXTRA_PATH],$DEVKIT_EXTRA_PATH)
507        fi
508
509        # Fallback default of just /bin if DEVKIT_PATH is not defined
510        if test "x$DEVKIT_TOOLCHAIN_PATH" = x; then
511          DEVKIT_TOOLCHAIN_PATH="$DEVKIT_ROOT/bin"
512        fi
513        BASIC_PREPEND_TO_PATH([TOOLCHAIN_PATH],$DEVKIT_TOOLCHAIN_PATH)
514
515        # If DEVKIT_SYSROOT is set, use that, otherwise try a couple of known
516        # places for backwards compatiblity.
517        if test "x$DEVKIT_SYSROOT" != x; then
518          SYSROOT="$DEVKIT_SYSROOT"
519        elif test -d "$DEVKIT_ROOT/$host_alias/libc"; then
520          SYSROOT="$DEVKIT_ROOT/$host_alias/libc"
521        elif test -d "$DEVKIT_ROOT/$host/sys-root"; then
522          SYSROOT="$DEVKIT_ROOT/$host/sys-root"
523        fi
524      ]
525  )
526
527  # You can force the sysroot if the sysroot encoded into the compiler tools
528  # is not correct.
529  AC_ARG_WITH(sys-root, [AS_HELP_STRING([--with-sys-root],
530      [alias for --with-sysroot for backwards compatability])],
531      [SYSROOT=$with_sys_root]
532  )
533
534  AC_ARG_WITH(sysroot, [AS_HELP_STRING([--with-sysroot],
535      [use this directory as sysroot])],
536      [SYSROOT=$with_sysroot]
537  )
538
539  AC_ARG_WITH([tools-dir], [AS_HELP_STRING([--with-tools-dir],
540      [alias for --with-toolchain-path for backwards compatibility])],
541      [BASIC_PREPEND_TO_PATH([TOOLCHAIN_PATH],$with_tools_dir)]
542  )
543
544  AC_ARG_WITH([toolchain-path], [AS_HELP_STRING([--with-toolchain-path],
545      [prepend these directories when searching for toolchain binaries (compilers etc)])],
546      [BASIC_PREPEND_TO_PATH([TOOLCHAIN_PATH],$with_toolchain_path)]
547  )
548
549  AC_ARG_WITH([extra-path], [AS_HELP_STRING([--with-extra-path],
550      [prepend these directories to the default path])],
551      [BASIC_PREPEND_TO_PATH([EXTRA_PATH],$with_extra_path)]
552  )
553
554  if test "x$OPENJDK_BUILD_OS" = "xmacosx"; then
555    # detect if Xcode is installed by running xcodebuild -version
556    # if no Xcode installed, xcodebuild exits with 1
557    # if Xcode is installed, even if xcode-select is misconfigured, then it exits with 0
558    if /usr/bin/xcodebuild -version >/dev/null 2>&1; then
559      # We need to use xcodebuild in the toolchain dir provided by the user, this will
560      # fall back on the stub binary in /usr/bin/xcodebuild
561      AC_PATH_PROG([XCODEBUILD], [xcodebuild], [/usr/bin/xcodebuild], [$TOOLCHAIN_PATH])
562    else
563      # this should result in SYSROOT being empty, unless --with-sysroot is provided
564      # when only the command line tools are installed there are no SDKs, so headers
565      # are copied into the system frameworks
566      XCODEBUILD=
567      AC_SUBST(XCODEBUILD)
568    fi
569
570    AC_MSG_CHECKING([for sdk name])
571    AC_ARG_WITH([sdk-name], [AS_HELP_STRING([--with-sdk-name],
572        [use the platform SDK of the given name. @<:@macosx@:>@])],
573        [SDKNAME=$with_sdk_name]
574    )
575    AC_MSG_RESULT([$SDKNAME])
576
577    # if toolchain path is specified then don't rely on system headers, they may not compile
578    HAVE_SYSTEM_FRAMEWORK_HEADERS=0
579    test -z "$TOOLCHAIN_PATH" && \
580      HAVE_SYSTEM_FRAMEWORK_HEADERS=`test ! -f /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h; echo $?`
581
582    if test -z "$SYSROOT"; then
583      if test -n "$XCODEBUILD"; then
584        # if we don't have system headers, use default SDK name (last resort)
585        if test -z "$SDKNAME" -a $HAVE_SYSTEM_FRAMEWORK_HEADERS -eq 0; then
586          SDKNAME=${SDKNAME:-macosx}
587        fi
588
589        if test -n "$SDKNAME"; then
590          # Call xcodebuild to determine SYSROOT
591          SYSROOT=`"$XCODEBUILD" -sdk $SDKNAME -version | grep '^Path: ' | sed 's/Path: //'`
592        fi
593      else
594        if test $HAVE_SYSTEM_FRAMEWORK_HEADERS -eq 0; then
595          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])
596        fi
597      fi
598    else
599      # warn user if --with-sdk-name was also set
600      if test -n "$with_sdk_name"; then
601        AC_MSG_WARN([Both SYSROOT and --with-sdk-name are set, only SYSROOT will be used])
602      fi
603    fi
604
605    if test $HAVE_SYSTEM_FRAMEWORK_HEADERS -eq 0 -a -z "$SYSROOT"; then
606      # If no system framework headers, then SYSROOT must be set, or we won't build
607      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.])
608    fi
609
610    # Perform a basic sanity test
611    if test ! -f "$SYSROOT/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h"; then
612      if test -z "$SYSROOT"; then
613        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])
614      else
615        AC_MSG_ERROR([Invalid SDK or SYSROOT path, dependent framework headers not found])
616      fi
617    fi
618
619    # set SDKROOT too, Xcode tools will pick it up
620    AC_SUBST(SDKROOT,$SYSROOT)
621  fi
622
623  # Prepend the extra path to the global path
624  BASIC_PREPEND_TO_PATH([PATH],$EXTRA_PATH)
625
626  if test "x$OPENJDK_BUILD_OS" = "xsolaris"; then
627    # Add extra search paths on solaris for utilities like ar and as etc...
628    PATH="$PATH:/usr/ccs/bin:/usr/sfw/bin:/opt/csw/bin"
629  fi
630
631  AC_MSG_CHECKING([for sysroot])
632  AC_MSG_RESULT([$SYSROOT])
633  AC_MSG_CHECKING([for toolchain path])
634  AC_MSG_RESULT([$TOOLCHAIN_PATH])
635  AC_MSG_CHECKING([for extra path])
636  AC_MSG_RESULT([$EXTRA_PATH])
637])
638
639AC_DEFUN_ONCE([BASIC_SETUP_OUTPUT_DIR],
640[
641
642  AC_ARG_WITH(conf-name, [AS_HELP_STRING([--with-conf-name],
643      [use this as the name of the configuration @<:@generated from important configuration options@:>@])],
644      [ CONF_NAME=${with_conf_name} ])
645
646  # Test from where we are running configure, in or outside of src root.
647  AC_MSG_CHECKING([where to store configuration])
648  if test "x$CURDIR" = "x$SRC_ROOT" || test "x$CURDIR" = "x$SRC_ROOT/common" \
649      || test "x$CURDIR" = "x$SRC_ROOT/common/autoconf" \
650      || test "x$CURDIR" = "x$SRC_ROOT/make" ; then
651    # We are running configure from the src root.
652    # Create a default ./build/target-variant-debuglevel output root.
653    if test "x${CONF_NAME}" = x; then
654      AC_MSG_RESULT([in default location])
655      CONF_NAME="${OPENJDK_TARGET_OS}-${OPENJDK_TARGET_CPU}-${JDK_VARIANT}-${ANDED_JVM_VARIANTS}-${DEBUG_LEVEL}"
656    else
657      AC_MSG_RESULT([in build directory with custom name])
658    fi
659    OUTPUT_ROOT="$SRC_ROOT/build/${CONF_NAME}"
660    $MKDIR -p "$OUTPUT_ROOT"
661    if test ! -d "$OUTPUT_ROOT"; then
662      AC_MSG_ERROR([Could not create build directory $OUTPUT_ROOT])
663    fi
664  else
665    # We are running configure from outside of the src dir.
666    # Then use the current directory as output dir!
667    # If configuration is situated in normal build directory, just use the build
668    # directory name as configuration name, otherwise use the complete path.
669    if test "x${CONF_NAME}" = x; then
670      CONF_NAME=`$ECHO $CURDIR | $SED -e "s!^${SRC_ROOT}/build/!!"`
671    fi
672    OUTPUT_ROOT="$CURDIR"
673    AC_MSG_RESULT([in current directory])
674
675    # WARNING: This might be a bad thing to do. You need to be sure you want to
676    # have a configuration in this directory. Do some sanity checks!
677
678    if test ! -e "$OUTPUT_ROOT/spec.gmk"; then
679      # If we have a spec.gmk, we have run here before and we are OK. Otherwise, check for
680      # other files
681      files_present=`$LS $OUTPUT_ROOT`
682      # Configure has already touched config.log and confdefs.h in the current dir when this check
683      # is performed.
684      filtered_files=`$ECHO "$files_present" | $SED -e 's/config.log//g' -e 's/confdefs.h//g' -e 's/ //g' \
685      | $TR -d '\n'`
686      if test "x$filtered_files" != x; then
687        AC_MSG_NOTICE([Current directory is $CURDIR.])
688        AC_MSG_NOTICE([Since this is not the source root, configure will output the configuration here])
689        AC_MSG_NOTICE([(as opposed to creating a configuration in <src_root>/build/<conf-name>).])
690        AC_MSG_NOTICE([However, this directory is not empty. This is not allowed, since it could])
691        AC_MSG_NOTICE([seriously mess up just about everything.])
692        AC_MSG_NOTICE([Try 'cd $SRC_ROOT' and restart configure])
693        AC_MSG_NOTICE([(or create a new empty directory and cd to it).])
694        AC_MSG_ERROR([Will not continue creating configuration in $CURDIR])
695      fi
696    fi
697  fi
698  AC_MSG_CHECKING([what configuration name to use])
699  AC_MSG_RESULT([$CONF_NAME])
700
701  BASIC_FIXUP_PATH(OUTPUT_ROOT)
702
703  CONFIGURESUPPORT_OUTPUTDIR="$OUTPUT_ROOT/configure-support"
704  $MKDIR -p "$CONFIGURESUPPORT_OUTPUTDIR"
705
706  AC_SUBST(SPEC, $OUTPUT_ROOT/spec.gmk)
707  AC_SUBST(CONF_NAME, $CONF_NAME)
708  AC_SUBST(OUTPUT_ROOT, $OUTPUT_ROOT)
709  AC_SUBST(CONFIGURESUPPORT_OUTPUTDIR)
710
711  # The spec.gmk file contains all variables for the make system.
712  AC_CONFIG_FILES([$OUTPUT_ROOT/spec.gmk:$AUTOCONF_DIR/spec.gmk.in])
713  # The hotspot-spec.gmk file contains legacy variables for the hotspot make system.
714  AC_CONFIG_FILES([$OUTPUT_ROOT/hotspot-spec.gmk:$AUTOCONF_DIR/hotspot-spec.gmk.in])
715  # The bootcycle-spec.gmk file contains support for boot cycle builds.
716  AC_CONFIG_FILES([$OUTPUT_ROOT/bootcycle-spec.gmk:$AUTOCONF_DIR/bootcycle-spec.gmk.in])
717  # The compare.sh is used to compare the build output to other builds.
718  AC_CONFIG_FILES([$OUTPUT_ROOT/compare.sh:$AUTOCONF_DIR/compare.sh.in])
719  # The generated Makefile knows where the spec.gmk is and where the source is.
720  # You can run make from the OUTPUT_ROOT, or from the top-level Makefile
721  # which will look for generated configurations
722  AC_CONFIG_FILES([$OUTPUT_ROOT/Makefile:$AUTOCONF_DIR/Makefile.in])
723])
724
725#%%% Simple tools %%%
726
727# Check if we have found a usable version of make
728# $1: the path to a potential make binary (or empty)
729# $2: the description on how we found this
730AC_DEFUN([BASIC_CHECK_MAKE_VERSION],
731[
732  MAKE_CANDIDATE="$1"
733  DESCRIPTION="$2"
734  if test "x$MAKE_CANDIDATE" != x; then
735    AC_MSG_NOTICE([Testing potential make at $MAKE_CANDIDATE, found using $DESCRIPTION])
736    MAKE_VERSION_STRING=`$MAKE_CANDIDATE --version | $HEAD -n 1`
737    IS_GNU_MAKE=`$ECHO $MAKE_VERSION_STRING | $GREP 'GNU Make'`
738    if test "x$IS_GNU_MAKE" = x; then
739      AC_MSG_NOTICE([Found potential make at $MAKE_CANDIDATE, however, this is not GNU Make. Ignoring.])
740    else
741      IS_MODERN_MAKE=`$ECHO $MAKE_VERSION_STRING | $GREP -e '3\.8[[12]]' -e '4\.'`
742      if test "x$IS_MODERN_MAKE" = x; then
743        AC_MSG_NOTICE([Found GNU make at $MAKE_CANDIDATE, however this is not version 3.81 or later. (it is: $MAKE_VERSION_STRING). Ignoring.])
744      else
745        if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
746          if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
747            MAKE_EXPECTED_ENV='cygwin'
748          elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
749            MAKE_EXPECTED_ENV='msys'
750          else
751            AC_MSG_ERROR([Unknown Windows environment])
752          fi
753          MAKE_BUILT_FOR=`$MAKE_CANDIDATE --version | $GREP -i 'built for'`
754          IS_MAKE_CORRECT_ENV=`$ECHO $MAKE_BUILT_FOR | $GREP $MAKE_EXPECTED_ENV`
755        else
756          # Not relevant for non-Windows
757          IS_MAKE_CORRECT_ENV=true
758        fi
759        if test "x$IS_MAKE_CORRECT_ENV" = x; then
760          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.])
761        else
762          FOUND_MAKE=$MAKE_CANDIDATE
763          BASIC_FIXUP_EXECUTABLE(FOUND_MAKE)
764        fi
765      fi
766    fi
767  fi
768])
769
770AC_DEFUN([BASIC_CHECK_MAKE_OUTPUT_SYNC],
771[
772  # Check if make supports the output sync option and if so, setup using it.
773  AC_MSG_CHECKING([if make --output-sync is supported])
774  if $MAKE --version -O > /dev/null 2>&1; then
775    OUTPUT_SYNC_SUPPORTED=true
776    AC_MSG_RESULT([yes])
777    AC_MSG_CHECKING([for output-sync value])
778    AC_ARG_WITH([output-sync], [AS_HELP_STRING([--with-output-sync],
779      [set make output sync type if supported by make. @<:@recurse@:>@])],
780      [OUTPUT_SYNC=$with_output_sync])
781    if test "x$OUTPUT_SYNC" = "x"; then
782      OUTPUT_SYNC=none
783    fi
784    AC_MSG_RESULT([$OUTPUT_SYNC])
785    if ! $MAKE --version -O$OUTPUT_SYNC > /dev/null 2>&1; then
786      AC_MSG_ERROR([Make did not the support the value $OUTPUT_SYNC as output sync type.])
787    fi
788  else
789    OUTPUT_SYNC_SUPPORTED=false
790    AC_MSG_RESULT([no])
791  fi
792  AC_SUBST(OUTPUT_SYNC_SUPPORTED)
793  AC_SUBST(OUTPUT_SYNC)
794])
795
796# Goes looking for a usable version of GNU make.
797AC_DEFUN([BASIC_CHECK_GNU_MAKE],
798[
799  # We need to find a recent version of GNU make. Especially on Solaris, this can be tricky.
800  if test "x$MAKE" != x; then
801    # User has supplied a make, test it.
802    if test ! -f "$MAKE"; then
803      AC_MSG_ERROR([The specified make (by MAKE=$MAKE) is not found.])
804    fi
805    BASIC_CHECK_MAKE_VERSION("$MAKE", [user supplied MAKE=$MAKE])
806    if test "x$FOUND_MAKE" = x; then
807      AC_MSG_ERROR([The specified make (by MAKE=$MAKE) is not GNU make 3.81 or newer.])
808    fi
809  else
810    # Try our hardest to locate a correct version of GNU make
811    AC_PATH_PROGS(CHECK_GMAKE, gmake)
812    BASIC_CHECK_MAKE_VERSION("$CHECK_GMAKE", [gmake in PATH])
813
814    if test "x$FOUND_MAKE" = x; then
815      AC_PATH_PROGS(CHECK_MAKE, make)
816      BASIC_CHECK_MAKE_VERSION("$CHECK_MAKE", [make in PATH])
817    fi
818
819    if test "x$FOUND_MAKE" = x; then
820      if test "x$TOOLCHAIN_PATH" != x; then
821        # We have a toolchain path, check that as well before giving up.
822        OLD_PATH=$PATH
823        PATH=$TOOLCHAIN_PATH:$PATH
824        AC_PATH_PROGS(CHECK_TOOLSDIR_GMAKE, gmake)
825        BASIC_CHECK_MAKE_VERSION("$CHECK_TOOLSDIR_GMAKE", [gmake in tools-dir])
826        if test "x$FOUND_MAKE" = x; then
827          AC_PATH_PROGS(CHECK_TOOLSDIR_MAKE, make)
828          BASIC_CHECK_MAKE_VERSION("$CHECK_TOOLSDIR_MAKE", [make in tools-dir])
829        fi
830        PATH=$OLD_PATH
831      fi
832    fi
833
834    if test "x$FOUND_MAKE" = x; then
835      AC_MSG_ERROR([Cannot find GNU make 3.81 or newer! Please put it in the path, or add e.g. MAKE=/opt/gmake3.81/make as argument to configure.])
836    fi
837  fi
838
839  MAKE=$FOUND_MAKE
840  AC_SUBST(MAKE)
841  AC_MSG_NOTICE([Using GNU make 3.81 (or later) at $FOUND_MAKE (version: $MAKE_VERSION_STRING)])
842
843  BASIC_CHECK_MAKE_OUTPUT_SYNC
844])
845
846AC_DEFUN([BASIC_CHECK_FIND_DELETE],
847[
848  # Test if find supports -delete
849  AC_MSG_CHECKING([if find supports -delete])
850  FIND_DELETE="-delete"
851
852  DELETEDIR=`$MKTEMP -d tmp.XXXXXXXXXX` || (echo Could not create temporary directory!; exit $?)
853
854  echo Hejsan > $DELETEDIR/TestIfFindSupportsDelete
855
856  TEST_DELETE=`$FIND "$DELETEDIR" -name TestIfFindSupportsDelete $FIND_DELETE 2>&1`
857  if test -f $DELETEDIR/TestIfFindSupportsDelete; then
858    # No, it does not.
859    rm $DELETEDIR/TestIfFindSupportsDelete
860    if test "x$OPENJDK_TARGET_OS" = "xaix"; then
861      # AIX 'find' is buggy if called with '-exec {} \+' and an empty file list
862      FIND_DELETE="-print | xargs rm"
863    else
864      FIND_DELETE="-exec rm \{\} \+"
865    fi
866    AC_MSG_RESULT([no])
867  else
868    AC_MSG_RESULT([yes])
869  fi
870  rmdir $DELETEDIR
871  AC_SUBST(FIND_DELETE)
872])
873
874AC_DEFUN_ONCE([BASIC_SETUP_COMPLEX_TOOLS],
875[
876  BASIC_CHECK_GNU_MAKE
877
878  BASIC_CHECK_FIND_DELETE
879
880  # These tools might not be installed by default,
881  # need hint on how to install them.
882  BASIC_REQUIRE_PROGS(UNZIP, unzip)
883  BASIC_REQUIRE_PROGS(ZIP, zip)
884
885  # Non-required basic tools
886
887  BASIC_PATH_PROGS(LDD, ldd)
888  if test "x$LDD" = "x"; then
889    # List shared lib dependencies is used for
890    # debug output and checking for forbidden dependencies.
891    # We can build without it.
892    LDD="true"
893  fi
894  BASIC_PATH_PROGS(OTOOL, otool)
895  if test "x$OTOOL" = "x"; then
896    OTOOL="true"
897  fi
898  BASIC_PATH_PROGS(READELF, [greadelf readelf])
899  BASIC_PATH_PROGS(HG, hg)
900  BASIC_PATH_PROGS(STAT, stat)
901  BASIC_PATH_PROGS(TIME, time)
902  # Check if it's GNU time
903  IS_GNU_TIME=`$TIME --version 2>&1 | $GREP 'GNU time'`
904  if test "x$IS_GNU_TIME" != x; then
905    IS_GNU_TIME=yes
906  else
907    IS_GNU_TIME=no
908  fi
909  AC_SUBST(IS_GNU_TIME)
910
911  if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
912    BASIC_REQUIRE_PROGS(DSYMUTIL, dsymutil)
913    BASIC_REQUIRE_PROGS(XATTR, xattr)
914    BASIC_PATH_PROGS(CODESIGN, codesign)
915    if test "x$CODESIGN" != "x"; then
916      # Verify that the openjdk_codesign certificate is present
917      AC_MSG_CHECKING([if openjdk_codesign certificate is present])
918      rm -f codesign-testfile
919      touch codesign-testfile
920      codesign -s openjdk_codesign codesign-testfile 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD || CODESIGN=
921      rm -f codesign-testfile
922      if test "x$CODESIGN" = x; then
923        AC_MSG_RESULT([no])
924      else
925        AC_MSG_RESULT([yes])
926      fi
927    fi
928  fi
929])
930
931# Check if build directory is on local disk. If not possible to determine,
932# we prefer to claim it's local.
933# Argument 1: directory to test
934# Argument 2: what to do if it is on local disk
935# Argument 3: what to do otherwise (remote disk or failure)
936AC_DEFUN([BASIC_CHECK_DIR_ON_LOCAL_DISK],
937[
938  # df -l lists only local disks; if the given directory is not found then
939  # a non-zero exit code is given
940  if test "x$DF" = x; then
941    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
942      # msys does not have df; use Windows "net use" instead.
943      IS_NETWORK_DISK=`net use | grep \`pwd -W | cut -d ":" -f 1 | tr a-z A-Z\`:`
944      if test "x$IS_NETWORK_DISK" = x; then
945        $2
946      else
947        $3
948      fi
949    else
950      # No df here, say it's local
951      $2
952    fi
953  else
954    if $DF -l $1 > /dev/null 2>&1; then
955      $2
956    else
957      $3
958    fi
959  fi
960])
961
962# Check that source files have basic read permissions set. This might
963# not be the case in cygwin in certain conditions.
964AC_DEFUN_ONCE([BASIC_CHECK_SRC_PERMS],
965[
966  if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then
967    file_to_test="$SRC_ROOT/LICENSE"
968    if test `$STAT -c '%a' "$file_to_test"` -lt 400; then
969      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.])
970    fi
971  fi
972])
973
974AC_DEFUN_ONCE([BASIC_TEST_USABILITY_ISSUES],
975[
976  # Did user specify any unknown variables?
977  BASIC_CHECK_LEFTOVER_OVERRIDDEN
978
979  AC_MSG_CHECKING([if build directory is on local disk])
980  BASIC_CHECK_DIR_ON_LOCAL_DISK($OUTPUT_ROOT,
981      [OUTPUT_DIR_IS_LOCAL="yes"],
982      [OUTPUT_DIR_IS_LOCAL="no"])
983  AC_MSG_RESULT($OUTPUT_DIR_IS_LOCAL)
984
985  BASIC_CHECK_SRC_PERMS
986
987  # Check if the user has any old-style ALT_ variables set.
988  FOUND_ALT_VARIABLES=`env | grep ^ALT_`
989
990  # Before generating output files, test if they exist. If they do, this is a reconfigure.
991  # Since we can't properly handle the dependencies for this, warn the user about the situation
992  if test -e $OUTPUT_ROOT/spec.gmk; then
993    IS_RECONFIGURE=yes
994  else
995    IS_RECONFIGURE=no
996  fi
997])
998
999# Check for support for specific options in bash
1000AC_DEFUN_ONCE([BASIC_CHECK_BASH_OPTIONS],
1001[
1002  # Test if bash supports pipefail.
1003  AC_MSG_CHECKING([if bash supports pipefail])
1004  if ${BASH} -c 'set -o pipefail'; then
1005    BASH_ARGS="$BASH_ARGS -o pipefail"
1006    AC_MSG_RESULT([yes])
1007  else
1008    AC_MSG_RESULT([no])
1009  fi
1010
1011  AC_MSG_CHECKING([if bash supports errexit (-e)])
1012  if ${BASH} -e -c 'true'; then
1013    BASH_ARGS="$BASH_ARGS -e"
1014    AC_MSG_RESULT([yes])
1015  else
1016    AC_MSG_RESULT([no])
1017  fi
1018
1019  AC_SUBST(BASH_ARGS)
1020])
1021