configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jan 31 13:09:01 2010 +0100 (2010-01-31)
branchnewlib
changeset 1770 f7eaca0e8519
parent 1288 07b12579841d
permissions -rwxr-xr-x
newlib: close the obsolete devel branch

newlib has been integrated through the AVR32 stuff, and the newlib branch
has been bit-rotting in the meantime.
yann@182
     1
#!/bin/sh
yann@182
     2
yann@1366
     3
myname="${0##*/}"
yann@1366
     4
yann@1105
     5
VERSION=$( cat .version )
yann@1105
     6
DATE=$( date +%Y%m%d )
yann@182
     7
yann@183
     8
PREFIX_DEFAULT=/usr/local
yann@182
     9
yann@182
    10
BINDIR_set=
yann@182
    11
LIBDIR_set=
yann@182
    12
DOCDIR_set=
yann@182
    13
MANDIR_set=
yann@285
    14
LOCAL_set=
yann@1366
    15
FORCE=
yann@182
    16
yann@641
    17
do_quit=
yann@614
    18
yann@673
    19
# Simply print the error message, and exit. Obvious, he?
yann@673
    20
do_error() {
yann@1366
    21
    echo "${myname}: ${@}"
yann@673
    22
    exit 1
yann@673
    23
}
yann@673
    24
yann@641
    25
# Given an option string and the following argument,
yann@641
    26
# echoes the value of the option.
yann@641
    27
# If --var=val => echoes val and returns 0, meaning second arg was not consumed
yann@641
    28
# If --var val => echoes val and returns non null, meaning second arg was used
yann@182
    29
get_optval(){
yann@182
    30
    case "$1" in
yann@182
    31
        --*=?*)
yann@1140
    32
            echo "${1#*=}"
yann@1105
    33
            return 0
yann@182
    34
            ;;
yann@182
    35
        *)
yann@182
    36
            echo "${2}"
yann@1105
    37
            return 1
yann@182
    38
            ;;
yann@182
    39
    esac
yann@182
    40
}
yann@182
    41
yann@641
    42
# The set_xxx functions will set the corresponding configuration variable
yann@641
    43
# They return 0 if second arg was not consumed, and non-zero if it was consumed.
yann@182
    44
set_prefix() {
yann@1105
    45
    PREFIX="$( get_optval "$1" "$2" )"
yann@182
    46
}
yann@182
    47
set_bindir() {
yann@376
    48
    BINDIR_set=1
yann@1105
    49
    BINDIR="$( get_optval "$1" "$2" )"
yann@182
    50
}
yann@182
    51
set_libdir() {
yann@376
    52
    LIBDIR_set=1
yann@1105
    53
    LIBDIR="$( get_optval "$1" "$2" )"
yann@182
    54
}
yann@182
    55
set_docdir() {
yann@376
    56
    DOCDIR_set=1
yann@1105
    57
    DOCDIR="$( get_optval "$1" "$2" )"
yann@182
    58
}
yann@182
    59
set_mandir() {
yann@376
    60
    MANDIR_set=1
yann@1105
    61
    MANDIR="$( get_optval "$1" "$2" )"
yann@182
    62
}
yann@1140
    63
set_tool() {
yann@1140
    64
    local var_name="${1%%=*}"
yann@1140
    65
    var_name="${var_name#--with-}"
yann@1140
    66
    eval ${var_name}="\$( get_optval "$1" "$2" )"
yann@614
    67
}
yann@614
    68
yann@1366
    69
# var_list is a list of variables, each one holding a path to a
yann@1366
    70
# tool, either detected by ./configure, or specified by the user.
yann@1366
    71
var_list=""
yann@1366
    72
yann@1366
    73
# This function adds a variable name to the above list of variable names.
yann@1366
    74
# $1: the name of the variable to add to the list
yann@1366
    75
add_to_var_list() {
yann@1366
    76
    var_list="${var_list} ${1}"
yann@1366
    77
}
yann@1366
    78
yann@1366
    79
# A function to test for required tools/headers/libraries
yann@1366
    80
# $*: [prog|inc|lib]=<name[ name...]>
yann@1366
    81
#     the name(s) of tool(s) to test for
yann@1366
    82
#     mandatory
yann@1366
    83
#       eg: prog=bash   prog="curl wget"
yann@1366
    84
# $*: var=<var_name>
yann@1366
    85
#     the name of the variable to test and set
yann@1366
    86
#     optional
yann@1366
    87
#       eg: var=bash    if ${bash} is set and non-null, use that,
yann@1366
    88
#                       else check for bash and set bash=$(which bash)
yann@1366
    89
# $*: ver=<regexp>
yann@1366
    90
#     for each 'prog', test if $(prog --version) matches 'regexp'
yann@1366
    91
#     optional
yann@1366
    92
#       eg: ver='^GNU bash, version [34]\.'
yann@1366
    93
# $*: err=<error_message>
yann@1366
    94
#     the error message to print if tool is missing
yann@1366
    95
#     optional, defaults to: '${prog}: none found'
yann@1366
    96
#       eg: err="'bash' 3.x or above was not found"
yann@1366
    97
has_or_abort() {
yann@1366
    98
    local prog inc lib
yann@1366
    99
    local var ver err
yann@1366
   100
    local val
yann@1366
   101
    local item
yann@1366
   102
    local where
yann@1366
   103
    local version
yann@1366
   104
    local status
yann@1366
   105
yann@1366
   106
    for item in "${@}"; do
yann@1366
   107
        case "${item}" in
yann@1366
   108
            prog=*|inc=*|lib=*|var=*|ver=*|err=*)
yann@1366
   109
                eval ${item%%=*}="'${item#*=}'"
yann@1366
   110
                ;;
yann@1366
   111
            *)  do_error "has_or_abort: incorrect parameters: '$@'";;
yann@1366
   112
        esac
yann@1366
   113
    done
yann@1366
   114
yann@1366
   115
    case "${prog}:${inc}:${lib}" in
yann@1366
   116
        ?*::)
yann@1366
   117
            for item in ${prog}; do
yann@1366
   118
                printf "Checking for '${item}'... "
yann@1366
   119
                if [ -n "${var}" ]; then
yann@1366
   120
                    eval val="\${${var}}"
yann@1366
   121
                    if [ -n "${val}" ]; then
yann@1366
   122
                        printf "${val} (cached)\n"
yann@1366
   123
                        return 0
yann@1366
   124
                    fi
yann@1366
   125
                fi
yann@1366
   126
                where="$( which "${item}" 2>/dev/null )"
yann@1366
   127
                if [ -z "${where}" ]; then
yann@1366
   128
                    printf "no\n"
yann@1366
   129
                    continue
yann@1366
   130
                elif [ -n "${ver}" ]; then
yann@1366
   131
                    version=$( ${where} --version 2>&1 )
yann@1366
   132
                    str=$( echo "${version}" |grep -E "${ver}" |head -n 1 )
yann@1366
   133
                    if [ -z "${str}" ]; then
yann@1366
   134
                        printf "no\n"
yann@1366
   135
                        unset where
yann@1366
   136
                        continue
yann@1366
   137
                    fi
yann@1366
   138
                fi
yann@1366
   139
                status="${where}"
yann@1366
   140
                break
yann@1366
   141
            done
yann@1366
   142
            ;;
yann@1366
   143
        :?*:)
yann@1366
   144
            for item in ${inc}; do
yann@1366
   145
                printf "Checking for '${item}'... "
yann@1366
   146
                if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
yann@1366
   147
                    where="${item}"
yann@1366
   148
                    status=yes
yann@1366
   149
                    break;
yann@1366
   150
                fi
yann@1366
   151
                printf "no\n"
yann@1366
   152
            done
yann@1366
   153
            ;;
yann@1366
   154
        ::?*)
yann@1366
   155
            for item in ${lib}; do
yann@1366
   156
                printf "Checking for '${item}'... "
yann@1366
   157
                where="$( gcc -print-file-name="${item}" )"
yann@1366
   158
                if [ "${where}" != "${item}" ]; then
yann@1366
   159
                    where="$( readlink -e "${where}" )"
yann@1366
   160
                    status=yes
yann@1366
   161
                    break;
yann@1366
   162
                fi
yann@1366
   163
                printf "no\n"
yann@1366
   164
            done
yann@1366
   165
            ;;
yann@1366
   166
    esac
yann@1366
   167
    if [ -z "${status}" ]; then
yann@1366
   168
        printf "\n${err:-${prog}${inc}${lib}: none found}\n\n"
yann@1366
   169
        printf "Either you are missing entirely the needed tool,\n"
yann@1366
   170
        printf "or the version you have is too old.\n"
yann@1366
   171
        if [ -n "${var}" ]; then
yann@1366
   172
            printf "You can give the path to this tool using: --with-${var}=PATH\n"
yann@1366
   173
        fi
yann@1366
   174
        # FORCE can be set in the environment
yann@1366
   175
        [ -z "${FORCE}" ] && do_error "Bailing out..."
yann@1366
   176
        printf "\n"
yann@1366
   177
        printf "<*                                          *>\n"
yann@1366
   178
        printf "<*            FORCE in action:              *>\n"
yann@1366
   179
        printf "<* Continuing despite missing pre-requisite *>\n"
yann@1366
   180
        printf "<*          Prepare for breakage            *>\n"
yann@1366
   181
        printf "<*                                          *>\n"
yann@1366
   182
        printf "\n"
yann@1366
   183
    else
yann@1366
   184
        printf "${status}"
yann@1366
   185
        if [ -n "${var}" ]; then
yann@1366
   186
            eval ${var}='"'"${where}"'"'
yann@1366
   187
            add_to_var_list "${var}"
yann@1366
   188
        fi
yann@1366
   189
        printf "\n"
yann@1366
   190
    fi
yann@1366
   191
}
yann@1366
   192
yann@183
   193
do_help() {
yann@183
   194
    cat <<__EOF__
yann@1140
   195
\`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
yann@183
   196
yann@183
   197
USAGE: ./configure [OPTION]...
yann@183
   198
yann@183
   199
Defaults for the options are specified in brackets.
yann@183
   200
yann@183
   201
Configuration:
yann@1105
   202
  -h, --help              display this help and exit
yann@1366
   203
      --force             force configure to continue, even in case
yann@1366
   204
                          some pre-requisites are missing
yann@615
   205
yann@615
   206
Installation directories:
yann@185
   207
  --prefix=PREFIX         install files in PREFIX [${PREFIX_DEFAULT}]
yann@285
   208
  --local                 don't install, and use current directory
yann@183
   209
yann@183
   210
By default, \`make install' will install all the files in
yann@183
   211
\`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
yann@183
   212
an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
yann@183
   213
for instance \`--prefix=\${HOME}'.
yann@183
   214
yann@183
   215
For better control, use the options below.
yann@183
   216
yann@183
   217
Fine tuning of the installation directories:
yann@683
   218
  --bindir=DIR            user executables [PREFIX/bin]
yann@683
   219
  --libdir=DIR            object code libraries [PREFIX/lib]
yann@683
   220
  --docdir=DIR            info documentation [PREFIX/share/doc]
yann@683
   221
  --mandir=DIR            man documentation [PREFIX/share/man]
yann@614
   222
yann@614
   223
Optional Features:
yann@1140
   224
  --with-install=PATH     Specify the full PATH to GNU install
yann@1366
   225
  --with-make=PATH        Specify the full PATH to GNU make >= 3.80
yann@1140
   226
  --with-grep=PATH        Specify the full PATH to GNU grep
yann@1140
   227
  --with-sed=PATH         Specify the full PATH to GNU sed
yann@1140
   228
  --with-bash=PATH        Specify the full PATH to bash >= 3.0
yann@183
   229
__EOF__
yann@183
   230
}
yann@183
   231
yann@376
   232
#---------------------------------------------------------------------
yann@376
   233
# Set user's options
yann@376
   234
yann@182
   235
while [ $# -ne 0 ]; do
yann@182
   236
    case "$1" in
yann@1366
   237
        --local)    LOCAL_set="y"; shift;;
yann@182
   238
        --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
yann@182
   239
        --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
yann@182
   240
        --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
yann@182
   241
        --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
yann@182
   242
        --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
yann@1140
   243
        --with-*)   set_tool   "$1" "$2" && shift || shift 2;;
yann@1366
   244
        --force)    FORCE=1; shift;;
yann@183
   245
        --help|-h)  do_help; exit 0;;
yann@1140
   246
        *)          echo "Unrecognised option: '${1}'"; do_help; exit 1;;
yann@182
   247
    esac
yann@182
   248
done
yann@182
   249
yann@641
   250
# Use defaults
yann@185
   251
[ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
yann@641
   252
yann@641
   253
# Special case when installing locally
yann@1366
   254
if [ "${LOCAL_set}" = "y" ]; then
yann@1105
   255
    set_prefix "" "$( pwd )"
yann@1105
   256
    set_bindir "" "$( pwd )"
yann@1105
   257
    set_libdir "" "$( pwd )"
yann@1105
   258
    set_docdir "" "$( pwd )/docs"
yann@1105
   259
    set_mandir "" "$( pwd )/docs"
yann@285
   260
fi
yann@183
   261
yann@376
   262
#---------------------------------------------------------------------
yann@1140
   263
# Some sanity checks, now
yann@1106
   264
yann@1140
   265
# We check for grep and sed manually, because they are used in has_or_abort
yann@1140
   266
printf "Checking for 'grep'... "
yann@1140
   267
if [ -n "${grep}" ]; then
yann@1140
   268
    echo "${grep} (cached)"
yann@1140
   269
else
yann@1140
   270
    grep="$( which grep 2>/dev/null )"
yann@1187
   271
    if [ -z "${grep}" ]; then
yann@1187
   272
        echo "not found"
yann@1187
   273
    else
yann@1187
   274
        echo "${grep}"
yann@1187
   275
        printf "Checking whether '${grep}' supports -E... "
yann@1187
   276
        if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
yann@1187
   277
            echo "yes"
yann@1187
   278
        else
yann@1187
   279
            echo "no"
yann@1187
   280
            grep=
yann@1187
   281
        fi
yann@1187
   282
    fi
yann@1106
   283
fi
yann@1187
   284
if [ -z "${grep}" ]; then
yann@1187
   285
    echo "Either you are missing entirely the needed tool,"
rpjday@1288
   286
    echo "or the version you have is too old."
yann@1187
   287
    echo "You can give the path to this tool using: --with-grep=PATH"
yann@1187
   288
    do_error "Bailing out..."
yann@1140
   289
fi
yann@1366
   290
add_to_var_list grep
yann@1140
   291
yann@1140
   292
printf "Checking for 'sed'... "
yann@1140
   293
if [ -n "${sed}" ]; then
yann@1140
   294
    echo "${sed} (cached)"
yann@1140
   295
else
yann@1140
   296
    sed="$( which sed 2>/dev/null )"
yann@1187
   297
    if [ -z "${sed}" ]; then
yann@1187
   298
        echo "not found"
yann@1187
   299
    else
yann@1187
   300
        echo "${sed}"
rpjday@1288
   301
        printf "Checking whether '${sed}' supports -i and -e... "
yann@1187
   302
        touch .ct-ng.sed.test
yann@1187
   303
        if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
yann@1187
   304
            echo "yes"
yann@1187
   305
        else
yann@1187
   306
            echo "no"
yann@1187
   307
            sed=
yann@1187
   308
        fi
yann@1187
   309
        rm -f .ct-ng.sed.test
yann@1187
   310
    fi
yann@1140
   311
fi
yann@1187
   312
if [ -z "${sed}" ]; then
yann@1187
   313
    echo "Either you are missing entirely the needed tool,"
rpjday@1288
   314
    echo "or the version you have is too old."
yann@1187
   315
    echo "You can give the path to this tool using: --with-sed=PATH"
yann@1187
   316
    do_error "Bailing out..."
yann@1140
   317
fi
yann@1366
   318
add_to_var_list sed
yann@1140
   319
yann@1366
   320
# The regular list of tools we can now easily check for
yann@1366
   321
has_or_abort prog=bash                              \
yann@1366
   322
             var=bash                               \
yann@1366
   323
             ver='^GNU bash, version [34]\.'        \
yann@1366
   324
             err="'bash' 3.x or above was not found"
yann@1366
   325
has_or_abort prog=cut
yann@1366
   326
has_or_abort prog=install var=install
yann@1366
   327
has_or_abort prog=make                                  \
yann@1366
   328
             var=make                                   \
yann@1366
   329
             ver='^GNU Make (3.[89][[:digit:]]|[4-9])'  \
yann@1366
   330
             err="GNU 'make' 3.80 or above was not found"
yann@1366
   331
has_or_abort prog=gcc
yann@1366
   332
has_or_abort prog=awk
yann@1366
   333
has_or_abort prog=bison
yann@1366
   334
has_or_abort prog=flex
yann@1366
   335
has_or_abort prog=makeinfo
yann@1366
   336
has_or_abort prog=automake                                                      \
yann@1366
   337
             ver='\(GNU automake\) (1\.[[:digit:]]{2,}\.|[2-9][[:digit:]]*\.)'  \
yann@1366
   338
             err="'automake' 1.10 or above was not found"
yann@1366
   339
has_or_abort prog=libtool                                                                           \
yann@1366
   340
             ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)'   \
yann@1366
   341
             err="'libtool' 1.5.26 or above was not found"
yann@1366
   342
has_or_abort prog="curl wget"
yann@1366
   343
has_or_abort prog=patch
yann@1366
   344
has_or_abort prog=tar
yann@1366
   345
has_or_abort prog=gzip
yann@1366
   346
has_or_abort prog=bzip2
yann@1366
   347
has_or_abort prog=lzma
yann@1366
   348
has_or_abort prog=readlink
yann@1366
   349
yann@1366
   350
has_or_abort inc="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"    \
yann@1366
   351
             err="'ncurses' headers files were not found"
yann@1366
   352
yann@1366
   353
has_or_abort lib="$( echo lib{ncursesw,ncurses,curses}.{so,a,dylib} )"  \
yann@1366
   354
             err="'ncurses' library was not found"
yann@1106
   355
yann@1106
   356
#---------------------------------------------------------------------
yann@1106
   357
# Compute the version string
yann@376
   358
yann@435
   359
# If this version is a svn snapshot, try to get the revision number
yann@435
   360
# If we can't get the revision number, use date
yann@435
   361
case "${VERSION}" in
yann@1105
   362
    *+svn|svn)
yann@1366
   363
        has_or_abort prog=svnversion
yann@1366
   364
        printf "Computing version string... "
yann@1105
   365
        REVISION="$( LC_ALL=C svnversion )"
yann@1105
   366
        case "${REVISION}" in
yann@1105
   367
            exported)
yann@1105
   368
                VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
yann@1105
   369
            *)
yann@1105
   370
                URL="$( LC_ALL=C svn info 2>/dev/null   \
yann@1105
   371
                                 |egrep 'URL: '         \
yann@1105
   372
                                 |cut -d ' ' -f 2-      \
yann@1105
   373
                      )"
yann@1106
   374
                ROOT="$( LC_ALL=C svn info 2>/dev/null      \
yann@1106
   375
                         |"${grep}" '^Repository Root: '    \
yann@1106
   376
                         |cut -d ' ' -f 3-                  \
yann@1105
   377
                       )"
yann@1105
   378
                VERSION="${VERSION}${URL#${ROOT}}@${REVISION}"
yann@1105
   379
                ;;
yann@1105
   380
        esac
yann@1105
   381
        # Arrange to have no / in the directory name, no need to create an
yann@1105
   382
        # arbitrarily deep directory structure
yann@1106
   383
        VERSION="$( echo "${VERSION}" |"${sed}" -r -e 's|/+|_|g;' )"
yann@444
   384
        ;;
yann@435
   385
esac
yann@553
   386
echo "${VERSION}"
yann@435
   387
yann@1106
   388
#---------------------------------------------------------------------
yann@1106
   389
# Compute and check install paths
yann@1106
   390
yann@614
   391
# Now we have the version string, we can build up the paths
yann@554
   392
[ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
yann@554
   393
[ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib/ct-ng-${VERSION}"
yann@554
   394
[ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc/ct-ng-${VERSION}"
yann@554
   395
[ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1"
yann@554
   396
yann@1047
   397
# Check that install PATHs are absolute
yann@1047
   398
for p in BIN LIB DOC MAN; do
yann@1105
   399
    var="${p}DIR"
yann@1105
   400
    eval v='"${'"${var}"'}"'
yann@1105
   401
    case "${v}" in
yann@1105
   402
        /*) ;;
yann@1105
   403
        *)  do_error "'${var}' is not an absolute path: '${v}'"
yann@1105
   404
    esac
yann@1047
   405
done
yann@1047
   406
yann@1106
   407
#---------------------------------------------------------------------
yann@1106
   408
# That's all, folks!
yann@614
   409
yann@641
   410
printf "Building up Makefile... "
yann@1140
   411
var_sed="$( for var_name in ${var_list}; do
yann@1140
   412
                eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
yann@1140
   413
            done 
yann@1140
   414
          )"
yann@1106
   415
"${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g
yann@1106
   416
                s,@@LIBDIR@@,${LIBDIR},g
yann@1106
   417
                s,@@DOCDIR@@,${DOCDIR},g
yann@1106
   418
                s,@@MANDIR@@,${MANDIR},g
yann@1106
   419
                s,@@VERSION@@,${VERSION},g
yann@1106
   420
                s,@@DATE@@,${DATE},g
yann@1140
   421
                ${var_sed}
yann@1106
   422
                s,@@LOCAL@@,${LOCAL_set},g"  Makefile.in >Makefile
yann@673
   423
echo "done"
yann@185
   424
yann@185
   425
cat <<__EOF__
yann@673
   426
yann@197
   427
crosstool-NG configured as follows:
yann@554
   428
  PREFIX='${PREFIX}'
yann@554
   429
  BINDIR='${BINDIR}'
yann@554
   430
  LIBDIR='${LIBDIR}'
yann@554
   431
  DOCDIR='${DOCDIR}'
yann@554
   432
  MANDIR='${MANDIR}'
yann@1106
   433
yann@1106
   434
Now run:
yann@1106
   435
  make
yann@185
   436
__EOF__
yann@1366
   437
if [ "${LOCAL_set}" != "y" ]; then
yann@1366
   438
    printf "  make install\n"
yann@1366
   439
fi