configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Jul 09 21:13:07 2008 +0000 (2008-07-09)
changeset 644 8c816e372384
parent 615 c9d37346d57f
child 673 a78a4bcc62d6
permissions -rwxr-xr-x
Fix wiki table sample output.

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