configure 8.8 KB
Newer Older
O
ohair 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#!/bin/bash
#
# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

if test "x$BASH_VERSION" = x; then
  echo This script needs bash to run.
  echo It is recommended to use the configure script in the source tree root instead.
  exit 1
fi
30

31
# Force autoconf to use bash. This also means we must disable autoconf re-exec.
32
export CONFIG_SHELL=$BASH
33
export _as_can_reexec=no
34

35 36
CONFIGURE_COMMAND_LINE="$@"
conf_script_dir=`dirname $0`
37 38 39 40 41 42

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
43

44 45 46
###
### Test that the generated configure is up-to-date
###
47

O
ohair 已提交
48 49 50 51 52
run_autogen_or_fail() {
  if test "x`which autoconf 2> /dev/null`" = x; then
    echo "Cannot locate autoconf, unable to correct situation."
    echo "Please install autoconf and run 'bash autogen.sh' to update the generated files."
    echo "Error: Cannot continue" 1>&2
53
    exit 1
O
ohair 已提交
54 55 56
  else
    echo "Running autogen.sh to correct the situation"
    bash $conf_script_dir/autogen.sh
57
  fi
O
ohair 已提交
58
}
59

O
ohair 已提交
60 61 62 63 64
check_autoconf_timestamps() {
  for file in $conf_script_dir/configure.ac $conf_script_dir/*.m4 ; do
    if test $file -nt $conf_script_dir/generated-configure.sh; then
      echo "Warning: The configure source files is newer than the generated files."
      run_autogen_or_fail
65
    fi
66 67
  done

O
ohair 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
  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 $conf_script_dir/configure.ac $conf_script_dir/*.m4 $conf_custom_script_dir/*.m4; do
      if test $file -nt $conf_custom_script_dir/generated-configure.sh; then
        echo "Warning: The configure source files is newer than the custom generated files."
        run_autogen_or_fail
      fi
    done
  fi
}

check_hg_updates() {
  if test "x`which hg 2> /dev/null`" != x; then
    conf_updated_autoconf_files=`cd $conf_script_dir && hg status -mard 2> /dev/null | grep autoconf`
    if test "x$conf_updated_autoconf_files" != x; then
      echo "Configure source code has been updated, checking time stamps"
      check_autoconf_timestamps
    fi

    if test -e $conf_custom_script_dir; then
      # If custom source configure is available, make sure it is up-to-date as well.
      conf_custom_updated_autoconf_files=`cd $conf_custom_script_dir && hg status -mard 2> /dev/null | grep autoconf`
      if test "x$conf_custom_updated_autoconf_files" != x; then
        echo "Configure custom source code has been updated, checking time stamps"
        check_autoconf_timestamps
      fi
    fi
  fi
}

# Check for local changes
check_hg_updates

if test -e $conf_custom_script_dir/generated-configure.sh; then
102 103
  # 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.
O
ohair 已提交
104 105 106 107 108
  conf_open_configure_timestamp=`grep DATE_WHEN_GENERATED= $conf_script_dir/generated-configure.sh  | cut -d"=" -f 2`
  conf_custom_configure_timestamp=`grep DATE_WHEN_GENERATED= $conf_custom_script_dir/generated-configure.sh  | cut -d"=" -f 2`
  if test $conf_open_configure_timestamp -gt $conf_custom_configure_timestamp; then
    echo "Warning: The generated configure file contains changes not present in the custom generated file."
    run_autogen_or_fail
109 110 111
  fi
fi

112
# Autoconf calls the configure script recursively sometimes.
113
# Don't start logging twice in that case
O
ohair 已提交
114
if test "x$conf_debug_configure" = xtrue; then
115 116
  conf_debug_configure=recursive
fi
117 118 119
###
### Process command-line arguments
###
O
ohair 已提交
120
conf_processed_arguments=()
121
conf_openjdk_target=
122

123
for conf_option
124
do
125
  case $conf_option in
126 127
    --openjdk-target=*)
      conf_openjdk_target=`expr "X$conf_option" : '[^=]*=\(.*\)'`
128
      ;;
129 130 131 132 133
    --debug-configure)
      if test "x$conf_debug_configure" != xrecursive; then
        conf_debug_configure=true
        export conf_debug_configure
      fi
134 135 136 137 138 139 140 141
      ;;
    [^-]*=*)
      # Add name of variable to CONFIGURE_OVERRIDDEN_VARIABLES list inside !...!.
      conf_env_var=`expr "x$conf_option" : 'x\([^=]*\)='`
      CONFIGURE_OVERRIDDEN_VARIABLES="$CONFIGURE_OVERRIDDEN_VARIABLES!$conf_env_var!"
      # ... and then process argument as usual
      conf_processed_arguments=("${conf_processed_arguments[@]}" "$conf_option")
      ;;
142
    *)
143 144
      conf_processed_arguments=("${conf_processed_arguments[@]}" "$conf_option")
      ;;
145 146
  esac

147
  case $conf_option in
148 149 150 151 152 153 154 155
    -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" ;;
    -help | --help | --hel | --he | -h)
      conf_print_help=true ;;
156 157 158
  esac
done

O
ohair 已提交
159 160
if test "x$conf_legacy_crosscompile" != "x"; then
  if test "x$conf_openjdk_target" != "x"; then
161 162 163 164 165
    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
166
  else
167 168 169
    echo "Warning: You are using legacy autoconf cross-compilation flags."
    echo "It is recommended that you use --openjdk-target instead."
    echo ""
170 171 172
  fi
fi

O
ohair 已提交
173
if test "x$conf_openjdk_target" != "x"; then
174
  conf_build_platform=`sh $conf_script_dir/build-aux/config.guess`
O
ohair 已提交
175
  conf_processed_arguments=("--build=$conf_build_platform" "--host=$conf_openjdk_target" "--target=$conf_openjdk_target" "${conf_processed_arguments[@]}")
176 177
fi

178 179 180
# 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.
O
ohair 已提交
181
conf_processed_arguments=("--enable-option-checking=fatal" "${conf_processed_arguments[@]}")
182

183 184 185
###
### Call the configure script
###
O
ohair 已提交
186
if test -e $conf_custom_script_dir/generated-configure.sh; then
187 188 189 190 191 192
  # 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
193
fi
194

O
ohair 已提交
195
if test "x$conf_debug_configure" != x; then
196 197 198 199
  # Turn on shell debug output if requested (initial or recursive)
  set -x
fi

O
ohair 已提交
200
if test "x$conf_debug_configure" = xtrue; then
201 202
  # Turn on logging, but don't turn on twice when called recursive
  conf_debug_logfile=./debug-configure.log
O
ohair 已提交
203
  (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
204
else
O
ohair 已提交
205
  ( . $conf_script_to_run "${conf_processed_arguments[@]}" )
206 207
fi

208
conf_result_code=$?
209 210 211
###
### Post-processing
###
212

O
ohair 已提交
213 214 215 216 217 218 219 220 221 222 223 224 225 226
if test $conf_result_code -eq 0; then
  if test "x$conf_print_help" = xtrue; then
    cat <<EOT

Additional (non-autoconf) OpenJDK Options:
  --openjdk-target=TARGET cross-compile with TARGET as target platform
                          (i.e. the one you will run the resulting binary on).
                          Equivalent to --host=TARGET --target=TARGET
                          --build=<current platform>
  --debug-configure       Run the configure script with additional debug
                          logging enabled.

Please be aware that, when cross-compiling, the OpenJDK configure script will
generally use 'target' where autoconf traditionally uses 'host'.
227 228 229

Also note that variables must be passed on the command line. Variables in the
environment will generally be ignored, unlike traditional autoconf scripts.
O
ohair 已提交
230 231 232 233 234 235
EOT
  fi
else
  echo configure exiting with result code $conf_result_code
fi

236
exit $conf_result_code