configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat May 02 21:50:09 2009 +0000 (2009-05-02)
changeset 1313 7f0afd31d602
parent 1312 dd2afd8765a1
child 1332 61e81db78cf4
permissions -rwxr-xr-x
Add check for the {n,}curses library.
Add check for readlink, needed to check for libraries.

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