configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Jun 25 08:34:47 2008 +0000 (2008-06-25)
changeset 614 ede871c1fd91
parent 554 be6197b5b33b
child 615 c9d37346d57f
permissions -rwxr-xr-x
Enable using contributed code: add a new ./configure option to select which contributions should be applied.

/trunk/configure | 44 43 1 0 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
     1 #!/bin/sh
     2 
     3 VERSION=$(cat .version)
     4 DATE=$(date +%Y%m%d)
     5 
     6 PREFIX_DEFAULT=/usr/local
     7 
     8 BINDIR_set=
     9 LIBDIR_set=
    10 DOCDIR_set=
    11 MANDIR_set=
    12 LOCAL_set=
    13 
    14 qo_quit=
    15 CONTRIB_list=
    16 
    17 get_optval(){
    18     local ret
    19     case "$1" in
    20         --*=?*)
    21             echo "${1}" |cut -d '=' -f 2-
    22             ret=0
    23             ;;
    24         *)
    25             echo "${2}"
    26             ret=1
    27             ;;
    28     esac
    29     return ${ret}
    30 }
    31 
    32 set_prefix() {
    33     PREFIX=$(get_optval "$1" "$2")
    34     return $?
    35 }
    36 
    37 set_bindir() {
    38     BINDIR_set=1
    39     BINDIR=$(get_optval "$1" "$2")
    40     return $?
    41 }
    42 
    43 set_libdir() {
    44     LIBDIR_set=1
    45     LIBDIR=$(get_optval "$1" "$2")
    46     return $?
    47 }
    48 
    49 set_docdir() {
    50     DOCDIR_set=1
    51     DOCDIR=$(get_optval "$1" "$2")
    52     return $?
    53 }
    54 
    55 set_mandir() {
    56     MANDIR_set=1
    57     MANDIR=$(get_optval "$1" "$2")
    58     return $?
    59 }
    60 
    61 set_contrib() {
    62     opt_val=$(get_optval "$1" "$2")
    63     local ret=$?
    64     case "${opt_val}" in
    65         all)
    66             CONTRIB_list=$(LC_ALL=C ls -1 contrib/*.patch.lzma |sed -r -e 's|.*/||; s|\.patch\.lzma||;')
    67             ;;
    68         list)
    69             do_quit=1
    70             echo "Available contributions:"
    71             LC_ALL=C ls -1 contrib/*.patch.lzma |sed -r -e 's|.*/||; s|\.patch\.lzma||; s|^|  |;'
    72             ;;
    73         *)  CONTRIB_list="${CONTRIB_list},${opt_val}";;
    74     esac
    75     return $ret
    76 }
    77 
    78 do_help() {
    79     cat <<__EOF__
    80 \`configure' configures crosstool-NG ${VERSION} to adapt to many kind of systems.
    81 
    82 USAGE: ./configure [OPTION]...
    83 
    84 Defaults for the options are specified in brackets.
    85 
    86 Configuration:
    87   -h, --help              display this help and exit                                                                                                                  
    88   --prefix=PREFIX         install files in PREFIX [${PREFIX_DEFAULT}]
    89   --local                 don't install, and use current directory
    90 
    91 By default, \`make install' will install all the files in
    92 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
    93 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
    94 for instance \`--prefix=\${HOME}'.
    95 
    96 For better control, use the options below.
    97 
    98 Fine tuning of the installation directories:
    99   --bindir=DIR           user executables [PREFIX/bin]
   100   --libdir=DIR           object code libraries [PREFIX/lib]
   101   --docdir=DIR           info documentation [PREFIX/share/doc]
   102   --mandir=DIR           man documentation [PREFIX/share/man]
   103 
   104 Optional Features:
   105   --with-contrib=XXX     Include externally contributed features found in the
   106                          contrib/ sub-directory. Set to a comma-separated list
   107                          of features. Use 'all' to use all contributions, and
   108                          'list' to see which are available.
   109 __EOF__
   110 }
   111 
   112 do_error() {
   113     echo "[ERROR] ${@}"
   114     exit 1
   115 }
   116 
   117 #---------------------------------------------------------------------
   118 # Set user's options
   119 
   120 while [ $# -ne 0 ]; do
   121     case "$1" in
   122         --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
   123         --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
   124         --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
   125         --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
   126         --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
   127         --local)    LOCAL_set=1; shift;;
   128         --with-contrib*)
   129                     set_contrib "$1" "$2" && shift || shift 2
   130                     [ "${do_quit}" = "1" ] && exit 0
   131                     ;;
   132         --help|-h)  do_help; exit 0;;
   133         *)          do_help; exit 1;;
   134     esac
   135 done
   136 
   137 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
   138 if [ "${LOCAL_set}" = "1" ]; then
   139     set_prefix "" $(pwd)
   140     set_bindir "" $(pwd)
   141     set_libdir "" $(pwd)
   142     set_docdir "" $(pwd)/docs
   143     set_mandir "" $(pwd)/docs
   144 fi
   145 
   146 #---------------------------------------------------------------------
   147 # Some sanity checks, now
   148 
   149 # If this version is a svn snapshot, try to get the revision number
   150 # If we can't get the revision number, use date
   151 echo -n "Computing version string... "
   152 case "${VERSION}" in
   153   *+svn)
   154     REVISION=$(LC_ALL=C svnversion)
   155     case "${REVISION}" in
   156       exported)
   157         VERSION="${VERSION}unknown@$(date +%Y%m%d.%H%M%S)";;
   158       *)
   159         URL=$(LC_ALL=C svn info 2>/dev/null |egrep 'URL: ' |cut -d ' ' -f 2-)
   160         ROOT=$(LC_ALL=C svn info 2>/dev/null |egrep 'Repository Root: ' |cut -d ' ' -f 3-)
   161         VERSION="${VERSION}${URL#${ROOT}}@${REVISION}"
   162         ;;
   163     esac
   164     VERSION="${VERSION/\//_}"
   165     ;;
   166 esac
   167 echo "${VERSION}"
   168 
   169 # Now we have the version string, we can build up the paths
   170 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
   171 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib/ct-ng-${VERSION}"
   172 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc/ct-ng-${VERSION}"
   173 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1"
   174 
   175 # Check bash is present, and at least version 3.0
   176 echo -n "Checking bash is at least bash-3.0... "
   177 [ -x /bin/bash ] || do_error "bash 3.0 or above was not found in /bin/bash"
   178 bash_version=$(/bin/bash -c 'echo ${BASH_VERSION}')
   179 bash_major=$(/bin/bash -c 'echo ${BASH_VERSINFO[0]}')
   180 [ ${bash_major} -ge 3 ] || do_error "bash 3.0 or above is needed (/bin/bash is ${bash_version})"
   181 echo "ok (${bash_version})"
   182 
   183 echo -n "Applying contributed code: "
   184 for c in ${CONTRIB_list//,/ }; do
   185     echo -n "${c}... "
   186     if [ ! -f "contrib/${c}.patch.lzma" ]; then
   187         do_error "Contribution '${c}' does not exist"
   188     fi
   189     lzcat "contrib/${c}.patch.lzma" |patch -p1 >/dev/null 2>&1
   190 done
   191 echo "done"
   192 
   193 echo -n "Building up Makefile... "
   194 sed -r -e "s,@@BINDIR@@,${BINDIR},g;"   \
   195        -e "s,@@LIBDIR@@,${LIBDIR},g;"   \
   196        -e "s,@@DOCDIR@@,${DOCDIR},g;"   \
   197        -e "s,@@MANDIR@@,${MANDIR},g;"   \
   198        -e "s,@@VERSION@@,${VERSION},g;" \
   199        -e "s,@@DATE@@,${DATE},g;"       \
   200        -e "s,@@LOCAL@@,${LOCAL_set},g;" \
   201        Makefile.in >Makefile
   202 echo "ok"
   203 
   204 cat <<__EOF__
   205 crosstool-NG configured as follows:
   206   PREFIX='${PREFIX}'
   207   BINDIR='${BINDIR}'
   208   LIBDIR='${LIBDIR}'
   209   DOCDIR='${DOCDIR}'
   210   MANDIR='${MANDIR}'
   211   CONTRIB='${CONTRIB_list//
   212 /,}'
   213 __EOF__