configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Jan 07 12:11:37 2009 +0000 (2009-01-07)
changeset 1132 c232833120c1
parent 1106 2051ee3d1b75
child 1140 6bdb31785d6c
permissions -rwxr-xr-x
./configurei: make FORCE work again:
- removed the --force command line option
- use FORCE from the environment

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