common/autoconf/configure
author ohair
Tue, 18 Sep 2012 11:29:16 -0700
changeset 13697 5262b00bc10c
parent 13132 bd88bb8dd3af
child 14111 2a82ecb35fc7
permissions -rw-r--r--
7197849: Update new build-infra makefiles Reviewed-by: ihse, erikj, ohrstrom, tbell

#!/bin/sh

CONFIGURE_COMMAND_LINE="$@"
conf_script_dir=`dirname $0`

if [ "$CUSTOM_CONFIG_DIR" = "" ]; then
  conf_custom_script_dir="$conf_script_dir/../../jdk/make/closed/autoconf"
else
  conf_custom_script_dir=$CUSTOM_CONFIG_DIR
fi

###
### Test that the generated configure is up-to-date
###

# On Solaris /bin/sh doesn't support test -nt but /usr/bin/test does.
TEST=`which test`

print_error_not_up_to_date() {
  echo "Error: The configure source files is newer than the generated files."
  echo "Please run 'sh autogen.sh' to update the generated files."
  echo "Note that this test might trigger incorrectly sometimes due to hg timestamps".
}

# NOTE: This test can occasionally go wrong due to the way mercurial handles
# timestamps. It it supposed to aid during development of build-infra, but should
# go away before making this the default build system.
for file in configure.ac *.m4 ; do
  if $TEST $file -nt generated-configure.sh; then
    print_error_not_up_to_date
    exit 1
  fi
done

if $TEST -e $conf_custom_script_dir/generated-configure.sh; then
  # If custom source configure is available, make sure it is up-to-date as well.
  for file in configure.ac *.m4 $conf_custom_script_dir/*.m4; do
    if $TEST $file -nt $conf_custom_script_dir/generated-configure.sh; then
      print_error_not_up_to_date
      exit 1
    fi
  done

  # Test if open configure is newer than custom configure, if so, custom needs to
  # be regenerated. This test is required to ensure consistency with custom source.
  conf_open_configure_timestamp=`grep DATE_WHEN_GENERATED: $conf_script_dir/generated-configure.sh  | cut -d" " -f 3`
  conf_custom_configure_timestamp=`grep DATE_WHEN_GENERATED: $conf_custom_script_dir/generated-configure.sh  | cut -d" " -f 3`
  if $TEST $conf_open_configure_timestamp -gt $conf_custom_configure_timestamp; then
    echo "Error: The generated configure file contains changes not present in the custom generated file."
    echo "Please run 'sh autogen.sh' to update the generated files."
    exit 1
  fi
  
fi

# Autoconf calls the configure script recursively sometimes. 
# Don't start logging twice in that case
if $TEST "x$conf_debug_configure" = xtrue; then
  conf_debug_configure=recursive
fi
###
### Process command-line arguments
###
conf_processed_arguments=
conf_openjdk_target=
conf_extra_cflags=
conf_extra_cxxflags=

for conf_option
do
  case $conf_option in
  --openjdk-target=*)
    conf_openjdk_target=`expr "X$conf_option" : '[^=]*=\(.*\)'`
    continue ;;
  --with-extra-cflags=*)
    conf_extra_cflags=`expr "X$conf_option" : '[^=]*=\(.*\)'`
    continue ;;
  --with-extra-cxxflags=*)
    conf_extra_cxxflags=`expr "X$conf_option" : '[^=]*=\(.*\)'`
    continue ;;
  --debug-configure)
    if $TEST "x$conf_debug_configure" != xrecursive; then
      conf_debug_configure=true
      export conf_debug_configure
    fi
    continue ;;
  *)
    conf_processed_arguments="$conf_processed_arguments $conf_option" ;;
  esac

  case $conf_option in
  -build | --build | --buil | --bui | --bu |-build=* | --build=* | --buil=* | --bui=* | --bu=*)
    conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
  -target | --target | --targe | --targ | --tar | --ta | --t | -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
    conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
  -host | --host | --hos | --ho | -host=* | --host=* | --hos=* | --ho=*)
    conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
  esac
done

if $TEST "x$conf_legacy_crosscompile" != "x"; then
  if $TEST "x$conf_openjdk_target" != "x"; then
    echo "Error: Specifying --openjdk-target together with autoconf"
    echo "legacy cross-compilation flags is not supported."
    echo "You specified: --openjdk-target=$conf_openjdk_target and $conf_legacy_crosscompile."
    echo "The recommended use is just --openjdk-target."
    exit 1
  else
    echo "Warning: You are using legacy autoconf cross-compilation flags."
    echo "It is recommended that you use --openjdk-target instead."
    echo ""
  fi
fi

if $TEST "x$conf_openjdk_target" != "x"; then
  conf_build_platform=`sh $conf_script_dir/build-aux/config.guess`
  conf_processed_arguments="--build=$conf_build_platform --host=$conf_openjdk_target --target=$conf_openjdk_target $conf_processed_arguments"
fi

# Make configure exit with error on invalid options as default.
# Can be overridden by --disable-option-checking, since we prepend our argument
# and later options override earlier.
conf_processed_arguments="--enable-option-checking=fatal $conf_processed_arguments"

###
### Call the configure script
###
if $TEST -e $conf_custom_script_dir/generated-configure.sh; then
  # Custom source configure available; run that instead
  echo Running custom generated-configure.sh
  conf_script_to_run=$conf_custom_script_dir/generated-configure.sh
else
  echo Running generated-configure.sh
  conf_script_to_run=$conf_script_dir/generated-configure.sh
fi  

if $TEST "x$conf_debug_configure" != x; then
  # Turn on shell debug output if requested (initial or recursive)
  set -x
fi

if $TEST "x$conf_debug_configure" = xtrue; then
  # Turn on logging, but don't turn on twice when called recursive
  conf_debug_logfile=./debug-configure.log
  (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
else
  . $conf_script_to_run $conf_processed_arguments --with-extra-cflags="$conf_extra_cflags" --with-extra-cxxflags="$conf_extra_cxxflags"
fi

conf_result_code=$?
###
### Post-processing
###

# Move the log file to the output root, if this was successfully created
if $TEST -d "$OUTPUT_ROOT"; then
  mv -f config.log "$OUTPUT_ROOT" 2> /dev/null
fi

exit $conf_result_code