configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon May 25 19:48:42 2009 +0000 (2009-05-25)
branchgcc-4.4
changeset 1387 a52504ffac55
parent 1333 93d889b9d9bd
child 1402 146c62142e1b
child 1409 7264ce426be4
permissions -rwxr-xr-x
/devel/gcc-4.4:
- TODO: remove completed items

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