configure revision 983:96f74167f6a0
1139825Simp#!/bin/bash
2207141Sjeff#
3207141Sjeff# Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
4207141Sjeff# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
536201Sjulian#
636206Sjulian# This code is free software; you can redistribute it and/or modify it
736206Sjulian# under the terms of the GNU General Public License version 2 only, as
836206Sjulian# published by the Free Software Foundation.
936206Sjulian#
1036201Sjulian# This code is distributed in the hope that it will be useful, but WITHOUT
1161926Smckusick# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1236201Sjulian# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1361926Smckusick# version 2 for more details (a copy is included in the LICENSE file that
1461926Smckusick# accompanied this code).
1561926Smckusick#
1636201Sjulian# You should have received a copy of the GNU General Public License version
1736201Sjulian# 2 along with this work; if not, write to the Free Software Foundation,
1836201Sjulian# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1936201Sjulian#
2036201Sjulian# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2136201Sjulian# or visit www.oracle.com if you need additional information or have any
2236201Sjulian# questions.
2336201Sjulian#
2436201Sjulian
2536201Sjulianif test "x$1" != xCHECKME; then
2636201Sjulian  echo "WARNING: Calling the wrapper script directly is deprecated and unsupported."
2736201Sjulian  echo "Not all features of configure will be available."
28207141Sjeff  echo "Use the 'configure' script in the top-level directory instead."
29207141Sjeff  TOPDIR=$(cd $(dirname $0)/../.. > /dev/null && pwd)
30207141Sjeffelse
31207141Sjeff  # Now the next argument is the absolute top-level directory path.
32207141Sjeff  # The TOPDIR variable is passed on to configure.ac.
33207141Sjeff  TOPDIR="$2"
34207141Sjeff  # Remove these two arguments to get to the user supplied arguments
35207141Sjeff  shift
36207141Sjeff  shift
37207141Sjefffi
3836201Sjulian
3961926Smckusickconf_script_dir="$TOPDIR/common/autoconf"
4036201Sjulian
4136201Sjulianif [ "$CUSTOM_CONFIG_DIR" = "" ]; then
4292299Sobrien  conf_custom_script_dir="$TOPDIR/closed/autoconf"
4392299Sobrienelse
4492299Sobrien  conf_custom_script_dir="$CUSTOM_CONFIG_DIR"
45183072Skibfi
46231091Skib
47183072Skib###
48183072Skib### Test that the generated configure is up-to-date
4936206Sjulian###
50173501Sru
5136206Sjulianrun_autogen_or_fail() {
5236206Sjulian  if test "x`which autoconf 2> /dev/null`" = x; then
5336206Sjulian    echo "Cannot locate autoconf, unable to correct situation."
5436206Sjulian    echo "Please install autoconf and run 'bash autogen.sh' to update the generated files."
5536206Sjulian    echo "Error: Cannot continue" 1>&2
5636201Sjulian    exit 1
5748276Speter  else
5848276Speter    echo "Running autogen.sh to correct the situation"
5960041Sphk    bash $conf_script_dir/autogen.sh
6036201Sjulian  fi
61131907Smarcel}
62156203Sjeff
63243018Sjeffcheck_autoconf_timestamps() {
64222958Sjeff  for file in $conf_script_dir/configure.ac $conf_script_dir/*.m4 ; do
65140709Sjeff    if test $file -nt $conf_script_dir/generated-configure.sh; then
6636201Sjulian      echo "Warning: The configure source files is newer than the generated files."
6736201Sjulian      run_autogen_or_fail
68140709Sjeff    fi
69207141Sjeff  done
70220374Smckusick
7136206Sjulian  if test -e $conf_custom_script_dir/generated-configure.sh; then
72251171Sjeff    # If custom source configure is available, make sure it is up-to-date as well.
7376357Smckusick    for file in $conf_script_dir/configure.ac $conf_script_dir/*.m4 $conf_custom_script_dir/*.m4; do
74145824Sjeff      if test $file -nt $conf_custom_script_dir/generated-configure.sh; then
7536201Sjulian        echo "Warning: The configure source files is newer than the custom generated files."
7636201Sjulian        run_autogen_or_fail
7749535Sphk      fi
78222958Sjeff    done
7936201Sjulian  fi
8059241Srwatson}
8136201Sjulian
8236201Sjuliancheck_hg_updates() {
8336201Sjulian  if test "x`which hg 2> /dev/null`" != x; then
8436201Sjulian    conf_updated_autoconf_files=`cd $conf_script_dir && hg status -mard 2> /dev/null | grep autoconf`
8536201Sjulian    if test "x$conf_updated_autoconf_files" != x; then
8636201Sjulian      echo "Configure source code has been updated, checking time stamps"
8736201Sjulian      check_autoconf_timestamps
8836201Sjulian    fi
89145824Sjeff
90222958Sjeff    if test -e $conf_custom_script_dir; then
91222958Sjeff      # If custom source configure is available, make sure it is up-to-date as well.
92145824Sjeff      conf_custom_updated_autoconf_files=`cd $conf_custom_script_dir && hg status -mard 2> /dev/null | grep autoconf`
93242734Sjeff      if test "x$conf_custom_updated_autoconf_files" != x; then
94242734Sjeff        echo "Configure custom source code has been updated, checking time stamps"
95183072Skib        check_autoconf_timestamps
96141685Sphk      fi
97243018Sjeff    fi
98243018Sjeff  fi
99141685Sphk}
100141685Sphk
101141685Sphk# Check for local changes
102141685Sphkcheck_hg_updates
103141685Sphk
104141685Sphkif test -e $conf_custom_script_dir/generated-configure.sh; then
105141685Sphk  # Test if open configure is newer than custom configure, if so, custom needs to
106141685Sphk  # be regenerated. This test is required to ensure consistency with custom source.
107141685Sphk  conf_open_configure_timestamp=`grep DATE_WHEN_GENERATED= $conf_script_dir/generated-configure.sh  | cut -d"=" -f 2`
108141685Sphk  conf_custom_configure_timestamp=`grep DATE_WHEN_GENERATED= $conf_custom_script_dir/generated-configure.sh  | cut -d"=" -f 2`
109141685Sphk  if test $conf_open_configure_timestamp -gt $conf_custom_configure_timestamp; then
110141685Sphk    echo "Warning: The generated configure file contains changes not present in the custom generated file."
111141685Sphk    run_autogen_or_fail
112141685Sphk  fi
113141685Sphkfi
114141685Sphk
115141685Sphk# Autoconf calls the configure script recursively sometimes.
116141685Sphk# Don't start logging twice in that case
117141685Sphkif test "x$conf_debug_configure" = xtrue; then
118141685Sphk  conf_debug_configure=recursive
119141685Sphkfi
120141685Sphk
121141685Sphk###
122141685Sphk### Process command-line arguments
123141685Sphk###
124141685Sphk
125141685Sphk# Returns a shell-escaped version of the argument given.
126141685Sphkfunction shell_quote() {
127141685Sphk  if [[ -n "$1" ]]; then
128141685Sphk    # Uses only shell-safe characters?  No quoting needed.
129141685Sphk    # '=' is a zsh meta-character, but only in word-initial position.
130141685Sphk    if echo "$1" | grep '^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\.:,%/+=_-]\{1,\}$' > /dev/null \
131141685Sphk        && ! echo "$1" | grep '^=' > /dev/null; then
132141685Sphk      quoted="$1"
133141685Sphk    else
134141685Sphk      if echo "$1" | grep "[\'!]" > /dev/null; then
135141685Sphk        # csh does history expansion within single quotes, but not
136141685Sphk        # when backslash-escaped!
137207309Sjeff        local quoted_quote="'\\''" quoted_exclam="'\\!'"
138207309Sjeff        word="${1//\'/${quoted_quote}}"
139207309Sjeff        word="${1//\!/${quoted_exclam}}"
140207309Sjeff      fi
141207309Sjeff      quoted="'$1'"
142207309Sjeff    fi
143207309Sjeff    echo "$quoted"
144207309Sjeff  fi
145207309Sjeff}
146207309Sjeff
147207309Sjeffconf_processed_arguments=()
148207309Sjeffconf_quoted_arguments=()
149207309Sjeffconf_openjdk_target=
150207309Sjeff
151207309Sjefffor conf_option
152223325Sjeffdo
153141685Sphk
154141685Sphk  # Process (and remove) our own extensions that will not be passed to autoconf
155141685Sphk  case $conf_option in
156223325Sjeff    --openjdk-target=*)
157141685Sphk      conf_openjdk_target=`expr "X$conf_option" : '[^=]*=\(.*\)'`
158141685Sphk      ;;
159141685Sphk    --debug-configure)
160141685Sphk      if test "x$conf_debug_configure" != xrecursive; then
161141685Sphk        conf_debug_configure=true
162141685Sphk        export conf_debug_configure
163207141Sjeff      fi
164141685Sphk      ;;
165156203Sjeff    *)
166141685Sphk      conf_processed_arguments=("${conf_processed_arguments[@]}" "$conf_option")
167207141Sjeff      ;;
168207141Sjeff  esac
169141685Sphk
170141685Sphk  # Store all variables overridden on the command line
171141685Sphk  case $conf_option in
172141685Sphk    [^-]*=*)
173141685Sphk      # Add name of variable to CONFIGURE_OVERRIDDEN_VARIABLES list inside !...!.
174141685Sphk      conf_env_var=`expr "x$conf_option" : 'x\([^=]*\)='`
175141685Sphk      CONFIGURE_OVERRIDDEN_VARIABLES="$CONFIGURE_OVERRIDDEN_VARIABLES!$conf_env_var!"
176141685Sphk      ;;
177141685Sphk  esac
178141685Sphk
179141685Sphk  # Save the arguments, intelligently quoted for CONFIGURE_COMMAND_LINE.
180141685Sphk  case $conf_option in
181141685Sphk    *=*)
182141685Sphk      conf_option_name=`expr "x$conf_option" : 'x\([^=]*\)='`
183141685Sphk      conf_option_name=$(shell_quote "$conf_option_name")
184141685Sphk      conf_option_value=`expr "x$conf_option" : 'x[^=]*=\(.*\)'`
185141685Sphk      conf_option_value=$(shell_quote "$conf_option_value")
186141685Sphk      conf_quoted_arguments=("${conf_quoted_arguments[@]}" "$conf_option_name=$conf_option_value")
187141685Sphk      ;;
188141685Sphk    *)
189141685Sphk      conf_quoted_arguments=("${conf_quoted_arguments[@]}" "$(shell_quote "$conf_option")")
190141685Sphk      ;;
191141685Sphk  esac
192141685Sphk
193141685Sphk  # Check for certain autoconf options that require extra action
194141685Sphk  case $conf_option in
195141685Sphk    -build | --build | --buil | --bui | --bu |-build=* | --build=* | --buil=* | --bui=* | --bu=*)
196141685Sphk      conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
197141685Sphk    -target | --target | --targe | --targ | --tar | --ta | --t | -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
198141685Sphk      conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
199157805Skensmith    -host | --host | --hos | --ho | -host=* | --host=* | --hos=* | --ho=*)
200141685Sphk      conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
201141685Sphk    -help | --help | --hel | --he | -h)
202141685Sphk      conf_print_help=true ;;
203141685Sphk  esac
204141685Sphkdone
205141685Sphk
206141685Sphk# Save the quoted command line
207141685SphkCONFIGURE_COMMAND_LINE="${conf_quoted_arguments[@]}"
208141685Sphk
209141685Sphkif test "x$conf_legacy_crosscompile" != "x"; then
210141685Sphk  if test "x$conf_openjdk_target" != "x"; then
211141685Sphk    echo "Error: Specifying --openjdk-target together with autoconf"
212141685Sphk    echo "legacy cross-compilation flags is not supported."
213141685Sphk    echo "You specified: --openjdk-target=$conf_openjdk_target and $conf_legacy_crosscompile."
214141685Sphk    echo "The recommended use is just --openjdk-target."
215141685Sphk    exit 1
216141685Sphk  else
217141685Sphk    echo "Warning: You are using legacy autoconf cross-compilation flags."
218141685Sphk    echo "It is recommended that you use --openjdk-target instead."
219141685Sphk    echo ""
220141685Sphk  fi
221141685Sphkfi
222141685Sphk
223141685Sphkif test "x$conf_openjdk_target" != "x"; then
224141685Sphk  conf_build_platform=`sh $conf_script_dir/build-aux/config.guess`
225141685Sphk  conf_processed_arguments=("--build=$conf_build_platform" "--host=$conf_openjdk_target" "--target=$conf_openjdk_target" "${conf_processed_arguments[@]}")
226141685Sphkfi
227141685Sphk
228141685Sphk# Make configure exit with error on invalid options as default.
229222958Sjeff# Can be overridden by --disable-option-checking, since we prepend our argument
230222958Sjeff# and later options override earlier.
231222958Sjeffconf_processed_arguments=("--enable-option-checking=fatal" "${conf_processed_arguments[@]}")
232222958Sjeff
233222958Sjeff###
234222958Sjeff### Call the configure script
235222958Sjeff###
236222958Sjeffif test -e $conf_custom_script_dir/generated-configure.sh; then
237222958Sjeff  # Custom source configure available; run that instead
238222958Sjeff  echo "Running custom generated-configure.sh"
239222958Sjeff  conf_script_to_run=$conf_custom_script_dir/generated-configure.sh
240222958Sjeffelse
241222958Sjeff  echo "Running generated-configure.sh"
242222958Sjeff  conf_script_to_run=$conf_script_dir/generated-configure.sh
243222958Sjefffi
244222958Sjeff
245222958Sjeffif test "x$conf_debug_configure" != x; then
246222958Sjeff  # Turn on shell debug output if requested (initial or recursive)
247222958Sjeff  set -x
248141685Sphkfi
249141685Sphk
250141685Sphkif test "x$conf_debug_configure" = xtrue; then
251141685Sphk  # Turn on logging, but don't turn on twice when called recursive
252141685Sphk  conf_debug_logfile=./debug-configure.log
253141685Sphk  (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
254141685Sphkelse
255141685Sphk  ( . $conf_script_to_run "${conf_processed_arguments[@]}" )
256141685Sphkfi
257141685Sphk
258141685Sphkconf_result_code=$?
259141685Sphk###
260141685Sphk### Post-processing
261141685Sphk###
262141685Sphk
263141685Sphkif test $conf_result_code -eq 0; then
264141685Sphk  if test "x$conf_print_help" = xtrue; then
265141685Sphk    cat <<EOT
266141685Sphk
267141685SphkAdditional (non-autoconf) OpenJDK Options:
268141685Sphk  --openjdk-target=TARGET cross-compile with TARGET as target platform
269141685Sphk                          (i.e. the one you will run the resulting binary on).
270141685Sphk                          Equivalent to --host=TARGET --target=TARGET
271141685Sphk                          --build=<current platform>
272141685Sphk  --debug-configure       Run the configure script with additional debug
273141685Sphk                          logging enabled.
274141685Sphk
275141685SphkEOT
276141685Sphk
277141685Sphk    # Print list of toolchains. This must be done by the autoconf script.
278141685Sphk    ( CONFIGURE_PRINT_TOOLCHAIN_LIST=true . $conf_script_to_run PRINTF=printf )
279141685Sphk
280141685Sphk    cat <<EOT
281207142Spjd
282207142SpjdPlease be aware that, when cross-compiling, the OpenJDK configure script will
283141685Sphkgenerally use 'target' where autoconf traditionally uses 'host'.
284141685Sphk
285141685SphkAlso note that variables must be passed on the command line. Variables in the
286141685Sphkenvironment will generally be ignored, unlike traditional autoconf scripts.
287141685SphkEOT
288141685Sphk  fi
289141685Sphkelse
290141685Sphk  echo configure exiting with result code $conf_result_code
291141685Sphkfi
292141685Sphk
293141685Sphkexit $conf_result_code
294141685Sphk