configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Mar 08 17:09:39 2009 +0000 (2009-03-08)
changeset 1247 9759fe659b4f
parent 1187 3a76b3242ed8
child 1255 d856241f693c
permissions -rwxr-xr-x
Use "grep -E" instead of the deprecated "egrep".

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