common/autoconf/configure

changeset 494
e64f2cb57d05
parent 478
2ba6f4da4bf3
child 797
69da99676239
     1.1 --- a/common/autoconf/configure	Wed Oct 24 13:11:42 2012 -0700
     1.2 +++ b/common/autoconf/configure	Fri Oct 26 14:29:57 2012 -0700
     1.3 @@ -1,4 +1,32 @@
     1.4 -#!/bin/sh
     1.5 +#!/bin/bash
     1.6 +#
     1.7 +# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     1.8 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.9 +#
    1.10 +# This code is free software; you can redistribute it and/or modify it
    1.11 +# under the terms of the GNU General Public License version 2 only, as
    1.12 +# published by the Free Software Foundation.
    1.13 +#
    1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 +# version 2 for more details (a copy is included in the LICENSE file that
    1.18 +# accompanied this code).
    1.19 +#
    1.20 +# You should have received a copy of the GNU General Public License version
    1.21 +# 2 along with this work; if not, write to the Free Software Foundation,
    1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 +#
    1.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 +# or visit www.oracle.com if you need additional information or have any
    1.26 +# questions.
    1.27 +#
    1.28 +
    1.29 +if test "x$BASH_VERSION" = x; then
    1.30 +  echo This script needs bash to run.
    1.31 +  echo It is recommended to use the configure script in the source tree root instead.
    1.32 +  exit 1
    1.33 +fi
    1.34  
    1.35  CONFIGURE_COMMAND_LINE="$@"
    1.36  conf_script_dir=`dirname $0`
    1.37 @@ -13,58 +41,81 @@
    1.38  ### Test that the generated configure is up-to-date
    1.39  ###
    1.40  
    1.41 -# On Solaris /bin/sh doesn't support test -nt but /usr/bin/test does.
    1.42 -TEST=`which test`
    1.43 -
    1.44 -print_error_not_up_to_date() {
    1.45 -  echo "Error: The configure source files is newer than the generated files."
    1.46 -  echo "Please run 'sh autogen.sh' to update the generated files."
    1.47 -  echo "Note that this test might trigger incorrectly sometimes due to hg timestamps".
    1.48 +run_autogen_or_fail() {
    1.49 +  if test "x`which autoconf 2> /dev/null`" = x; then
    1.50 +    echo "Cannot locate autoconf, unable to correct situation."
    1.51 +    echo "Please install autoconf and run 'bash autogen.sh' to update the generated files."
    1.52 +    echo "Error: Cannot continue" 1>&2
    1.53 +    exit 1
    1.54 +  else
    1.55 +    echo "Running autogen.sh to correct the situation"
    1.56 +    bash $conf_script_dir/autogen.sh
    1.57 +  fi
    1.58  }
    1.59  
    1.60 -# NOTE: This test can occasionally go wrong due to the way mercurial handles
    1.61 -# timestamps. It it supposed to aid during development of build-infra, but should
    1.62 -# go away before making this the default build system.
    1.63 -for file in configure.ac *.m4 ; do
    1.64 -  if $TEST $file -nt generated-configure.sh; then
    1.65 -    print_error_not_up_to_date
    1.66 -    exit 1
    1.67 -  fi
    1.68 -done
    1.69 -
    1.70 -if $TEST -e $conf_custom_script_dir/generated-configure.sh; then
    1.71 -  # If custom source configure is available, make sure it is up-to-date as well.
    1.72 -  for file in configure.ac *.m4 $conf_custom_script_dir/*.m4; do
    1.73 -    if $TEST $file -nt $conf_custom_script_dir/generated-configure.sh; then
    1.74 -      print_error_not_up_to_date
    1.75 -      exit 1
    1.76 +check_autoconf_timestamps() {
    1.77 +  for file in $conf_script_dir/configure.ac $conf_script_dir/*.m4 ; do
    1.78 +    if test $file -nt $conf_script_dir/generated-configure.sh; then
    1.79 +      echo "Warning: The configure source files is newer than the generated files."
    1.80 +      run_autogen_or_fail
    1.81      fi
    1.82    done
    1.83  
    1.84 +  if test -e $conf_custom_script_dir/generated-configure.sh; then
    1.85 +    # If custom source configure is available, make sure it is up-to-date as well.
    1.86 +    for file in $conf_script_dir/configure.ac $conf_script_dir/*.m4 $conf_custom_script_dir/*.m4; do
    1.87 +      if test $file -nt $conf_custom_script_dir/generated-configure.sh; then
    1.88 +        echo "Warning: The configure source files is newer than the custom generated files."
    1.89 +        run_autogen_or_fail
    1.90 +      fi
    1.91 +    done
    1.92 +  fi
    1.93 +}
    1.94 +
    1.95 +check_hg_updates() {
    1.96 +  if test "x`which hg 2> /dev/null`" != x; then
    1.97 +    conf_updated_autoconf_files=`cd $conf_script_dir && hg status -mard 2> /dev/null | grep autoconf`
    1.98 +    if test "x$conf_updated_autoconf_files" != x; then
    1.99 +      echo "Configure source code has been updated, checking time stamps"
   1.100 +      check_autoconf_timestamps
   1.101 +    fi
   1.102 +
   1.103 +    if test -e $conf_custom_script_dir; then
   1.104 +      # If custom source configure is available, make sure it is up-to-date as well.
   1.105 +      conf_custom_updated_autoconf_files=`cd $conf_custom_script_dir && hg status -mard 2> /dev/null | grep autoconf`
   1.106 +      if test "x$conf_custom_updated_autoconf_files" != x; then
   1.107 +        echo "Configure custom source code has been updated, checking time stamps"
   1.108 +        check_autoconf_timestamps
   1.109 +      fi
   1.110 +    fi
   1.111 +    
   1.112 +  fi
   1.113 +}
   1.114 +
   1.115 +# Check for local changes
   1.116 +check_hg_updates
   1.117 +
   1.118 +if test -e $conf_custom_script_dir/generated-configure.sh; then
   1.119    # Test if open configure is newer than custom configure, if so, custom needs to
   1.120    # be regenerated. This test is required to ensure consistency with custom source.
   1.121 -  conf_open_configure_timestamp=`grep DATE_WHEN_GENERATED: $conf_script_dir/generated-configure.sh  | cut -d" " -f 3`
   1.122 -  conf_custom_configure_timestamp=`grep DATE_WHEN_GENERATED: $conf_custom_script_dir/generated-configure.sh  | cut -d" " -f 3`
   1.123 -  if $TEST $conf_open_configure_timestamp -gt $conf_custom_configure_timestamp; then
   1.124 -    echo "Error: The generated configure file contains changes not present in the custom generated file."
   1.125 -    echo "Please run 'sh autogen.sh' to update the generated files."
   1.126 -    exit 1
   1.127 +  conf_open_configure_timestamp=`grep DATE_WHEN_GENERATED= $conf_script_dir/generated-configure.sh  | cut -d"=" -f 2`
   1.128 +  conf_custom_configure_timestamp=`grep DATE_WHEN_GENERATED= $conf_custom_script_dir/generated-configure.sh  | cut -d"=" -f 2`
   1.129 +  if test $conf_open_configure_timestamp -gt $conf_custom_configure_timestamp; then
   1.130 +    echo "Warning: The generated configure file contains changes not present in the custom generated file."
   1.131 +    run_autogen_or_fail
   1.132    fi
   1.133 -  
   1.134  fi
   1.135  
   1.136  # Autoconf calls the configure script recursively sometimes. 
   1.137  # Don't start logging twice in that case
   1.138 -if $TEST "x$conf_debug_configure" = xtrue; then
   1.139 +if test "x$conf_debug_configure" = xtrue; then
   1.140    conf_debug_configure=recursive
   1.141  fi
   1.142  ###
   1.143  ### Process command-line arguments
   1.144  ###
   1.145 -conf_processed_arguments=
   1.146 +conf_processed_arguments=()
   1.147  conf_openjdk_target=
   1.148 -conf_extra_cflags=
   1.149 -conf_extra_cxxflags=
   1.150  
   1.151  for conf_option
   1.152  do
   1.153 @@ -72,20 +123,14 @@
   1.154    --openjdk-target=*)
   1.155      conf_openjdk_target=`expr "X$conf_option" : '[^=]*=\(.*\)'`
   1.156      continue ;;
   1.157 -  --with-extra-cflags=*)
   1.158 -    conf_extra_cflags=`expr "X$conf_option" : '[^=]*=\(.*\)'`
   1.159 -    continue ;;
   1.160 -  --with-extra-cxxflags=*)
   1.161 -    conf_extra_cxxflags=`expr "X$conf_option" : '[^=]*=\(.*\)'`
   1.162 -    continue ;;
   1.163    --debug-configure)
   1.164 -    if $TEST "x$conf_debug_configure" != xrecursive; then
   1.165 +    if test "x$conf_debug_configure" != xrecursive; then
   1.166        conf_debug_configure=true
   1.167        export conf_debug_configure
   1.168      fi
   1.169      continue ;;
   1.170    *)
   1.171 -    conf_processed_arguments="$conf_processed_arguments $conf_option" ;;
   1.172 +    conf_processed_arguments=("${conf_processed_arguments[@]}" "$conf_option") ;;
   1.173    esac
   1.174  
   1.175    case $conf_option in
   1.176 @@ -95,11 +140,13 @@
   1.177      conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
   1.178    -host | --host | --hos | --ho | -host=* | --host=* | --hos=* | --ho=*)
   1.179      conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
   1.180 +  -help | --help | --hel | --he | -h)
   1.181 +    conf_print_help=true ;;
   1.182    esac
   1.183  done
   1.184  
   1.185 -if $TEST "x$conf_legacy_crosscompile" != "x"; then
   1.186 -  if $TEST "x$conf_openjdk_target" != "x"; then
   1.187 +if test "x$conf_legacy_crosscompile" != "x"; then
   1.188 +  if test "x$conf_openjdk_target" != "x"; then
   1.189      echo "Error: Specifying --openjdk-target together with autoconf"
   1.190      echo "legacy cross-compilation flags is not supported."
   1.191      echo "You specified: --openjdk-target=$conf_openjdk_target and $conf_legacy_crosscompile."
   1.192 @@ -112,20 +159,20 @@
   1.193    fi
   1.194  fi
   1.195  
   1.196 -if $TEST "x$conf_openjdk_target" != "x"; then
   1.197 +if test "x$conf_openjdk_target" != "x"; then
   1.198    conf_build_platform=`sh $conf_script_dir/build-aux/config.guess`
   1.199 -  conf_processed_arguments="--build=$conf_build_platform --host=$conf_openjdk_target --target=$conf_openjdk_target $conf_processed_arguments"
   1.200 +  conf_processed_arguments=("--build=$conf_build_platform" "--host=$conf_openjdk_target" "--target=$conf_openjdk_target" "${conf_processed_arguments[@]}")
   1.201  fi
   1.202  
   1.203  # Make configure exit with error on invalid options as default.
   1.204  # Can be overridden by --disable-option-checking, since we prepend our argument
   1.205  # and later options override earlier.
   1.206 -conf_processed_arguments="--enable-option-checking=fatal $conf_processed_arguments"
   1.207 +conf_processed_arguments=("--enable-option-checking=fatal" "${conf_processed_arguments[@]}")
   1.208  
   1.209  ###
   1.210  ### Call the configure script
   1.211  ###
   1.212 -if $TEST -e $conf_custom_script_dir/generated-configure.sh; then
   1.213 +if test -e $conf_custom_script_dir/generated-configure.sh; then
   1.214    # Custom source configure available; run that instead
   1.215    echo Running custom generated-configure.sh
   1.216    conf_script_to_run=$conf_custom_script_dir/generated-configure.sh
   1.217 @@ -134,17 +181,17 @@
   1.218    conf_script_to_run=$conf_script_dir/generated-configure.sh
   1.219  fi  
   1.220  
   1.221 -if $TEST "x$conf_debug_configure" != x; then
   1.222 +if test "x$conf_debug_configure" != x; then
   1.223    # Turn on shell debug output if requested (initial or recursive)
   1.224    set -x
   1.225  fi
   1.226  
   1.227 -if $TEST "x$conf_debug_configure" = xtrue; then
   1.228 +if test "x$conf_debug_configure" = xtrue; then
   1.229    # Turn on logging, but don't turn on twice when called recursive
   1.230    conf_debug_logfile=./debug-configure.log
   1.231 -  (exec 3>&1 ; (. $conf_script_to_run $conf_processed_arguments --with-extra-cflags="$conf_extra_cflags" --with-extra-cxxflags="$conf_extra_cxxflags" 2>&1 1>&3 ) | tee -a $conf_debug_logfile 1>&2 ; exec 3>&-) | tee -a $conf_debug_logfile
   1.232 +  (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
   1.233  else
   1.234 -  . $conf_script_to_run $conf_processed_arguments --with-extra-cflags="$conf_extra_cflags" --with-extra-cxxflags="$conf_extra_cxxflags"
   1.235 +  ( . $conf_script_to_run "${conf_processed_arguments[@]}" )
   1.236  fi
   1.237  
   1.238  conf_result_code=$?
   1.239 @@ -152,8 +199,28 @@
   1.240  ### Post-processing
   1.241  ###
   1.242  
   1.243 +if test $conf_result_code -eq 0; then
   1.244 +  if test "x$conf_print_help" = xtrue; then
   1.245 +    cat <<EOT
   1.246 +
   1.247 +Additional (non-autoconf) OpenJDK Options:
   1.248 +  --openjdk-target=TARGET cross-compile with TARGET as target platform
   1.249 +                          (i.e. the one you will run the resulting binary on).
   1.250 +                          Equivalent to --host=TARGET --target=TARGET
   1.251 +                          --build=<current platform>
   1.252 +  --debug-configure       Run the configure script with additional debug
   1.253 +                          logging enabled.
   1.254 +
   1.255 +Please be aware that, when cross-compiling, the OpenJDK configure script will
   1.256 +generally use 'target' where autoconf traditionally uses 'host'.
   1.257 +EOT
   1.258 +  fi
   1.259 +else
   1.260 +  echo configure exiting with result code $conf_result_code
   1.261 +fi
   1.262 +
   1.263  # Move the log file to the output root, if this was successfully created
   1.264 -if $TEST -d "$OUTPUT_ROOT"; then
   1.265 +if test -d "$OUTPUT_ROOT"; then
   1.266    mv -f config.log "$OUTPUT_ROOT" 2> /dev/null
   1.267  fi
   1.268  

mercurial