configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jul 01 20:52:34 2007 +0000 (2007-07-01)
changeset 183 f8acccd11133
parent 182 223c84ec2d90
child 185 ade232db1313
permissions -rwxr-xr-x
./configure gains a help entry.
     1 #!/bin/sh
     2 
     3 VERSION=$(cat version)
     4 DATE=$(date +%Y%m%d)
     5 
     6 PREFIX_DEFAULT=/usr/local
     7 BINDIR_DEFAULT="${PREFIX}/bin"
     8 LIBDIR_DEFAULT="${PREFIX}/lib"
     9 DOCDIR_DEFAULT="${PREFIX}/share/doc"
    10 MANDIR_DEFAULT="${PREFIX}/share/man"
    11 
    12 BINDIR_set=
    13 LIBDIR_set=
    14 DOCDIR_set=
    15 MANDIR_set=
    16 
    17 get_optval(){
    18     local ret
    19     case "$1" in
    20         --*=?*)
    21             echo "${1:9}"
    22             ret=0
    23             ;;
    24         *)
    25             echo "${2}"
    26             ret=1
    27             ;;
    28     esac
    29     return ${ret}
    30 }
    31 
    32 set_prefix() {
    33     local ret
    34     PREFIX=$(get_optval "$1" "$2")
    35     ret=$?
    36     [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
    37     [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
    38     [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
    39     [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
    40     return ${ret}
    41 }
    42 
    43 set_bindir() {
    44     local ret
    45     BINDIR=$(get_optval "$1" "$2")
    46     ret=$?
    47     BINDIR_set=1
    48     return ${ret}
    49 }
    50 
    51 set_libdir() {
    52     local ret
    53     LIBDIR=$(get_optval "$1" "$2")
    54     ret=$?
    55     LIBDIR_set=1
    56     return ${ret}
    57 }
    58 
    59 set_docdir() {
    60     local ret
    61     DOCDIR=$(get_optval "$1" "$2")
    62     ret=$?
    63     DOCDIR_set=1
    64     return ${ret}
    65 }
    66 
    67 set_mandir() {
    68     local ret
    69     MANDIR=$(get_optval "$1" "$2")
    70     ret=$?
    71     MANDIR_set=1
    72     return ${ret}
    73 }
    74 
    75 do_help() {
    76     cat <<__EOF__
    77 \`configure' configures ct-ng ${VERSION} to adapt to many kind of systems.
    78 
    79 USAGE: ./configure [OPTION]...
    80 
    81 Defaults for the options are specified in brackets.
    82 
    83 Configuration:
    84   -h, --help              display this help and exit                                                                                                                  
    85   --prefix=PREFIX         install architecture-independent files in PREFIX
    86                           [${PREFIX_DEFAULT}]
    87 
    88 By default, \`make install' will install all the files in
    89 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
    90 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
    91 for instance \`--prefix=\${HOME}'.
    92 
    93 For better control, use the options below.
    94 
    95 Fine tuning of the installation directories:
    96   --bindir=DIR           user executables [PREFIX/bin]
    97   --libdir=DIR           object code libraries [PREFIX/lib]
    98   --docdir=DIR           info documentation [PREFIX/share/doc]
    99   --mandir=DIR           man documentation [PREFIX/share/man]
   100 __EOF__
   101 }
   102 
   103 while [ $# -ne 0 ]; do
   104     case "$1" in
   105         --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
   106         --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
   107         --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
   108         --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
   109         --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
   110         --help|-h)  do_help; exit 0;;
   111         *)          do_help; exit 1;;
   112     esac
   113 done
   114 
   115 [ -z "${PREFIX}" ] && set_prefix --prefix "${PREFIX_DEFAULT}"
   116 
   117 sed -r -e "s,@@BINDIR@@,${BINDIR},g;"   \
   118        -e "s,@@LIBDIR@@,${LIBDIR},g;"   \
   119        -e "s,@@DOCDIR@@,${DOCDIR},g;"   \
   120        -e "s,@@MANDIR@@,${MANDIR},g;"   \
   121        -e "s,@@VERSION@@,${VERSION},g;" \
   122        -e "s,@@DATE@@,${DATE},g;"       \
   123         Makefile.in >Makefile