configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu Sep 25 21:49:17 2008 +0000 (2008-09-25)
changeset 875 07dcd5ca5094
parent 774 77d925a3765a
child 876 24e131e13113
permissions -rwxr-xr-x
Update the sstrip help entries. Courtesy "Joachim Nilsson" <joachim.nilsson@vmlinux.org>.

/trunk/config/tools/sstrip.in | 9 5 4 0 +++++----
1 file changed, 5 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 /bin/bash/^GNU bash, version 3\.
    14 make/^GNU Make
    15 gcc
    16 awk/^GNU Awk
    17 sed
    18 bison
    19 flex
    20 makeinfo
    21 automake
    22 libtool
    23 patch
    24 tar
    25 gzip
    26 bzip2
    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 or be an exiting fully qualified file name
    51 # Usage: has_or_abort foobar/string
    52 #          -> foobar must exist in PATH or be an existing FQFN, and $(foobar --version) must contain 'string'
    53 has_or_abort() {
    54     tool="${1%/*}"
    55     regexp="${1##*/}"
    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 the existence of absolutely required tools
   254 { IFS='
   255 ';
   256   for tool in ${TOOLS_TO_CHECK}; do
   257       has_or_abort "${tool}"
   258   done;
   259 }
   260 
   261 # It's safer to change all ',' to spaces rather than setting IFS
   262 CONTRIB_list=$(echo "${CONTRIB_list}" |sed -r -e 's/,+/ /g;')
   263 if [ -n "${CONTRIB_list}" ]; then
   264     has_or_abort lzcat
   265     printf "Applying contributed code: "
   266     for c in ${CONTRIB_list}; do
   267         printf "${c}, "
   268         if [ ! -f "contrib/${c}.patch.lzma" ]; then
   269             do_error "Contribution '${c}' does not exist"
   270         fi
   271         lzcat "contrib/${c}.patch.lzma" |patch -p1 >/dev/null 2>&1
   272     done
   273     echo "done"
   274 fi
   275 
   276 printf "Building up Makefile... "
   277 sed -r -e "s,@@BINDIR@@,${BINDIR},g;"   \
   278        -e "s,@@LIBDIR@@,${LIBDIR},g;"   \
   279        -e "s,@@DOCDIR@@,${DOCDIR},g;"   \
   280        -e "s,@@MANDIR@@,${MANDIR},g;"   \
   281        -e "s,@@VERSION@@,${VERSION},g;" \
   282        -e "s,@@DATE@@,${DATE},g;"       \
   283        -e "s,@@LOCAL@@,${LOCAL_set},g;" \
   284        Makefile.in >Makefile
   285 echo "done"
   286 
   287 cat <<__EOF__
   288 
   289 crosstool-NG configured as follows:
   290   PREFIX='${PREFIX}'
   291   BINDIR='${BINDIR}'
   292   LIBDIR='${LIBDIR}'
   293   DOCDIR='${DOCDIR}'
   294   MANDIR='${MANDIR}'
   295   CONTRIB='${CONTRIB_list}'
   296 __EOF__