configure revision 1319:507654772146
1168404Spjd#!/bin/bash
2168404Spjd#
3168404Spjd# Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
4168404Spjd# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5168404Spjd#
6168404Spjd# This code is free software; you can redistribute it and/or modify it
7168404Spjd# under the terms of the GNU General Public License version 2 only, as
8168404Spjd# published by the Free Software Foundation.
9168404Spjd#
10168404Spjd# This code is distributed in the hope that it will be useful, but WITHOUT
11168404Spjd# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12168404Spjd# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13168404Spjd# version 2 for more details (a copy is included in the LICENSE file that
14168404Spjd# accompanied this code).
15168404Spjd#
16168404Spjd# You should have received a copy of the GNU General Public License version
17168404Spjd# 2 along with this work; if not, write to the Free Software Foundation,
18168404Spjd# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19168404Spjd#
20168404Spjd# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21168404Spjd# or visit www.oracle.com if you need additional information or have any
22219089Spjd# questions.
23249643Smm#
24252140Sdelphij
25265754Sdelphijif test "x$1" != xCHECKME; then
26168404Spjd  echo "WARNING: Calling the wrapper script directly is deprecated and unsupported."
27168404Spjd  echo "Not all features of configure will be available."
28219089Spjd  echo "Use the 'configure' script in the top-level directory instead."
29219089Spjd  TOPDIR=$(cd $(dirname $0)/../.. > /dev/null && pwd)
30185029Spjdelse
31168404Spjd  # Now the next argument is the absolute top-level directory path.
32168404Spjd  # The TOPDIR variable is passed on to configure.ac.
33168404Spjd  TOPDIR="$2"
34168404Spjd  # Remove these two arguments to get to the user supplied arguments
35168404Spjd  shift
36168404Spjd  shift
37168404Spjdfi
38185029Spjd
39168404Spjdif test "x$BASH" = x; then
40168404Spjd  echo "Error: This script must be run using bash." 1>&2
41168404Spjd  exit 1
42168404Spjdfi
43168404Spjd# Force autoconf to use bash. This also means we must disable autoconf re-exec.
44168404Spjdexport CONFIG_SHELL=$BASH
45168404Spjdexport _as_can_reexec=no
46185029Spjd
47219089Spjdconf_script_dir="$TOPDIR/common/autoconf"
48219089Spjd
49249643Smmif [ "$CUSTOM_CONFIG_DIR" = "" ]; then
50168404Spjd  conf_custom_script_dir="$TOPDIR/closed/autoconf"
51219089Spjdelse
52219089Spjd  conf_custom_script_dir="$CUSTOM_CONFIG_DIR"
53219089Spjdfi
54219089Spjd
55219089Spjd###
56219089Spjd### Test that the generated configure is up-to-date
57219089Spjd###
58219089Spjd
59219089Spjdrun_autogen_or_fail() {
60219089Spjd  if test "x`which autoconf 2> /dev/null | grep -v '^no autoconf in'`" = x; then
61219089Spjd    echo "Cannot locate autoconf, unable to correct situation."
62219089Spjd    echo "Please install autoconf and run 'bash autogen.sh' to update the generated files."
63219089Spjd    echo "Error: Cannot continue" 1>&2
64219089Spjd    exit 1
65219089Spjd  else
66219089Spjd    echo "Running autogen.sh to correct the situation"
67219089Spjd    bash $conf_script_dir/autogen.sh
68219089Spjd  fi
69168404Spjd}
70168404Spjd
71168404Spjdcheck_autoconf_timestamps() {
72219089Spjd  for file in $conf_script_dir/configure.ac $conf_script_dir/*.m4 ; do
73168404Spjd    if test $file -nt $conf_script_dir/generated-configure.sh; then
74168404Spjd      echo "Warning: The configure source files is newer than the generated files."
75168404Spjd      run_autogen_or_fail
76168404Spjd    fi
77168404Spjd  done
78219089Spjd
79168404Spjd  if test -e $conf_custom_script_dir/generated-configure.sh; then
80168404Spjd    # If custom source configure is available, make sure it is up-to-date as well.
81168404Spjd    for file in $conf_script_dir/configure.ac $conf_script_dir/*.m4 $conf_custom_script_dir/*.m4; do
82168404Spjd      if test $file -nt $conf_custom_script_dir/generated-configure.sh; then
83168404Spjd        echo "Warning: The configure source files is newer than the custom generated files."
84168404Spjd        run_autogen_or_fail
85168404Spjd      fi
86219089Spjd    done
87168404Spjd  fi
88168404Spjd}
89219089Spjd
90168404Spjdcheck_hg_updates() {
91168404Spjd  if test "x`which hg 2> /dev/null | grep -v '^no hg in'`" != x; then
92168404Spjd    conf_updated_autoconf_files=`cd $conf_script_dir && hg status -mard 2> /dev/null | grep autoconf`
93168404Spjd    if test "x$conf_updated_autoconf_files" != x; then
94168404Spjd      echo "Configure source code has been updated, checking time stamps"
95219089Spjd      check_autoconf_timestamps
96168404Spjd    fi
97168404Spjd
98168404Spjd    if test -e $conf_custom_script_dir; then
99168404Spjd      # If custom source configure is available, make sure it is up-to-date as well.
100168404Spjd      conf_custom_updated_autoconf_files=`cd $conf_custom_script_dir && hg status -mard 2> /dev/null | grep autoconf`
101219089Spjd      if test "x$conf_custom_updated_autoconf_files" != x; then
102168404Spjd        echo "Configure custom source code has been updated, checking time stamps"
103168404Spjd        check_autoconf_timestamps
104168404Spjd      fi
105168404Spjd    fi
106168404Spjd  fi
107219089Spjd}
108168404Spjd
109168404Spjd# Check for local changes
110168404Spjdcheck_hg_updates
111168404Spjd
112168404Spjdif test -e $conf_custom_script_dir/generated-configure.sh; then
113219089Spjd  # Test if open configure is newer than custom configure, if so, custom needs to
114168404Spjd  # be regenerated. This test is required to ensure consistency with custom source.
115168404Spjd  conf_open_configure_timestamp=`grep DATE_WHEN_GENERATED= $conf_script_dir/generated-configure.sh  | cut -d"=" -f 2`
116168404Spjd  conf_custom_configure_timestamp=`grep DATE_WHEN_GENERATED= $conf_custom_script_dir/generated-configure.sh  | cut -d"=" -f 2`
117168404Spjd  if test $conf_open_configure_timestamp -gt $conf_custom_configure_timestamp; then
118219089Spjd    echo "Warning: The generated configure file contains changes not present in the custom generated file."
119219089Spjd    run_autogen_or_fail
120219089Spjd  fi
121219089Spjdfi
122219089Spjd
123219089Spjd# Autoconf calls the configure script recursively sometimes.
124219089Spjd# Don't start logging twice in that case
125219089Spjdif test "x$conf_debug_configure" = xtrue; then
126219089Spjd  conf_debug_configure=recursive
127219089Spjdfi
128219089Spjd
129219089Spjd###
130168404Spjd### Process command-line arguments
131168404Spjd###
132168404Spjd
133219089Spjd# Returns a shell-escaped version of the argument given.
134168404Spjdfunction shell_quote() {
135168404Spjd  if [[ -n "$1" ]]; then
136168404Spjd    # Uses only shell-safe characters?  No quoting needed.
137168404Spjd    # '=' is a zsh meta-character, but only in word-initial position.
138168404Spjd    if echo "$1" | grep '^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\.:,%/+=_-]\{1,\}$' > /dev/null \
139168404Spjd        && ! echo "$1" | grep '^=' > /dev/null; then
140219089Spjd      quoted="$1"
141168404Spjd    else
142168404Spjd      if echo "$1" | grep "[\'!]" > /dev/null; then
143168404Spjd        # csh does history expansion within single quotes, but not
144168404Spjd        # when backslash-escaped!
145168404Spjd        local quoted_quote="'\\''" quoted_exclam="'\\!'"
146219089Spjd        word="${1//\'/${quoted_quote}}"
147168404Spjd        word="${1//\!/${quoted_exclam}}"
148168404Spjd      fi
149168404Spjd      quoted="'$1'"
150168404Spjd    fi
151168404Spjd    echo "$quoted"
152168404Spjd  fi
153219089Spjd}
154168404Spjd
155168404Spjdconf_processed_arguments=()
156168404Spjdconf_quoted_arguments=()
157168404Spjdconf_openjdk_target=
158168404Spjd
159219089Spjdfor conf_option
160168404Spjddo
161168404Spjd
162168404Spjd  # Process (and remove) our own extensions that will not be passed to autoconf
163168404Spjd  case $conf_option in
164168404Spjd    --openjdk-target=*)
165219089Spjd      conf_openjdk_target=`expr "X$conf_option" : '[^=]*=\(.*\)'`
166168404Spjd      ;;
167219089Spjd    --debug-configure)
168168404Spjd      if test "x$conf_debug_configure" != xrecursive; then
169168404Spjd        conf_debug_configure=true
170185029Spjd        export conf_debug_configure
171219089Spjd      fi
172219089Spjd      ;;
173219089Spjd    *)
174219089Spjd      conf_processed_arguments=("${conf_processed_arguments[@]}" "$conf_option")
175219089Spjd      ;;
176219089Spjd  esac
177219089Spjd
178219089Spjd  # Store all variables overridden on the command line
179219089Spjd  case $conf_option in
180219089Spjd    [^-]*=*)
181219089Spjd      # Add name of variable to CONFIGURE_OVERRIDDEN_VARIABLES list inside !...!.
182219089Spjd      conf_env_var=`expr "x$conf_option" : 'x\([^=]*\)='`
183219089Spjd      CONFIGURE_OVERRIDDEN_VARIABLES="$CONFIGURE_OVERRIDDEN_VARIABLES!$conf_env_var!"
184219089Spjd      ;;
185219089Spjd  esac
186219089Spjd
187219089Spjd  # Save the arguments, intelligently quoted for CONFIGURE_COMMAND_LINE.
188219089Spjd  case $conf_option in
189185029Spjd    *=*)
190185029Spjd      conf_option_name=`expr "x$conf_option" : 'x\([^=]*\)='`
191219089Spjd      conf_option_name=$(shell_quote "$conf_option_name")
192185029Spjd      conf_option_value=`expr "x$conf_option" : 'x[^=]*=\(.*\)'`
193185029Spjd      conf_option_value=$(shell_quote "$conf_option_value")
194185029Spjd      conf_quoted_arguments=("${conf_quoted_arguments[@]}" "$conf_option_name=$conf_option_value")
195185029Spjd      ;;
196185029Spjd    *)
197185029Spjd      conf_quoted_arguments=("${conf_quoted_arguments[@]}" "$(shell_quote "$conf_option")")
198185029Spjd      ;;
199219089Spjd  esac
200185029Spjd
201185029Spjd  # Check for certain autoconf options that require extra action
202185029Spjd  case $conf_option in
203185029Spjd    -build | --build | --buil | --bui | --bu |-build=* | --build=* | --buil=* | --bui=* | --bu=*)
204185029Spjd      conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
205219089Spjd    -target | --target | --targe | --targ | --tar | --ta | --t | -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
206185029Spjd      conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
207185029Spjd    -host | --host | --hos | --ho | -host=* | --host=* | --hos=* | --ho=*)
208185029Spjd      conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
209185029Spjd    -help | --help | --hel | --he | -h)
210185029Spjd      conf_print_help=true ;;
211185029Spjd  esac
212185029Spjddone
213219089Spjd
214185029Spjd# Save the quoted command line
215185029SpjdCONFIGURE_COMMAND_LINE="${conf_quoted_arguments[@]}"
216219089Spjd
217219089Spjdif test "x$conf_legacy_crosscompile" != "x"; then
218219089Spjd  if test "x$conf_openjdk_target" != "x"; then
219219089Spjd    echo "Error: Specifying --openjdk-target together with autoconf"
220219089Spjd    echo "legacy cross-compilation flags is not supported."
221219089Spjd    echo "You specified: --openjdk-target=$conf_openjdk_target and $conf_legacy_crosscompile."
222219089Spjd    echo "The recommended use is just --openjdk-target."
223219089Spjd    exit 1
224219089Spjd  else
225219089Spjd    echo "Warning: You are using legacy autoconf cross-compilation flags."
226219089Spjd    echo "It is recommended that you use --openjdk-target instead."
227219089Spjd    echo ""
228219089Spjd  fi
229219089Spjdfi
230219089Spjd
231219089Spjdif test "x$conf_openjdk_target" != "x"; then
232219089Spjd  conf_build_platform=`sh $conf_script_dir/build-aux/config.guess`
233219089Spjd  conf_processed_arguments=("--build=$conf_build_platform" "--host=$conf_openjdk_target" "--target=$conf_openjdk_target" "${conf_processed_arguments[@]}")
234219089Spjdfi
235219089Spjd
236219089Spjd# Make configure exit with error on invalid options as default.
237219089Spjd# Can be overridden by --disable-option-checking, since we prepend our argument
238219089Spjd# and later options override earlier.
239219089Spjdconf_processed_arguments=("--enable-option-checking=fatal" "${conf_processed_arguments[@]}")
240219089Spjd
241219089Spjd###
242219089Spjd### Call the configure script
243219089Spjd###
244168404Spjdif test -e $conf_custom_script_dir/generated-configure.sh; then
245168404Spjd  # Custom source configure available; run that instead
246168404Spjd  echo "Running custom generated-configure.sh"
247168404Spjd  conf_script_to_run=$conf_custom_script_dir/generated-configure.sh
248168404Spjdelse
249209962Smm  echo "Running generated-configure.sh"
250168404Spjd  conf_script_to_run=$conf_script_dir/generated-configure.sh
251168404Spjdfi
252168404Spjd
253209962Smmif test "x$conf_debug_configure" != x; then
254209962Smm  # Turn on shell debug output if requested (initial or recursive)
255209962Smm  set -x
256209962Smmfi
257209962Smm
258168404Spjdif test "x$conf_debug_configure" = xtrue; then
259168404Spjd  # Turn on logging, but don't turn on twice when called recursive
260168404Spjd  conf_debug_logfile=./debug-configure.log
261168404Spjd  (exec 3>&1 ; (. $conf_script_to_run "${conf_processed_arguments[@]}" 2>&1 1>&3 ) | tee -a $conf_debug_logfile 1>&2 ; exec 3>&-) | tee -a $conf_debug_logfile
262219089Spjdelse
263168404Spjd  ( . $conf_script_to_run "${conf_processed_arguments[@]}" )
264219089Spjdfi
265185029Spjd
266168404Spjdconf_result_code=$?
267185029Spjd###
268185029Spjd### Post-processing
269219089Spjd###
270219089Spjd
271219089Spjdif test $conf_result_code -eq 0; then
272219089Spjd  if test "x$conf_print_help" = xtrue; then
273219089Spjd    cat <<EOT
274168404Spjd
275168404SpjdAdditional (non-autoconf) OpenJDK Options:
276219089Spjd  --openjdk-target=TARGET cross-compile with TARGET as target platform
277219089Spjd                          (i.e. the one you will run the resulting binary on).
278219089Spjd                          Equivalent to --host=TARGET --target=TARGET
279219089Spjd                          --build=<current platform>
280185029Spjd  --debug-configure       Run the configure script with additional debug
281252140Sdelphij                          logging enabled.
282252140Sdelphij
283168404SpjdEOT
284219089Spjd
285247406Smm    # Print list of toolchains. This must be done by the autoconf script.
286219089Spjd    ( CONFIGURE_PRINT_TOOLCHAIN_LIST=true . $conf_script_to_run PRINTF=printf )
287168404Spjd
288249643Smm    cat <<EOT
289219089Spjd
290185029SpjdPlease be aware that, when cross-compiling, the OpenJDK configure script will
291185029Spjdgenerally use 'target' where autoconf traditionally uses 'host'.
292249643Smm
293168404SpjdAlso note that variables must be passed on the command line. Variables in the
294168404Spjdenvironment will generally be ignored, unlike traditional autoconf scripts.
295209962SmmEOT
296209962Smm  fi
297209962Smmelse
298219089Spjd  echo configure exiting with result code $conf_result_code
299209962Smmfi
300219089Spjd
301209962Smmexit $conf_result_code
302209962Smm