configure
changeset 1140 6bdb31785d6c
parent 1132 c232833120c1
child 1151 06893705782f
     1.1 --- a/configure	Wed Jan 07 12:11:37 2009 +0000
     1.2 +++ b/configure	Sun Jan 18 15:08:28 2009 +0000
     1.3 @@ -11,7 +11,8 @@
     1.4  #  - others obvious... :-/
     1.5  #
     1.6  # Format of a pattern to check for, one per line:
     1.7 -#   pattern := tool_test  OR  pattern || tool_test
     1.8 +#   pattern := var_name : tool_pattern  OR  tool_pattern
     1.9 +#   tool_pattern := tool_test  OR  tool_pattern || tool_test
    1.10  #   tool_test := tool=regexp OR tool
    1.11  #   tool := basename of the tool  OR  absolute pathname to the tool
    1.12  #   regexp := valid grep(1) extended regular expression, $( tool --version)
    1.13 @@ -22,24 +23,29 @@
    1.14  # would parse 'foo || bar || buz' ).
    1.15  #
    1.16  # Examples:
    1.17 -#    /bin/bash=^GNU bash, version 3\.
    1.18 -#       will ensure that /bin/bash exists, and that $( /bin/bash --version )
    1.19 +#    bash:bash=^GNU bash, version 3\.
    1.20 +#     - if ${bash} is set and non-null, does nothing
    1.21 +#     - else ensures that bash exists in the PATH, and that
    1.22 +#         "$( "$( which bash )" --version |head -n 1 )"
    1.23  #       matches the regexp '^GNU bash, version 3\.'
    1.24 +#       - if so, then sets bash="$( which bash )"
    1.25  #    autoconf=(GNU Autoconf) || autoconf2.50
    1.26 -#       will ensure that:
    1.27 -#         - 'autoconf' is to be found in the PATH, and that $( autoconf --version )
    1.28 +#     - does not look at an existing variable
    1.29 +#     - ensures that:
    1.30 +#         - 'autoconf' is to be found in the PATH, and that $( autoconf --version |head -n 1 )
    1.31  #           matches the regexp '(GNU Autoconf)' (which btw is the signature of
    1.32  #           autoconf >= 2.50),
    1.33  #       OR that:
    1.34  #         - 'autoconf2.50' is to be found in the PATH
    1.35  #
    1.36  TOOLS_TO_CHECK='
    1.37 -/bin/bash=^GNU bash, version 3\.
    1.38 +bash:bash=^GNU bash, version 3\.
    1.39  cut
    1.40  xargs
    1.41 -make=^GNU Make
    1.42 +install:install=GNU coreutils
    1.43 +make:make=^GNU Make
    1.44  gcc
    1.45 -gawk=^GNU Awk
    1.46 +awk:awk=^GNU Awk || gawk=^GNU Awk
    1.47  bison
    1.48  flex
    1.49  makeinfo
    1.50 @@ -61,7 +67,6 @@
    1.51  LOCAL_set=
    1.52  
    1.53  do_quit=
    1.54 -CONTRIB_list=
    1.55  
    1.56  # Simply print the error message, and exit. Obvious, he?
    1.57  do_error() {
    1.58 @@ -73,8 +78,19 @@
    1.59  # Usage: has_or_abort test_pattern (see top of file, TOOLS_TO_CHECK, for
    1.60  #                                   complete pattern format)
    1.61  has_or_abort() {
    1.62 +    local save_IFS
    1.63 +    local var_name
    1.64 +    local var_value
    1.65 +    local tool_pattern
    1.66 +    local field
    1.67 +
    1.68 +    var_name="$( echo "${1}" |"${sed}" -r -e 's/^((([^=:]+):.+|[^:=]+)=.+|[^:=]+)$/\3/;' )"
    1.69 +    field="${var_name:+2}"
    1.70 +    field="${field:-1}"
    1.71 +    tool_pattern="$( echo "${1}" |cut -d : -f ${field}- |"${sed}" -r -e 's/ *\|\| */\n/g;' )"
    1.72 +
    1.73      save_IFS="${IFS}"
    1.74 -    tool_pattern="$( echo "${1}" |"${sed}" -r -e 's/ *\|\| */\n/g;' )"
    1.75 +    # Set IFS to \n only
    1.76      IFS='
    1.77  '
    1.78      for item in ${tool_pattern}; do
    1.79 @@ -87,7 +103,15 @@
    1.80                  regexp=
    1.81                  ;;
    1.82          esac
    1.83 +
    1.84          printf "Checking for '${tool}'... "
    1.85 +        if [ -n "${var_name}" ]; then
    1.86 +            eval var_value='"${'"${var_name}"'}"'
    1.87 +            if [ -n "${var_value}" ]; then
    1.88 +                echo "${var_value} (cached)"
    1.89 +                return 0
    1.90 +            fi
    1.91 +        fi
    1.92          where=$( which "${tool}" 2>/dev/null )
    1.93          if [ -z "${where}" ]; then
    1.94              echo "not found"
    1.95 @@ -102,9 +126,8 @@
    1.96                  continue
    1.97              fi
    1.98          fi
    1.99 -        echo "${where}"
   1.100          break
   1.101 -    done;
   1.102 +    done
   1.103      if [ -z "${where}" ]; then
   1.104          for item in ${tool_pattern}; do
   1.105              case "${item}" in
   1.106 @@ -122,6 +145,11 @@
   1.107          echo "or the version you have is tool old."
   1.108          # FORCE can be set in the environment
   1.109          [ -z "${FORCE}" ] && do_error "Bailing out..."
   1.110 +    else
   1.111 +        echo "${where}"
   1.112 +        if [ -n "${var_name}" ]; then
   1.113 +            eval ${var_name}='"'"${where}"'"'
   1.114 +        fi
   1.115      fi
   1.116      IFS="${save_IFS}"
   1.117      return 0
   1.118 @@ -134,7 +162,7 @@
   1.119  get_optval(){
   1.120      case "$1" in
   1.121          --*=?*)
   1.122 -            echo "${1}" |cut -d '=' -f 2-
   1.123 +            echo "${1#*=}"
   1.124              return 0
   1.125              ;;
   1.126          *)
   1.127 @@ -165,38 +193,15 @@
   1.128      MANDIR_set=1
   1.129      MANDIR="$( get_optval "$1" "$2" )"
   1.130  }
   1.131 -
   1.132 -# The set_contrib function is different in that it will work like the others,
   1.133 -# except in two cases:
   1.134 -# If all => replaces all with the list of all available contribs
   1.135 -# If list => just echoes the list of all available contribs, and instructs
   1.136 -# caller to quit immediately by setting do_quit to non null.
   1.137 -# (can't use the return code, see above).
   1.138 -set_contrib() {
   1.139 -    opt_val="$( get_optval "$1" "$2" )"
   1.140 -    ret=$?
   1.141 -    case "${opt_val}" in
   1.142 -        all)
   1.143 -            CONTRIB_list="$( LC_ALL=C ls -1 contrib/*.patch.lzma                \
   1.144 -                                      |xargs -I {} basename {} .patch.lzma      \
   1.145 -                                      |"${sed}" -r -e ':a; /$/N; s/\n/,/; ta;'  \
   1.146 -                           )"
   1.147 -            ;;
   1.148 -        list)
   1.149 -            do_quit=1
   1.150 -            echo "Available contributions:"
   1.151 -            LC_ALL=C ls -1 contrib/*.patch.lzma             \
   1.152 -                     |xargs -I {} basename {} .patch.lzma   \
   1.153 -                     |"${sed}" -r -e 's/^/  /;'
   1.154 -            ;;
   1.155 -        *)  CONTRIB_list="${CONTRIB_list},${opt_val}";;
   1.156 -    esac
   1.157 -    return $ret
   1.158 +set_tool() {
   1.159 +    local var_name="${1%%=*}"
   1.160 +    var_name="${var_name#--with-}"
   1.161 +    eval ${var_name}="\$( get_optval "$1" "$2" )"
   1.162  }
   1.163  
   1.164  do_help() {
   1.165      cat <<__EOF__
   1.166 -\`configure' configures crosstool-NG ${VERSION} to adapt to many kind of systems.
   1.167 +\`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
   1.168  
   1.169  USAGE: ./configure [OPTION]...
   1.170  
   1.171 @@ -223,58 +228,29 @@
   1.172    --mandir=DIR            man documentation [PREFIX/share/man]
   1.173  
   1.174  Optional Features:
   1.175 -  --with-contrib=XXX      Include externally contributed features found in the
   1.176 -                          contrib/ sub-directory. Set to a comma-separated list
   1.177 -                          of features. Use 'all' to use all contributions, and
   1.178 -                          'list' to see which are available.
   1.179 +  --with-install=PATH     Specify the full PATH to GNU install
   1.180 +  --with-make=PATH        Specify the full PATH to GNU make
   1.181 +  --with-grep=PATH        Specify the full PATH to GNU grep
   1.182 +  --with-sed=PATH         Specify the full PATH to GNU sed
   1.183 +  --with-awk=PATH         Specify the full PATH to GNU awk
   1.184 +  --with-bash=PATH        Specify the full PATH to bash >= 3.0
   1.185  __EOF__
   1.186  }
   1.187  
   1.188  #---------------------------------------------------------------------
   1.189 -# Some sanity checks, now
   1.190 -
   1.191 -# We check for grep and sed manually, because it is used in has_or_abort
   1.192 -printf "Checking for 'grep'... "
   1.193 -grep="$( which grep 2>/dev/null )"
   1.194 -[ -z "${grep}" ] && do_error "not found"
   1.195 -echo "${grep}"
   1.196 -printf "Checking whether '${grep}' supports -E... "
   1.197 -if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
   1.198 -    echo "yes"
   1.199 -else
   1.200 -    do_error "no"
   1.201 -fi
   1.202 -printf "Checking for 'sed'... "
   1.203 -sed="$( which sed 2>/dev/null )"
   1.204 -[ -z "${sed}" ] && do_error "not found"
   1.205 -echo "${sed}"
   1.206 -
   1.207 -# Check the existence of absolutely required tools
   1.208 -save_IFS="${IFS}"
   1.209 -IFS='
   1.210 -'
   1.211 -for tool in ${TOOLS_TO_CHECK}; do
   1.212 -    has_or_abort "${tool}"
   1.213 -done
   1.214 -IFS="${save_IFS}"
   1.215 -
   1.216 -#---------------------------------------------------------------------
   1.217  # Set user's options
   1.218  
   1.219  while [ $# -ne 0 ]; do
   1.220      case "$1" in
   1.221 +        --local)    LOCAL_set=1; shift;;
   1.222          --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
   1.223          --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
   1.224          --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
   1.225          --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
   1.226          --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
   1.227 -        --local)    LOCAL_set=1; shift;;
   1.228 -        --with-contrib*)
   1.229 -                    set_contrib "$1" "$2" && shift || shift 2
   1.230 -                    [ "${do_quit}" = "1" ] && exit 0
   1.231 -                    ;;
   1.232 +        --with-*)   set_tool   "$1" "$2" && shift || shift 2;;
   1.233          --help|-h)  do_help; exit 0;;
   1.234 -        *)          do_help; exit 1;;
   1.235 +        *)          echo "Unrecognised option: '${1}'"; do_help; exit 1;;
   1.236      esac
   1.237  done
   1.238  
   1.239 @@ -291,24 +267,50 @@
   1.240  fi
   1.241  
   1.242  #---------------------------------------------------------------------
   1.243 -# Apply contributed code
   1.244 +# Some sanity checks, now
   1.245  
   1.246 -# It's safer to change all ',' to spaces rather than setting IFS
   1.247 -CONTRIB_list="$( echo "${CONTRIB_list}"                                     \
   1.248 -                 |"${sed}" -r -e 's/,+/ /g; s/ +/ /g; s/^ //g; s/ $//g;'    \
   1.249 -               )"
   1.250 -if [ -n "${CONTRIB_list}" ]; then
   1.251 -    has_or_abort 'lzcat'
   1.252 -    printf "Applying contributed code: "
   1.253 -    for c in ${CONTRIB_list}; do
   1.254 -        printf "${c}, "
   1.255 -        if [ ! -f "contrib/${c}.patch.lzma" ]; then
   1.256 -            do_error "Contribution '${c}' does not exist"
   1.257 -        fi
   1.258 -        lzcat "contrib/${c}.patch.lzma" |patch -p1 >/dev/null 2>&1
   1.259 -    done
   1.260 -    echo "done"
   1.261 +# We check for grep and sed manually, because they are used in has_or_abort
   1.262 +printf "Checking for 'grep'... "
   1.263 +if [ -n "${grep}" ]; then
   1.264 +    echo "${grep} (cached)"
   1.265 +else
   1.266 +    grep="$( which grep 2>/dev/null )"
   1.267 +    [ -z "${grep}" ] && do_error "not found"
   1.268 +    echo "${grep}"
   1.269  fi
   1.270 +printf "Checking whether '${grep}' supports -E... "
   1.271 +if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
   1.272 +    echo "yes"
   1.273 +else
   1.274 +    do_error "no"
   1.275 +fi
   1.276 +
   1.277 +printf "Checking for 'sed'... "
   1.278 +if [ -n "${sed}" ]; then
   1.279 +    echo "${sed} (cached)"
   1.280 +else
   1.281 +    sed="$( which sed 2>/dev/null )"
   1.282 +    [ -z "${sed}" ] && do_error "not found"
   1.283 +    echo "${sed}"
   1.284 +fi
   1.285 +printf "Checking wether '${sed}' supports -i and -e... "
   1.286 +touch .ct-ng.sed.test
   1.287 +if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
   1.288 +    rm -f .ct-ng.sed.test
   1.289 +    echo "yes"
   1.290 +else
   1.291 +    rm -f .ct-ng.sed.test
   1.292 +    do_error "no"
   1.293 +fi
   1.294 +
   1.295 +# Check the existence of absolutely required tools
   1.296 +save_IFS="${IFS}"
   1.297 +IFS='
   1.298 +'
   1.299 +for tool in ${TOOLS_TO_CHECK}; do
   1.300 +    has_or_abort "${tool}"
   1.301 +done
   1.302 +IFS="${save_IFS}"
   1.303  
   1.304  #---------------------------------------------------------------------
   1.305  # Compute the version string
   1.306 @@ -364,12 +366,22 @@
   1.307  # That's all, folks!
   1.308  
   1.309  printf "Building up Makefile... "
   1.310 +var_list="grep
   1.311 +          sed
   1.312 +          $( printf "${TOOLS_TO_CHECK}"                                 \
   1.313 +             |"${sed}" -r -e 's/^((([^=:]+):.+|[^:=]+)=.+|[^:=]+)$/\3/;'
   1.314 +           )"
   1.315 +var_sed="$( for var_name in ${var_list}; do
   1.316 +                eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
   1.317 +            done 
   1.318 +          )"
   1.319  "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g
   1.320                  s,@@LIBDIR@@,${LIBDIR},g
   1.321                  s,@@DOCDIR@@,${DOCDIR},g
   1.322                  s,@@MANDIR@@,${MANDIR},g
   1.323                  s,@@VERSION@@,${VERSION},g
   1.324                  s,@@DATE@@,${DATE},g
   1.325 +                ${var_sed}
   1.326                  s,@@LOCAL@@,${LOCAL_set},g"  Makefile.in >Makefile
   1.327  echo "done"
   1.328  
   1.329 @@ -381,7 +393,6 @@
   1.330    LIBDIR='${LIBDIR}'
   1.331    DOCDIR='${DOCDIR}'
   1.332    MANDIR='${MANDIR}'
   1.333 -  CONTRIB='${CONTRIB_list}'
   1.334  
   1.335  Now run:
   1.336    make