configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Aug 05 13:27:09 2008 +0000 (2008-08-05)
changeset 760 80098c869f5e
parent 707 54a54765e827
child 774 77d925a3765a
permissions -rwxr-xr-x
Mark "ADA", "ObjC", "ObjC++" and "other languages" as being EXPERIMENTAL.

/trunk/config/cc.in | 12 8 4 0 ++++++++----
1 file changed, 8 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 TOOLS_TO_CHECK='
    13 make/^GNU
    14 gcc
    15 awk/^GNU
    16 sed
    17 bison
    18 flex
    19 makeinfo
    20 automake
    21 libtool
    22 patch
    23 tar
    24 gzip
    25 bzip2
    26 readlink
    27 '
    28 
    29 PREFIX_DEFAULT=/usr/local
    30 
    31 BINDIR_set=
    32 LIBDIR_set=
    33 DOCDIR_set=
    34 MANDIR_set=
    35 LOCAL_set=
    36 
    37 FORCE=0
    38 
    39 do_quit=
    40 CONTRIB_list=
    41 
    42 # Simply print the error message, and exit. Obvious, he?
    43 do_error() {
    44     echo "${@}"
    45     exit 1
    46 }
    47 
    48 # A small function to test for existence of various tools
    49 # Usage: has_or_abort foobar
    50 #          -> foobar must exist in PATH
    51 # Usage: has_or_abort foobar/string
    52 #          -> foobar must exist in PATH, and $(foobar --version) must contain 'string'
    53 has_or_abort() {
    54     tool=$(echo "${1}/" |cut -d / -f 1)
    55     regexp=$(echo "${1}/" |cut -d / -f 2)
    56     printf "Checking for '${tool}'... "
    57     where=$(which "${tool}" 2>/dev/null || true)
    58     if [ -z "${where}" ]; then
    59         printf "not found!"
    60         [ ${FORCE} -eq 0 ] && do_error " Bailing out..."
    61         echo
    62     else
    63         printf "${where}"
    64         if [ -n "${regexp}" ]; then
    65             str=$(${tool} --version 2>&1 |egrep "${regexp}" |head -n 1)
    66             if [ -z "${str}" ]; then
    67                 printf " failed: '${tool} --version' does not match regexp '${regexp}'."
    68                 [ ${FORCE} -eq 0 ] && do_error " Bailing out..."
    69             fi
    70         fi
    71         echo
    72     fi
    73     return 0
    74 }
    75 
    76 # Given an option string and the following argument,
    77 # echoes the value of the option.
    78 # If --var=val => echoes val and returns 0, meaning second arg was not consumed
    79 # If --var val => echoes val and returns non null, meaning second arg was used
    80 get_optval(){
    81     local ret
    82     case "$1" in
    83         --*=?*)
    84             echo "${1}" |cut -d '=' -f 2-
    85             ret=0
    86             ;;
    87         *)
    88             echo "${2}"
    89             ret=1
    90             ;;
    91     esac
    92     return ${ret}
    93 }
    94 
    95 # The set_xxx functions will set the corresponding configuration variable
    96 # They return 0 if second arg was not consumed, and non-zero if it was consumed.
    97 set_prefix() {
    98     PREFIX=$(get_optval "$1" "$2")
    99     return $?
   100 }
   101 set_bindir() {
   102     BINDIR_set=1
   103     BINDIR=$(get_optval "$1" "$2")
   104     return $?
   105 }
   106 set_libdir() {
   107     LIBDIR_set=1
   108     LIBDIR=$(get_optval "$1" "$2")
   109     return $?
   110 }
   111 set_docdir() {
   112     DOCDIR_set=1
   113     DOCDIR=$(get_optval "$1" "$2")
   114     return $?
   115 }
   116 set_mandir() {
   117     MANDIR_set=1
   118     MANDIR=$(get_optval "$1" "$2")
   119     return $?
   120 }
   121 
   122 # The set_contrib function is different in that it will work like the others,
   123 # except in two cases:
   124 # If all => replaces all with the list of all available contribs
   125 # If list => just echoes the list of all available contribs, and instructs
   126 # caller to quit immediately by setting do_quit to non null.
   127 # (can't use the return code, see above).
   128 set_contrib() {
   129     opt_val=$(get_optval "$1" "$2")
   130     local ret=$?
   131     case "${opt_val}" in
   132         all)
   133             CONTRIB_list=$(LC_ALL=C ls -1 contrib/*.patch.lzma  \
   134                            |xargs -I {} basename {} .patch.lzma \
   135                            |sed -r -e ':a; /$/N; s/\n/,/; ta;'
   136                           )
   137             ;;
   138         list)
   139             do_quit=1
   140             echo "Available contributions:"
   141             LC_ALL=C ls -1 contrib/*.patch.lzma     \
   142             |xargs -I {} basename {} .patch.lzma    \
   143             |sed -r -e 's/^/  /;'
   144             ;;
   145         *)  CONTRIB_list="${CONTRIB_list},${opt_val}";;
   146     esac
   147     return $ret
   148 }
   149 
   150 do_help() {
   151     cat <<__EOF__
   152 \`configure' configures crosstool-NG ${VERSION} to adapt to many kind of systems.
   153 
   154 USAGE: ./configure [OPTION]...
   155 
   156 Defaults for the options are specified in brackets.
   157 
   158 Configuration:
   159   -h, --help              display this help and exit                                                                                                                  
   160       --force             force ./configure to complete, even if one or more
   161                           tools were not found. Use at your own risk, only if
   162                           you know what you are doing!
   163 
   164 Installation directories:
   165   --prefix=PREFIX         install files in PREFIX [${PREFIX_DEFAULT}]
   166   --local                 don't install, and use current directory
   167 
   168 By default, \`make install' will install all the files in
   169 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
   170 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
   171 for instance \`--prefix=\${HOME}'.
   172 
   173 For better control, use the options below.
   174 
   175 Fine tuning of the installation directories:
   176   --bindir=DIR            user executables [PREFIX/bin]
   177   --libdir=DIR            object code libraries [PREFIX/lib]
   178   --docdir=DIR            info documentation [PREFIX/share/doc]
   179   --mandir=DIR            man documentation [PREFIX/share/man]
   180 
   181 Optional Features:
   182   --with-contrib=XXX      Include externally contributed features found in the
   183                           contrib/ sub-directory. Set to a comma-separated list
   184                           of features. Use 'all' to use all contributions, and
   185                           'list' to see which are available.
   186 __EOF__
   187 }
   188 
   189 #---------------------------------------------------------------------
   190 # Set user's options
   191 
   192 while [ $# -ne 0 ]; do
   193     case "$1" in
   194         --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
   195         --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
   196         --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
   197         --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
   198         --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
   199         --local)    LOCAL_set=1; shift;;
   200         --force)    FORCE=1; shift;;
   201         --with-contrib*)
   202                     set_contrib "$1" "$2" && shift || shift 2
   203                     [ "${do_quit}" = "1" ] && exit 0
   204                     ;;
   205         --help|-h)  do_help; exit 0;;
   206         *)          do_help; exit 1;;
   207     esac
   208 done
   209 
   210 # Use defaults
   211 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
   212 
   213 # Special case when installing locally
   214 if [ "${LOCAL_set}" = "1" ]; then
   215     set_prefix "" $(pwd)
   216     set_bindir "" $(pwd)
   217     set_libdir "" $(pwd)
   218     set_docdir "" $(pwd)/docs
   219     set_mandir "" $(pwd)/docs
   220 fi
   221 
   222 #---------------------------------------------------------------------
   223 # Some sanity checks, now
   224 
   225 # If this version is a svn snapshot, try to get the revision number
   226 # If we can't get the revision number, use date
   227 printf "Computing version string... "
   228 case "${VERSION}" in
   229   *+svn)
   230     REVISION=$(LC_ALL=C svnversion)
   231     case "${REVISION}" in
   232       exported)
   233         VERSION="${VERSION}unknown@$(date +%Y%m%d.%H%M%S)";;
   234       *)
   235         URL=$(LC_ALL=C svn info 2>/dev/null |egrep 'URL: ' |cut -d ' ' -f 2-)
   236         ROOT=$(LC_ALL=C svn info 2>/dev/null |egrep 'Repository Root: ' |cut -d ' ' -f 3-)
   237         VERSION="${VERSION}${URL#${ROOT}}@${REVISION}"
   238         ;;
   239     esac
   240     # Arrange to have no / in the directory name, no need to create an
   241     # arbitrarily deep directory structure
   242     VERSION=$(echo "${VERSION}" |sed -r -e 's|/+|_|g;')
   243     ;;
   244 esac
   245 echo "${VERSION}"
   246 
   247 # Now we have the version string, we can build up the paths
   248 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
   249 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib/ct-ng-${VERSION}"
   250 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc/ct-ng-${VERSION}"
   251 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1"
   252 
   253 # Check bash is present, and at least version 3.0
   254 printf "Checking '/bin/bash' is at least bash-3.0... "
   255 [ -x /bin/bash ] || do_error "bash 3.0 or above was not found in '/bin/bash'"
   256 bash_version=$(/bin/bash -c 'echo ${BASH_VERSION}')
   257 bash_major=$(/bin/bash -c 'echo ${BASH_VERSINFO[0]}')
   258 [ ${bash_major} -ge 3 ] || do_error "bash 3.0 or above is needed ('/bin/bash' is '${bash_version}')"
   259 echo "${bash_version}"
   260 
   261 # Check the existence of absolutely required tools
   262 for tool in ${TOOLS_TO_CHECK}; do
   263     has_or_abort "${tool}"
   264 done
   265 
   266 # It's safer to change all ',' to spaces rather than setting IFS
   267 CONTRIB_list=$(echo "${CONTRIB_list}" |sed -r -e 's/,+/ /g;')
   268 if [ -n "${CONTRIB_list}" ]; then
   269     has_or_abort lzcat
   270     printf "Applying contributed code: "
   271     for c in ${CONTRIB_list}; do
   272         printf "${c}, "
   273         if [ ! -f "contrib/${c}.patch.lzma" ]; then
   274             do_error "Contribution '${c}' does not exist"
   275         fi
   276         lzcat "contrib/${c}.patch.lzma" |patch -p1 >/dev/null 2>&1
   277     done
   278     echo "done"
   279 fi
   280 
   281 printf "Building up Makefile... "
   282 sed -r -e "s,@@BINDIR@@,${BINDIR},g;"   \
   283        -e "s,@@LIBDIR@@,${LIBDIR},g;"   \
   284        -e "s,@@DOCDIR@@,${DOCDIR},g;"   \
   285        -e "s,@@MANDIR@@,${MANDIR},g;"   \
   286        -e "s,@@VERSION@@,${VERSION},g;" \
   287        -e "s,@@DATE@@,${DATE},g;"       \
   288        -e "s,@@LOCAL@@,${LOCAL_set},g;" \
   289        Makefile.in >Makefile
   290 echo "done"
   291 
   292 cat <<__EOF__
   293 
   294 crosstool-NG configured as follows:
   295   PREFIX='${PREFIX}'
   296   BINDIR='${BINDIR}'
   297   LIBDIR='${LIBDIR}'
   298   DOCDIR='${DOCDIR}'
   299   MANDIR='${MANDIR}'
   300   CONTRIB='${CONTRIB_list}'
   301 __EOF__