configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Apr 20 21:10:03 2009 +0000 (2009-04-20)
changeset 1299 3448ac3f1a5d
parent 1298 7ac43d3747c0
child 1302 7df725fc8f66
permissions -rwxr-xr-x
There's no longer any reason to require GNU awk:
- the only part that required it (socks proxy settings) is gone,
- all remaining awk scripts are POSIXly correct (or should be).

-------- diffstat follows --------
/trunk/configure | 5 2 3 0 ++---
/trunk/Makefile.in | 2 0 2 0 --
/trunk/scripts/build/kernel/linux.sh | 2 1 1 0 +-
/trunk/scripts/build/internals.sh | 1 0 1 0 -
/trunk/scripts/build/mpfr.sh | 2 1 1 0 +-
/trunk/scripts/functions | 4 2 2 0 ++--
/trunk/scripts/saveSample.sh.in | 4 2 2 0 ++--
7 files changed, 8 insertions(+), 12 deletions(-)
     1 #!/bin/sh
     2 
     3 VERSION=$( cat .version )
     4 DATE=$( date +%Y%m%d )
     5 
     6 # All absolutely required tools, one per line to ease diff.
     7 # See function 'has_or_abort', below, for syntax
     8 #  - Hopefully, if gcc is present, then all associated tools will be
     9 #  - makeinfo for building docs, even if discarded later on
    10 #  - others obvious... :-/
    11 #
    12 # Format of a pattern to check for, one per line:
    13 #   pattern := var_name : tool_pattern  OR  tool_pattern
    14 #   tool_pattern := tool_test  OR  tool_pattern || tool_test
    15 #   tool_test := tool=regexp OR tool
    16 #   tool := basename of the tool  OR  absolute pathname to the tool
    17 #   regexp := valid grep(1) extended regular expression, $( tool --version)
    18 #             will be matched against this regexp.
    19 #
    20 # In case a pattern list is given (eg foo || bar || buz), then tests are performed
    21 # from left to right, stopping at the first matching test (like the shell
    22 # would parse 'foo || bar || buz' ).
    23 #
    24 # Examples:
    25 #    bash:bash=^GNU bash, version 3\.
    26 #     - if ${bash} is set and non-null, does nothing
    27 #     - else ensures that bash exists in the PATH, and that $( bash --version )
    28 #       matches the regexp '^GNU bash, version 3\.'
    29 #       - if so, then sets bash="$( which bash )"
    30 #    autoconf=(GNU Autoconf) || autoconf2.50
    31 #     - does not look at an existing variable
    32 #     - ensures that:
    33 #         - 'autoconf' is to be found in the PATH, and that $( autoconf --version )
    34 #           matches the regexp '(GNU Autoconf)' (which btw is the signature of
    35 #           autoconf >= 2.50),
    36 #       OR that:
    37 #         - 'autoconf2.50' is to be found in the PATH
    38 #
    39 TOOLS_TO_CHECK='
    40 bash:bash=^GNU bash, version [34]\.
    41 cut
    42 xargs
    43 install:install=GNU coreutils
    44 make:make=^GNU Make
    45 gcc
    46 awk
    47 bison
    48 flex
    49 makeinfo
    50 automake=\(GNU automake\) (1\.[[:digit:]]{2,}\.|[2-9][[:digit:]]*\.)
    51 libtool=\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)
    52 curl || wget
    53 patch
    54 tar
    55 gzip
    56 bzip2
    57 '
    58 
    59 PREFIX_DEFAULT=/usr/local
    60 
    61 BINDIR_set=
    62 LIBDIR_set=
    63 DOCDIR_set=
    64 MANDIR_set=
    65 LOCAL_set=
    66 
    67 do_quit=
    68 
    69 # Simply print the error message, and exit. Obvious, he?
    70 do_error() {
    71     echo "${@}"
    72     exit 1
    73 }
    74 
    75 # A small function to test for existence of various tools
    76 # Usage: has_or_abort test_pattern (see top of file, TOOLS_TO_CHECK, for
    77 #                                   complete pattern format)
    78 has_or_abort() {
    79     local save_IFS
    80     local var_name
    81     local var_value
    82     local tool_pattern
    83     local field
    84 
    85     var_name="$( echo "${1}" |"${sed}" -r -e 's/^(([^=:]+):.+|[^:=]+=.+|[^:=]+)$/\2/;' )"
    86     field="${var_name:+2}"
    87     field="${field:-1}"
    88     tool_pattern="$( echo "${1}" |cut -d : -f ${field}- |"${sed}" -r -e 's/ *\|\| */\n/g;' )"
    89 
    90     save_IFS="${IFS}"
    91     # Set IFS to \n only
    92     IFS='
    93 '
    94     for item in ${tool_pattern}; do
    95         case "${item}" in
    96             *=*)
    97                 tool="${item%%=*}"
    98                 regexp="${item#*=}"
    99                 ;;
   100             *)  tool="${item}"
   101                 regexp=
   102                 ;;
   103         esac
   104 
   105         printf "Checking for '${tool}'... "
   106         if [ -n "${var_name}" ]; then
   107             eval var_value='"${'"${var_name}"'}"'
   108             if [ -n "${var_value}" ]; then
   109                 echo "${var_value} (cached)"
   110                 return 0
   111             fi
   112         fi
   113         where=$( which "${tool}" 2>/dev/null )
   114         if [ -z "${where}" ]; then
   115             echo "not found"
   116             where=
   117             continue
   118         elif [ -n "${regexp}" ]; then
   119             tool_version=$( ${tool} --version 2>&1 )
   120             str=$( echo "${tool_version}" |"${grep}" -E "${regexp}" |head -n 1 )
   121             if [ -z "${str}" ]; then
   122                 echo "not found"
   123                 where=""
   124                 continue
   125             fi
   126         fi
   127         break
   128     done
   129     if [ -z "${where}" ]; then
   130         for item in ${tool_pattern}; do
   131             case "${item}" in
   132                 *=*)
   133                     tool="${item%%=*}"
   134                     regexp="${item#*=}"
   135                     ;;
   136                 *)  tool="${item}"
   137                     regexp=
   138                     ;;
   139             esac
   140             printf "  could not find '${tool}'"
   141             [ -n "${regexp}" ] && printf " matching regexp '${regexp}'"
   142             echo
   143         done
   144         echo "Either you are missing entirely the needed tool,"
   145         echo "or the version you have is too old."
   146         if [ -n "${var_name}" ]; then
   147             echo "You can give the path to this tool using: --with-${var_name}=PATH"
   148         fi
   149         # FORCE can be set in the environment
   150         [ -z "${FORCE}" ] && do_error "Bailing out..."
   151     else
   152         echo "${where}"
   153         if [ -n "${var_name}" ]; then
   154             eval ${var_name}='"'"${where}"'"'
   155         fi
   156     fi
   157     IFS="${save_IFS}"
   158     return 0
   159 }
   160 
   161 # Given an option string and the following argument,
   162 # echoes the value of the option.
   163 # If --var=val => echoes val and returns 0, meaning second arg was not consumed
   164 # If --var val => echoes val and returns non null, meaning second arg was used
   165 get_optval(){
   166     case "$1" in
   167         --*=?*)
   168             echo "${1#*=}"
   169             return 0
   170             ;;
   171         *)
   172             echo "${2}"
   173             return 1
   174             ;;
   175     esac
   176 }
   177 
   178 # The set_xxx functions will set the corresponding configuration variable
   179 # They return 0 if second arg was not consumed, and non-zero if it was consumed.
   180 set_prefix() {
   181     PREFIX="$( get_optval "$1" "$2" )"
   182 }
   183 set_bindir() {
   184     BINDIR_set=1
   185     BINDIR="$( get_optval "$1" "$2" )"
   186 }
   187 set_libdir() {
   188     LIBDIR_set=1
   189     LIBDIR="$( get_optval "$1" "$2" )"
   190 }
   191 set_docdir() {
   192     DOCDIR_set=1
   193     DOCDIR="$( get_optval "$1" "$2" )"
   194 }
   195 set_mandir() {
   196     MANDIR_set=1
   197     MANDIR="$( get_optval "$1" "$2" )"
   198 }
   199 set_tool() {
   200     local var_name="${1%%=*}"
   201     var_name="${var_name#--with-}"
   202     eval ${var_name}="\$( get_optval "$1" "$2" )"
   203 }
   204 
   205 do_help() {
   206     cat <<__EOF__
   207 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
   208 
   209 USAGE: ./configure [OPTION]...
   210 
   211 Defaults for the options are specified in brackets.
   212 
   213 Configuration:
   214   -h, --help              display this help and exit
   215 
   216 Installation directories:
   217   --prefix=PREFIX         install files in PREFIX [${PREFIX_DEFAULT}]
   218   --local                 don't install, and use current directory
   219 
   220 By default, \`make install' will install all the files in
   221 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
   222 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
   223 for instance \`--prefix=\${HOME}'.
   224 
   225 For better control, use the options below.
   226 
   227 Fine tuning of the installation directories:
   228   --bindir=DIR            user executables [PREFIX/bin]
   229   --libdir=DIR            object code libraries [PREFIX/lib]
   230   --docdir=DIR            info documentation [PREFIX/share/doc]
   231   --mandir=DIR            man documentation [PREFIX/share/man]
   232 
   233 Optional Features:
   234   --with-install=PATH     Specify the full PATH to GNU install
   235   --with-make=PATH        Specify the full PATH to GNU make
   236   --with-grep=PATH        Specify the full PATH to GNU grep
   237   --with-sed=PATH         Specify the full PATH to GNU sed
   238   --with-awk=PATH         Specify the full PATH to GNU awk
   239   --with-bash=PATH        Specify the full PATH to bash >= 3.0
   240 __EOF__
   241 }
   242 
   243 #---------------------------------------------------------------------
   244 # Set user's options
   245 
   246 while [ $# -ne 0 ]; do
   247     case "$1" in
   248         --local)    LOCAL_set="y"; shift;;
   249         --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
   250         --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
   251         --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
   252         --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
   253         --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
   254         --with-*)   set_tool   "$1" "$2" && shift || shift 2;;
   255         --help|-h)  do_help; exit 0;;
   256         *)          echo "Unrecognised option: '${1}'"; do_help; exit 1;;
   257     esac
   258 done
   259 
   260 # Use defaults
   261 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
   262 
   263 # Special case when installing locally
   264 if [ "${LOCAL_set}" = "y" ]; then
   265     set_prefix "" "$( pwd )"
   266     set_bindir "" "$( pwd )"
   267     set_libdir "" "$( pwd )"
   268     set_docdir "" "$( pwd )/docs"
   269     set_mandir "" "$( pwd )/docs"
   270 fi
   271 
   272 #---------------------------------------------------------------------
   273 # Some sanity checks, now
   274 
   275 # We check for grep and sed manually, because they are used in has_or_abort
   276 printf "Checking for 'grep'... "
   277 if [ -n "${grep}" ]; then
   278     echo "${grep} (cached)"
   279 else
   280     grep="$( which grep 2>/dev/null )"
   281     if [ -z "${grep}" ]; then
   282         echo "not found"
   283     else
   284         echo "${grep}"
   285         printf "Checking whether '${grep}' supports -E... "
   286         if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
   287             echo "yes"
   288         else
   289             echo "no"
   290             grep=
   291         fi
   292     fi
   293 fi
   294 if [ -z "${grep}" ]; then
   295     echo "Either you are missing entirely the needed tool,"
   296     echo "or the version you have is too old."
   297     echo "You can give the path to this tool using: --with-grep=PATH"
   298     do_error "Bailing out..."
   299 fi
   300 
   301 printf "Checking for 'sed'... "
   302 if [ -n "${sed}" ]; then
   303     echo "${sed} (cached)"
   304 else
   305     sed="$( which sed 2>/dev/null )"
   306     if [ -z "${sed}" ]; then
   307         echo "not found"
   308     else
   309         echo "${sed}"
   310         printf "Checking whether '${sed}' supports -i and -e... "
   311         touch .ct-ng.sed.test
   312         if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
   313             echo "yes"
   314         else
   315             echo "no"
   316             sed=
   317         fi
   318         rm -f .ct-ng.sed.test
   319     fi
   320 fi
   321 if [ -z "${sed}" ]; then
   322     echo "Either you are missing entirely the needed tool,"
   323     echo "or the version you have is too old."
   324     echo "You can give the path to this tool using: --with-sed=PATH"
   325     do_error "Bailing out..."
   326 fi
   327 
   328 # Check the existence of absolutely required tools
   329 save_IFS="${IFS}"
   330 IFS='
   331 '
   332 for tool in ${TOOLS_TO_CHECK}; do
   333     has_or_abort "${tool}"
   334 done
   335 IFS="${save_IFS}"
   336 
   337 #---------------------------------------------------------------------
   338 # Compute the version string
   339 
   340 # If this version is a svn snapshot, try to get the revision number
   341 # If we can't get the revision number, use date
   342 printf "Computing version string... "
   343 case "${VERSION}" in
   344     *+svn|svn)
   345         REVISION="$( LC_ALL=C svnversion )"
   346         case "${REVISION}" in
   347             exported)
   348                 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
   349             *)
   350                 URL="$( LC_ALL=C svn info 2>/dev/null   \
   351                                  |egrep 'URL: '         \
   352                                  |cut -d ' ' -f 2-      \
   353                       )"
   354                 ROOT="$( LC_ALL=C svn info 2>/dev/null      \
   355                          |"${grep}" '^Repository Root: '    \
   356                          |cut -d ' ' -f 3-                  \
   357                        )"
   358                 VERSION="${VERSION}${URL#${ROOT}}@${REVISION}"
   359                 ;;
   360         esac
   361         # Arrange to have no / in the directory name, no need to create an
   362         # arbitrarily deep directory structure
   363         VERSION="$( echo "${VERSION}" |"${sed}" -r -e 's|/+|_|g;' )"
   364         ;;
   365 esac
   366 echo "${VERSION}"
   367 
   368 #---------------------------------------------------------------------
   369 # Compute and check install paths
   370 
   371 # Now we have the version string, we can build up the paths
   372 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
   373 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib/ct-ng-${VERSION}"
   374 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc/ct-ng-${VERSION}"
   375 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1"
   376 
   377 # Check that install PATHs are absolute
   378 for p in BIN LIB DOC MAN; do
   379     var="${p}DIR"
   380     eval v='"${'"${var}"'}"'
   381     case "${v}" in
   382         /*) ;;
   383         *)  do_error "'${var}' is not an absolute path: '${v}'"
   384     esac
   385 done
   386 
   387 #---------------------------------------------------------------------
   388 # That's all, folks!
   389 
   390 printf "Building up Makefile... "
   391 var_list="grep
   392           sed
   393           $( printf "${TOOLS_TO_CHECK}"                                 \
   394              |"${sed}" -r -e 's/^(([^=:]+):.+|[^:=]+=.+|[^:=]+)$/\2/;'
   395            )"
   396 var_sed="$( for var_name in ${var_list}; do
   397                 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
   398             done 
   399           )"
   400 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g
   401                 s,@@LIBDIR@@,${LIBDIR},g
   402                 s,@@DOCDIR@@,${DOCDIR},g
   403                 s,@@MANDIR@@,${MANDIR},g
   404                 s,@@VERSION@@,${VERSION},g
   405                 s,@@DATE@@,${DATE},g
   406                 ${var_sed}
   407                 s,@@LOCAL@@,${LOCAL_set},g"  Makefile.in >Makefile
   408 echo "done"
   409 
   410 cat <<__EOF__
   411 
   412 crosstool-NG configured as follows:
   413   PREFIX='${PREFIX}'
   414   BINDIR='${BINDIR}'
   415   LIBDIR='${LIBDIR}'
   416   DOCDIR='${DOCDIR}'
   417   MANDIR='${MANDIR}'
   418 
   419 Now run:
   420   make
   421 __EOF__
   422 if [ "${LOCAL_set}" != "y" ]; then
   423     printf "  make install\n"
   424 fi