common/autoconf/configure
changeset 14111 2a82ecb35fc7
parent 13697 5262b00bc10c
child 19759 9d0666acc5af
equal deleted inserted replaced
14104:8d9d430b4244 14111:2a82ecb35fc7
     1 #!/bin/sh
     1 #!/bin/bash
       
     2 #
       
     3 # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
       
     4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     5 #
       
     6 # This code is free software; you can redistribute it and/or modify it
       
     7 # under the terms of the GNU General Public License version 2 only, as
       
     8 # published by the Free Software Foundation.
       
     9 #
       
    10 # This code is distributed in the hope that it will be useful, but WITHOUT
       
    11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    12 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    13 # version 2 for more details (a copy is included in the LICENSE file that
       
    14 # accompanied this code).
       
    15 #
       
    16 # You should have received a copy of the GNU General Public License version
       
    17 # 2 along with this work; if not, write to the Free Software Foundation,
       
    18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    19 #
       
    20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    21 # or visit www.oracle.com if you need additional information or have any
       
    22 # questions.
       
    23 #
       
    24 
       
    25 if test "x$BASH_VERSION" = x; then
       
    26   echo This script needs bash to run.
       
    27   echo It is recommended to use the configure script in the source tree root instead.
       
    28   exit 1
       
    29 fi
     2 
    30 
     3 CONFIGURE_COMMAND_LINE="$@"
    31 CONFIGURE_COMMAND_LINE="$@"
     4 conf_script_dir=`dirname $0`
    32 conf_script_dir=`dirname $0`
     5 
    33 
     6 if [ "$CUSTOM_CONFIG_DIR" = "" ]; then
    34 if [ "$CUSTOM_CONFIG_DIR" = "" ]; then
    11 
    39 
    12 ###
    40 ###
    13 ### Test that the generated configure is up-to-date
    41 ### Test that the generated configure is up-to-date
    14 ###
    42 ###
    15 
    43 
    16 # On Solaris /bin/sh doesn't support test -nt but /usr/bin/test does.
    44 run_autogen_or_fail() {
    17 TEST=`which test`
    45   if test "x`which autoconf 2> /dev/null`" = x; then
    18 
    46     echo "Cannot locate autoconf, unable to correct situation."
    19 print_error_not_up_to_date() {
    47     echo "Please install autoconf and run 'bash autogen.sh' to update the generated files."
    20   echo "Error: The configure source files is newer than the generated files."
    48     echo "Error: Cannot continue" 1>&2
    21   echo "Please run 'sh autogen.sh' to update the generated files."
    49     exit 1
    22   echo "Note that this test might trigger incorrectly sometimes due to hg timestamps".
    50   else
       
    51     echo "Running autogen.sh to correct the situation"
       
    52     bash $conf_script_dir/autogen.sh
       
    53   fi
    23 }
    54 }
    24 
    55 
    25 # NOTE: This test can occasionally go wrong due to the way mercurial handles
    56 check_autoconf_timestamps() {
    26 # timestamps. It it supposed to aid during development of build-infra, but should
    57   for file in $conf_script_dir/configure.ac $conf_script_dir/*.m4 ; do
    27 # go away before making this the default build system.
    58     if test $file -nt $conf_script_dir/generated-configure.sh; then
    28 for file in configure.ac *.m4 ; do
    59       echo "Warning: The configure source files is newer than the generated files."
    29   if $TEST $file -nt generated-configure.sh; then
    60       run_autogen_or_fail
    30     print_error_not_up_to_date
       
    31     exit 1
       
    32   fi
       
    33 done
       
    34 
       
    35 if $TEST -e $conf_custom_script_dir/generated-configure.sh; then
       
    36   # If custom source configure is available, make sure it is up-to-date as well.
       
    37   for file in configure.ac *.m4 $conf_custom_script_dir/*.m4; do
       
    38     if $TEST $file -nt $conf_custom_script_dir/generated-configure.sh; then
       
    39       print_error_not_up_to_date
       
    40       exit 1
       
    41     fi
    61     fi
    42   done
    62   done
    43 
    63 
       
    64   if test -e $conf_custom_script_dir/generated-configure.sh; then
       
    65     # If custom source configure is available, make sure it is up-to-date as well.
       
    66     for file in $conf_script_dir/configure.ac $conf_script_dir/*.m4 $conf_custom_script_dir/*.m4; do
       
    67       if test $file -nt $conf_custom_script_dir/generated-configure.sh; then
       
    68         echo "Warning: The configure source files is newer than the custom generated files."
       
    69         run_autogen_or_fail
       
    70       fi
       
    71     done
       
    72   fi
       
    73 }
       
    74 
       
    75 check_hg_updates() {
       
    76   if test "x`which hg 2> /dev/null`" != x; then
       
    77     conf_updated_autoconf_files=`cd $conf_script_dir && hg status -mard 2> /dev/null | grep autoconf`
       
    78     if test "x$conf_updated_autoconf_files" != x; then
       
    79       echo "Configure source code has been updated, checking time stamps"
       
    80       check_autoconf_timestamps
       
    81     fi
       
    82 
       
    83     if test -e $conf_custom_script_dir; then
       
    84       # If custom source configure is available, make sure it is up-to-date as well.
       
    85       conf_custom_updated_autoconf_files=`cd $conf_custom_script_dir && hg status -mard 2> /dev/null | grep autoconf`
       
    86       if test "x$conf_custom_updated_autoconf_files" != x; then
       
    87         echo "Configure custom source code has been updated, checking time stamps"
       
    88         check_autoconf_timestamps
       
    89       fi
       
    90     fi
       
    91     
       
    92   fi
       
    93 }
       
    94 
       
    95 # Check for local changes
       
    96 check_hg_updates
       
    97 
       
    98 if test -e $conf_custom_script_dir/generated-configure.sh; then
    44   # Test if open configure is newer than custom configure, if so, custom needs to
    99   # Test if open configure is newer than custom configure, if so, custom needs to
    45   # be regenerated. This test is required to ensure consistency with custom source.
   100   # be regenerated. This test is required to ensure consistency with custom source.
    46   conf_open_configure_timestamp=`grep DATE_WHEN_GENERATED: $conf_script_dir/generated-configure.sh  | cut -d" " -f 3`
   101   conf_open_configure_timestamp=`grep DATE_WHEN_GENERATED= $conf_script_dir/generated-configure.sh  | cut -d"=" -f 2`
    47   conf_custom_configure_timestamp=`grep DATE_WHEN_GENERATED: $conf_custom_script_dir/generated-configure.sh  | cut -d" " -f 3`
   102   conf_custom_configure_timestamp=`grep DATE_WHEN_GENERATED= $conf_custom_script_dir/generated-configure.sh  | cut -d"=" -f 2`
    48   if $TEST $conf_open_configure_timestamp -gt $conf_custom_configure_timestamp; then
   103   if test $conf_open_configure_timestamp -gt $conf_custom_configure_timestamp; then
    49     echo "Error: The generated configure file contains changes not present in the custom generated file."
   104     echo "Warning: The generated configure file contains changes not present in the custom generated file."
    50     echo "Please run 'sh autogen.sh' to update the generated files."
   105     run_autogen_or_fail
    51     exit 1
   106   fi
    52   fi
       
    53   
       
    54 fi
   107 fi
    55 
   108 
    56 # Autoconf calls the configure script recursively sometimes. 
   109 # Autoconf calls the configure script recursively sometimes. 
    57 # Don't start logging twice in that case
   110 # Don't start logging twice in that case
    58 if $TEST "x$conf_debug_configure" = xtrue; then
   111 if test "x$conf_debug_configure" = xtrue; then
    59   conf_debug_configure=recursive
   112   conf_debug_configure=recursive
    60 fi
   113 fi
    61 ###
   114 ###
    62 ### Process command-line arguments
   115 ### Process command-line arguments
    63 ###
   116 ###
    64 conf_processed_arguments=
   117 conf_processed_arguments=()
    65 conf_openjdk_target=
   118 conf_openjdk_target=
    66 conf_extra_cflags=
       
    67 conf_extra_cxxflags=
       
    68 
   119 
    69 for conf_option
   120 for conf_option
    70 do
   121 do
    71   case $conf_option in
   122   case $conf_option in
    72   --openjdk-target=*)
   123   --openjdk-target=*)
    73     conf_openjdk_target=`expr "X$conf_option" : '[^=]*=\(.*\)'`
   124     conf_openjdk_target=`expr "X$conf_option" : '[^=]*=\(.*\)'`
    74     continue ;;
   125     continue ;;
    75   --with-extra-cflags=*)
       
    76     conf_extra_cflags=`expr "X$conf_option" : '[^=]*=\(.*\)'`
       
    77     continue ;;
       
    78   --with-extra-cxxflags=*)
       
    79     conf_extra_cxxflags=`expr "X$conf_option" : '[^=]*=\(.*\)'`
       
    80     continue ;;
       
    81   --debug-configure)
   126   --debug-configure)
    82     if $TEST "x$conf_debug_configure" != xrecursive; then
   127     if test "x$conf_debug_configure" != xrecursive; then
    83       conf_debug_configure=true
   128       conf_debug_configure=true
    84       export conf_debug_configure
   129       export conf_debug_configure
    85     fi
   130     fi
    86     continue ;;
   131     continue ;;
    87   *)
   132   *)
    88     conf_processed_arguments="$conf_processed_arguments $conf_option" ;;
   133     conf_processed_arguments=("${conf_processed_arguments[@]}" "$conf_option") ;;
    89   esac
   134   esac
    90 
   135 
    91   case $conf_option in
   136   case $conf_option in
    92   -build | --build | --buil | --bui | --bu |-build=* | --build=* | --buil=* | --bui=* | --bu=*)
   137   -build | --build | --buil | --bui | --bu |-build=* | --build=* | --buil=* | --bui=* | --bu=*)
    93     conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
   138     conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
    94   -target | --target | --targe | --targ | --tar | --ta | --t | -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
   139   -target | --target | --targe | --targ | --tar | --ta | --t | -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
    95     conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
   140     conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
    96   -host | --host | --hos | --ho | -host=* | --host=* | --hos=* | --ho=*)
   141   -host | --host | --hos | --ho | -host=* | --host=* | --hos=* | --ho=*)
    97     conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
   142     conf_legacy_crosscompile="$conf_legacy_crosscompile $conf_option" ;;
       
   143   -help | --help | --hel | --he | -h)
       
   144     conf_print_help=true ;;
    98   esac
   145   esac
    99 done
   146 done
   100 
   147 
   101 if $TEST "x$conf_legacy_crosscompile" != "x"; then
   148 if test "x$conf_legacy_crosscompile" != "x"; then
   102   if $TEST "x$conf_openjdk_target" != "x"; then
   149   if test "x$conf_openjdk_target" != "x"; then
   103     echo "Error: Specifying --openjdk-target together with autoconf"
   150     echo "Error: Specifying --openjdk-target together with autoconf"
   104     echo "legacy cross-compilation flags is not supported."
   151     echo "legacy cross-compilation flags is not supported."
   105     echo "You specified: --openjdk-target=$conf_openjdk_target and $conf_legacy_crosscompile."
   152     echo "You specified: --openjdk-target=$conf_openjdk_target and $conf_legacy_crosscompile."
   106     echo "The recommended use is just --openjdk-target."
   153     echo "The recommended use is just --openjdk-target."
   107     exit 1
   154     exit 1
   110     echo "It is recommended that you use --openjdk-target instead."
   157     echo "It is recommended that you use --openjdk-target instead."
   111     echo ""
   158     echo ""
   112   fi
   159   fi
   113 fi
   160 fi
   114 
   161 
   115 if $TEST "x$conf_openjdk_target" != "x"; then
   162 if test "x$conf_openjdk_target" != "x"; then
   116   conf_build_platform=`sh $conf_script_dir/build-aux/config.guess`
   163   conf_build_platform=`sh $conf_script_dir/build-aux/config.guess`
   117   conf_processed_arguments="--build=$conf_build_platform --host=$conf_openjdk_target --target=$conf_openjdk_target $conf_processed_arguments"
   164   conf_processed_arguments=("--build=$conf_build_platform" "--host=$conf_openjdk_target" "--target=$conf_openjdk_target" "${conf_processed_arguments[@]}")
   118 fi
   165 fi
   119 
   166 
   120 # Make configure exit with error on invalid options as default.
   167 # Make configure exit with error on invalid options as default.
   121 # Can be overridden by --disable-option-checking, since we prepend our argument
   168 # Can be overridden by --disable-option-checking, since we prepend our argument
   122 # and later options override earlier.
   169 # and later options override earlier.
   123 conf_processed_arguments="--enable-option-checking=fatal $conf_processed_arguments"
   170 conf_processed_arguments=("--enable-option-checking=fatal" "${conf_processed_arguments[@]}")
   124 
   171 
   125 ###
   172 ###
   126 ### Call the configure script
   173 ### Call the configure script
   127 ###
   174 ###
   128 if $TEST -e $conf_custom_script_dir/generated-configure.sh; then
   175 if test -e $conf_custom_script_dir/generated-configure.sh; then
   129   # Custom source configure available; run that instead
   176   # Custom source configure available; run that instead
   130   echo Running custom generated-configure.sh
   177   echo Running custom generated-configure.sh
   131   conf_script_to_run=$conf_custom_script_dir/generated-configure.sh
   178   conf_script_to_run=$conf_custom_script_dir/generated-configure.sh
   132 else
   179 else
   133   echo Running generated-configure.sh
   180   echo Running generated-configure.sh
   134   conf_script_to_run=$conf_script_dir/generated-configure.sh
   181   conf_script_to_run=$conf_script_dir/generated-configure.sh
   135 fi  
   182 fi  
   136 
   183 
   137 if $TEST "x$conf_debug_configure" != x; then
   184 if test "x$conf_debug_configure" != x; then
   138   # Turn on shell debug output if requested (initial or recursive)
   185   # Turn on shell debug output if requested (initial or recursive)
   139   set -x
   186   set -x
   140 fi
   187 fi
   141 
   188 
   142 if $TEST "x$conf_debug_configure" = xtrue; then
   189 if test "x$conf_debug_configure" = xtrue; then
   143   # Turn on logging, but don't turn on twice when called recursive
   190   # Turn on logging, but don't turn on twice when called recursive
   144   conf_debug_logfile=./debug-configure.log
   191   conf_debug_logfile=./debug-configure.log
   145   (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
   192   (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
   146 else
   193 else
   147   . $conf_script_to_run $conf_processed_arguments --with-extra-cflags="$conf_extra_cflags" --with-extra-cxxflags="$conf_extra_cxxflags"
   194   ( . $conf_script_to_run "${conf_processed_arguments[@]}" )
   148 fi
   195 fi
   149 
   196 
   150 conf_result_code=$?
   197 conf_result_code=$?
   151 ###
   198 ###
   152 ### Post-processing
   199 ### Post-processing
   153 ###
   200 ###
   154 
   201 
       
   202 if test $conf_result_code -eq 0; then
       
   203   if test "x$conf_print_help" = xtrue; then
       
   204     cat <<EOT
       
   205 
       
   206 Additional (non-autoconf) OpenJDK Options:
       
   207   --openjdk-target=TARGET cross-compile with TARGET as target platform
       
   208                           (i.e. the one you will run the resulting binary on).
       
   209                           Equivalent to --host=TARGET --target=TARGET
       
   210                           --build=<current platform>
       
   211   --debug-configure       Run the configure script with additional debug
       
   212                           logging enabled.
       
   213 
       
   214 Please be aware that, when cross-compiling, the OpenJDK configure script will
       
   215 generally use 'target' where autoconf traditionally uses 'host'.
       
   216 EOT
       
   217   fi
       
   218 else
       
   219   echo configure exiting with result code $conf_result_code
       
   220 fi
       
   221 
   155 # Move the log file to the output root, if this was successfully created
   222 # Move the log file to the output root, if this was successfully created
   156 if $TEST -d "$OUTPUT_ROOT"; then
   223 if test -d "$OUTPUT_ROOT"; then
   157   mv -f config.log "$OUTPUT_ROOT" 2> /dev/null
   224   mv -f config.log "$OUTPUT_ROOT" 2> /dev/null
   158 fi
   225 fi
   159 
   226 
   160 exit $conf_result_code
   227 exit $conf_result_code