configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Jun 28 00:29:02 2011 +0200 (2011-06-28)
changeset 2527 a65f56df62de
parent 2526 e5fb003a354c
child 2528 3b058d7049bf
permissions -rwxr-xr-x
configure: pass the allowed lib extensions to check_for()

Rather than building all possible library names in the caller,
lets just do it once in check_for.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
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@2481
    72
kconfig_list=""
yann@1311
    73
yann@1311
    74
# This function adds a variable name to the above list of variable names.
yann@1311
    75
# $1: the name of the variable to add to the list
yann@1311
    76
add_to_var_list() {
yann@2481
    77
    local v
yann@2481
    78
    for v in ${var_list}; do
yann@2481
    79
        [ "${v}" = "${1}" ] && return 0
yann@2481
    80
    done
yann@1311
    81
    var_list="${var_list} ${1}"
yann@1311
    82
}
yann@2481
    83
add_to_kconfig_list() {
yann@2481
    84
    local k
yann@2481
    85
    for k in ${kconfig_list}; do
yann@2481
    86
        [ "${k}" = "${1}" ] && return 0
yann@2481
    87
    done
yann@2481
    88
    kconfig_list="${kconfig_list} ${1}"
yann@2481
    89
}
yann@1311
    90
yann@1311
    91
# A function to test for required tools/headers/libraries
yann@1560
    92
# Return 0 (true) if found, !0 (false) if not found
yann@1560
    93
#
yann@1311
    94
# $*: [prog|inc|lib]=<name[ name...]>
yann@1311
    95
#     the name(s) of tool(s) to test for
yann@1311
    96
#     mandatory
yann@1311
    97
#       eg: prog=bash   prog="curl wget"
yann@1311
    98
# $*: var=<var_name>
yann@1311
    99
#     the name of the variable to test and set
yann@1311
   100
#     optional
yann@1311
   101
#       eg: var=bash    if ${bash} is set and non-null, use that,
yann@1311
   102
#                       else check for bash and set bash=$(which bash)
yann@1311
   103
# $*: ver=<regexp>
yann@1311
   104
#     for each 'prog', test if $(prog --version) matches 'regexp'
yann@1311
   105
#     optional
yann@1311
   106
#       eg: ver='^GNU bash, version [34]\.'
yann@2527
   107
# $*: lib_exts=<extension[ extension...]>
yann@2527
   108
#     the list of allowed library extension
yann@2527
   109
#     mandatory
yann@2527
   110
#       eg: lib_exts="so dylib"     lib_exts="so dylib a"
yann@1311
   111
# $*: err=<error_message>
yann@1311
   112
#     the error message to print if tool is missing
yann@1311
   113
#     optional, defaults to: '${prog}: none found'
yann@1311
   114
#       eg: err="'bash' 3.x or above was not found"
yann@2480
   115
#     Note: err may be printed by caller, not us
yann@2481
   116
# $*: kconfig=<var_name>
yann@2481
   117
#     the name of a variable to pass down to kconfig if
yann@2481
   118
#     the prog/inc/lib was found
yann@2481
   119
#     optional, defaults to none
yann@2481
   120
#       eg: kconfig=has_libncurses
yann@1560
   121
check_for() {
yann@2527
   122
    local lib_exts
yann@1311
   123
    local val
yann@1311
   124
    local item
yann@1311
   125
    local where
yann@1312
   126
    local status
yann@2527
   127
    local ext
yann@1311
   128
yann@2481
   129
    # Note: prog/inc/lib and var/kconfig/ver/err are set here,
yann@2479
   130
    # but declared by the caller (because it needs it)
yann@1311
   131
    for item in "${@}"; do
yann@1311
   132
        case "${item}" in
yann@2527
   133
            prog=*|inc=*|lib=*|var=*|ver=*|err=*|kconfig=*|lib_exts=*)
yann@2497
   134
                eval ${item%%=*}=\"${item#*=}\"
yann@1311
   135
                ;;
yann@2527
   136
            *)  do_error "check_for: incorrect parameters: '${item}'";;
yann@1311
   137
        esac
yann@1311
   138
    done
yann@1311
   139
benoit@2507
   140
    case "${prog}:${inc}:${lib}" in
benoit@2507
   141
        ?*:?*:|?*::?*|:?*:?*|?*:?*:?*)
benoit@2507
   142
            if [ -n "${var}" ]; then
benoit@2507
   143
                do_error "check_for: the use of var is not compatible with passing several of [prog|inc|lib] at once"
benoit@2507
   144
            fi
benoit@2507
   145
            ;;
benoit@2507
   146
        ::) do_error "check_for: [prog|inc|lib] is mandatory";;
benoit@2507
   147
    esac
benoit@2507
   148
yann@2481
   149
    if [ -n "${kconfig}" ]; then
yann@2481
   150
        add_to_kconfig_list "${kconfig}"
yann@2481
   151
    fi
yann@2481
   152
benoit@2507
   153
    if [ -n "${prog}" ]; then
benoit@2507
   154
        for item in ${prog}; do
benoit@2507
   155
            printf "Checking for '${item}'... "
benoit@2507
   156
            if [ -n "${var}" ]; then
benoit@2507
   157
                eval val="\${${var}}"
benoit@2507
   158
                if [ -n "${val}" ]; then
benoit@2507
   159
                    printf "${val} (cached)\n"
benoit@2507
   160
                    add_to_var_list "${var}"
benoit@2507
   161
                    return 0
yann@1311
   162
                fi
benoit@2507
   163
            fi
benoit@2507
   164
            where="$( which "${item}" 2>/dev/null )"
benoit@2507
   165
            if [ -z "${where}" ]; then
benoit@2507
   166
                printf "no\n"
benoit@2507
   167
                continue
benoit@2507
   168
            elif [ -n "${ver}" ]; then
benoit@2507
   169
                str=$( LC_ALL=C "${where}" --version 2>&1   \
benoit@2507
   170
                       |grep -E "${ver}"                    \
benoit@2507
   171
                       |head -n 1
benoit@2507
   172
                     )
benoit@2507
   173
                if [ -z "${str}" ]; then
yann@1312
   174
                    printf "no\n"
benoit@2507
   175
                    unset where
yann@1311
   176
                    continue
yann@1311
   177
                fi
benoit@2507
   178
            fi
benoit@2507
   179
            status="${where}"
benoit@2507
   180
            break
benoit@2507
   181
        done
benoit@2507
   182
        if [ -z "${status}" ]; then
benoit@2507
   183
            return 1
benoit@2507
   184
        fi
benoit@2507
   185
        printf "${status}\n"
benoit@2507
   186
        unset status
yann@1560
   187
    fi
yann@1560
   188
benoit@2507
   189
    if [ -n "${inc}" ]; then
benoit@2507
   190
        for item in ${inc}; do
benoit@2507
   191
            printf "Checking for '${item}'... "
benoit@2507
   192
            if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
benoit@2507
   193
                where="${item}"
benoit@2507
   194
                status=yes
benoit@2507
   195
                break;
benoit@2507
   196
            fi
benoit@2507
   197
            printf "no\n"
benoit@2507
   198
        done
benoit@2507
   199
        if [ -z "${status}" ]; then
benoit@2507
   200
            return 1
benoit@2507
   201
        fi
benoit@2507
   202
        printf "${status}\n"
benoit@2507
   203
        unset status
benoit@2507
   204
    fi
benoit@2507
   205
benoit@2507
   206
    if [ -n "${lib}" ]; then
yann@2527
   207
        if [ -z "${lib_exts}" ]; then
yann@2527
   208
            do_error "check_for: no library extension specified for '${lib}'"
yann@2527
   209
        fi
benoit@2507
   210
        for item in ${lib}; do
yann@2527
   211
            for ext in ${lib_exts}; do
yann@2527
   212
                printf "Checking for '${item}.${ext}'... "
yann@2527
   213
                where="$( gcc -print-file-name="${item}.${ext}" )"
yann@2527
   214
                if [ "${where}" != "${item}.${ext}" ]; then
yann@2527
   215
                    where="$( readlink "${where}" )"
yann@2527
   216
                    status=yes
yann@2527
   217
                    break 2;
yann@2527
   218
                fi
yann@2527
   219
                printf "no\n"
yann@2527
   220
            done
benoit@2507
   221
        done
benoit@2507
   222
        if [ -z "${status}" ]; then
benoit@2507
   223
            return 1
benoit@2507
   224
        fi
benoit@2507
   225
        printf "${status}\n"
benoit@2507
   226
        unset status
benoit@2507
   227
    fi
benoit@2507
   228
yann@1560
   229
    if [ -n "${var}" ]; then
yann@1560
   230
        eval ${var}='"'"${where}"'"'
yann@1560
   231
        add_to_var_list "${var}"
yann@1560
   232
    fi
yann@2481
   233
    if [ -n "${kconfig}" ]; then
yann@2481
   234
        eval ${kconfig}=y
yann@2481
   235
    fi
yann@1560
   236
}
yann@1560
   237
yann@1560
   238
# This function checks for a tool, and aborts if not found
yann@1560
   239
# See check_for(), above, for how to call has_or_abort
yann@1560
   240
has_or_abort() {
yann@2479
   241
    # We declare these 6 variables here, although they are
yann@2479
   242
    # set in check_for(), called below
yann@2479
   243
    local prog inc lib
yann@2481
   244
    local var ver err kconfig
yann@2479
   245
yann@1560
   246
    if ! check_for "$@"; then
yann@2524
   247
        printf " * A mandatory dependency is missing, or version mis-match:\n"
yann@2524
   248
        printf " * - ${err:-${prog}${inc}${lib}: none found}\n"
yann@2479
   249
        if [ -n "${var}" ]; then
yann@2498
   250
            printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
yann@2479
   251
        fi
yann@2479
   252
        printf "\n"
yann@2479
   253
        # Bail out if --force is not specified
yann@1312
   254
        [ -z "${FORCE}" ] && do_error "Bailing out..."
yann@1312
   255
        printf "<*                                          *>\n"
yann@1312
   256
        printf "<*            FORCE in action:              *>\n"
yann@1312
   257
        printf "<* Continuing despite missing pre-requisite *>\n"
yann@1312
   258
        printf "<*          Prepare for breakage            *>\n"
yann@1312
   259
        printf "<*                                          *>\n"
yann@1312
   260
        printf "\n"
yann@1312
   261
    fi
yann@1311
   262
}
yann@1311
   263
yann@2480
   264
# This function checks for a tool, and warns if not found
yann@2480
   265
# See check_for(), above, for how to call has_or_abort
yann@2480
   266
# Note: if err is not set, then no error message is printed
yann@2480
   267
has_or_warn() {
yann@2480
   268
    # We declare these 6 variables here, although they are
yann@2480
   269
    # set in check_for(), called below
yann@2480
   270
    local prog inc lib
yann@2481
   271
    local var ver err kconfig
yann@2480
   272
yann@2480
   273
    if ! check_for "$@"; then
yann@2524
   274
        printf " * An optional dependency is missing, some features will be disabled"
yann@2524
   275
        printf "${err:+:\n * - ${err}}\n"
yann@2480
   276
        if [ -n "${var}" ]; then
yann@2498
   277
            printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
yann@2480
   278
        fi
yann@2480
   279
    fi
yann@2480
   280
}
yann@2480
   281
yann@183
   282
do_help() {
yann@183
   283
    cat <<__EOF__
yann@1140
   284
\`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
yann@183
   285
yann@183
   286
USAGE: ./configure [OPTION]...
yann@183
   287
yann@183
   288
Defaults for the options are specified in brackets.
yann@183
   289
yann@183
   290
Configuration:
yann@1105
   291
  -h, --help              display this help and exit
yann@1311
   292
      --force             force configure to continue, even in case
yann@1311
   293
                          some pre-requisites are missing
yann@615
   294
yann@615
   295
Installation directories:
yann@185
   296
  --prefix=PREFIX         install files in PREFIX [${PREFIX_DEFAULT}]
yann@285
   297
  --local                 don't install, and use current directory
yann@183
   298
yann@183
   299
By default, \`make install' will install all the files in
yann@183
   300
\`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
yann@183
   301
an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
yann@183
   302
for instance \`--prefix=\${HOME}'.
yann@183
   303
yann@183
   304
For better control, use the options below.
yann@183
   305
yann@183
   306
Fine tuning of the installation directories:
yann@683
   307
  --bindir=DIR            user executables [PREFIX/bin]
yann@683
   308
  --libdir=DIR            object code libraries [PREFIX/lib]
yann@683
   309
  --docdir=DIR            info documentation [PREFIX/share/doc]
yann@683
   310
  --mandir=DIR            man documentation [PREFIX/share/man]
yann@614
   311
yann@614
   312
Optional Features:
yann@1140
   313
  --with-install=PATH     Specify the full PATH to GNU install
yann@1311
   314
  --with-make=PATH        Specify the full PATH to GNU make >= 3.80
yann@1140
   315
  --with-grep=PATH        Specify the full PATH to GNU grep
yann@1140
   316
  --with-sed=PATH         Specify the full PATH to GNU sed
yann@1140
   317
  --with-bash=PATH        Specify the full PATH to bash >= 3.0
yann@183
   318
__EOF__
yann@183
   319
}
yann@183
   320
yann@376
   321
#---------------------------------------------------------------------
yann@376
   322
# Set user's options
yann@376
   323
yann@182
   324
while [ $# -ne 0 ]; do
yann@182
   325
    case "$1" in
yann@1297
   326
        --local)    LOCAL_set="y"; shift;;
yann@182
   327
        --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
yann@182
   328
        --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
yann@182
   329
        --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
yann@182
   330
        --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
yann@182
   331
        --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
yann@1140
   332
        --with-*)   set_tool   "$1" "$2" && shift || shift 2;;
yann@1311
   333
        --force)    FORCE=1; shift;;
yann@183
   334
        --help|-h)  do_help; exit 0;;
blueness@1739
   335
        # Skip, auto-stuff compatibility
blueness@1739
   336
        --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
blueness@1739
   337
        --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir)             shift 2;;
yann@1333
   338
        *)          printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
yann@182
   339
    esac
yann@182
   340
done
yann@182
   341
yann@641
   342
# Use defaults
yann@185
   343
[ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
yann@641
   344
yann@641
   345
# Special case when installing locally
yann@1297
   346
if [ "${LOCAL_set}" = "y" ]; then
yann@1105
   347
    set_prefix "" "$( pwd )"
yann@1105
   348
    set_bindir "" "$( pwd )"
yann@1105
   349
    set_libdir "" "$( pwd )"
yann@1105
   350
    set_docdir "" "$( pwd )/docs"
yann@1105
   351
    set_mandir "" "$( pwd )/docs"
yann@285
   352
fi
yann@183
   353
yann@376
   354
#---------------------------------------------------------------------
yann@1140
   355
# Some sanity checks, now
yann@1106
   356
yann@1560
   357
# We check for grep and sed manually, because they are used in check_for()
yann@1140
   358
printf "Checking for 'grep'... "
yann@1140
   359
if [ -n "${grep}" ]; then
yann@1333
   360
    printf "${grep} (cached)\n"
yann@1140
   361
else
yann@1140
   362
    grep="$( which grep 2>/dev/null )"
yann@1187
   363
    if [ -z "${grep}" ]; then
yann@1333
   364
        printf "not found\n"
yann@1187
   365
    else
yann@1333
   366
        printf "${grep}\n"
yann@1187
   367
        printf "Checking whether '${grep}' supports -E... "
yann@1187
   368
        if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
yann@1333
   369
            printf "yes\n"
yann@1187
   370
        else
yann@1333
   371
            printf "no\n"
yann@1187
   372
            grep=
yann@1187
   373
        fi
yann@1187
   374
    fi
yann@1106
   375
fi
yann@1187
   376
if [ -z "${grep}" ]; then
yann@1333
   377
    printf "Either you are missing entirely the needed tool,\n"
yann@1333
   378
    printf "or the version you have is too old.\n"
yann@1333
   379
    printf "You can give the path to this tool using: --with-grep=PATH\n"
yann@1187
   380
    do_error "Bailing out..."
yann@1140
   381
fi
yann@1311
   382
add_to_var_list grep
yann@1140
   383
yann@1140
   384
printf "Checking for 'sed'... "
yann@1140
   385
if [ -n "${sed}" ]; then
yann@1333
   386
    printf "${sed} (cached)\n"
yann@1140
   387
else
yann@1140
   388
    sed="$( which sed 2>/dev/null )"
yann@1187
   389
    if [ -z "${sed}" ]; then
yann@1333
   390
        printf "not found\n"
yann@1187
   391
    else
yann@1333
   392
        printf "${sed}\n"
rpjday@1288
   393
        printf "Checking whether '${sed}' supports -i and -e... "
yann@1187
   394
        touch .ct-ng.sed.test
yann@1187
   395
        if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
yann@1333
   396
            printf "yes\n"
yann@1187
   397
        else
yann@1333
   398
            printf "no\n"
yann@1187
   399
            sed=
yann@1187
   400
        fi
yann@1187
   401
        rm -f .ct-ng.sed.test
yann@1187
   402
    fi
yann@1140
   403
fi
yann@1187
   404
if [ -z "${sed}" ]; then
yann@1333
   405
    printf "Either you are missing entirely the needed tool,\n"
yann@1333
   406
    printf "or the version you have is too old.\n"
yann@1333
   407
    printf "You can give the path to this tool using: --with-sed=PATH\n"
yann@1187
   408
    do_error "Bailing out..."
yann@1140
   409
fi
yann@1311
   410
add_to_var_list sed
yann@1140
   411
yann@1311
   412
# The regular list of tools we can now easily check for
yann@1311
   413
has_or_abort prog=bash                              \
yann@1311
   414
             var=bash                               \
yann@1477
   415
             ver='^GNU bash, version (3\.[1-9]|4)'  \
yann@1477
   416
             err="'bash' 3.1 or above was not found"
yann@1311
   417
has_or_abort prog=cut
yann@1311
   418
has_or_abort prog=install var=install
yann@1311
   419
has_or_abort prog=make                                  \
yann@1311
   420
             var=make                                   \
yann@1311
   421
             ver='^GNU Make (3.[89][[:digit:]]|[4-9])'  \
yann@1311
   422
             err="GNU 'make' 3.80 or above was not found"
yann@1311
   423
has_or_abort prog=gcc
yann@1431
   424
has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
yann@1311
   425
has_or_abort prog=bison
yann@1311
   426
has_or_abort prog=flex
yann@1311
   427
has_or_abort prog=makeinfo
yann@1311
   428
has_or_abort prog=automake                                                      \
oron@1432
   429
             ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)'    \
yann@1311
   430
             err="'automake' 1.10 or above was not found"
yann@1311
   431
has_or_abort prog=libtool                                                                           \
titus@1969
   432
             var=libtool                                                                            \
yann@1311
   433
             ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)'   \
yann@1311
   434
             err="'libtool' 1.5.26 or above was not found"
titus@1957
   435
has_or_abort prog=stat
yann@2203
   436
has_or_abort prog="curl wget"
yann@1347
   437
has_or_abort prog=cvs
yann@1311
   438
has_or_abort prog=patch
yann@1311
   439
has_or_abort prog=tar
yann@1311
   440
has_or_abort prog=gzip
yann@1311
   441
has_or_abort prog=bzip2
yann@1311
   442
has_or_abort prog=lzma
yann@1313
   443
has_or_abort prog=readlink
titus@1962
   444
has_or_abort prog=objcopy var=objcopy
titus@1962
   445
has_or_abort prog=objdump var=objdump
titus@1962
   446
has_or_abort prog=readelf var=readelf
titus@1962
   447
has_or_abort prog=patch var=patch
yann@1311
   448
yann@2525
   449
# Host system checks
yann@2525
   450
yann@2525
   451
printf "Checking for host system... "
yann@2525
   452
host="$( uname -s )"
yann@2525
   453
printf "%s\n" "${host}"
yann@2525
   454
case "${host}" in
yann@2525
   455
    Linux)  ;;
yann@2525
   456
    Cygwin) ;;
yann@2525
   457
    *)
yann@2525
   458
        printf " * Runing under %s is not fully tested\n" "${host}"
yann@2525
   459
        printf " * You may encounter some weird behavior\n"
yann@2525
   460
        ;;
yann@2525
   461
esac
yann@2525
   462
yann@2526
   463
printf "Checking if static linking is possible... "
yann@2526
   464
static_link_ok=""
yann@2526
   465
case "${host}" in
yann@2526
   466
    Darwin) ;;
yann@2526
   467
    *)  tmp=.static.tmp
yann@2526
   468
        if gcc -xc - -static -o "${tmp}" >/dev/null 2>&1<<-_EOF_
yann@2526
   469
				int main() { return 0; }
yann@2526
   470
			_EOF_
yann@2526
   471
        then
yann@2526
   472
            static_link_ok="y"
yann@2526
   473
        fi
yann@2526
   474
        rm -f "${tmp}"
yann@2526
   475
        ;;
yann@2526
   476
esac
yann@2526
   477
if [ "${static_link_ok}" = "y" ]; then
yann@2526
   478
    printf "yes\n"
yann@2526
   479
else
yann@2526
   480
    printf "no\n"
yann@2526
   481
    printf " * An optional host feature is missing, some features will be disabled:\n"
yann@2526
   482
    printf " * - It will not be possible to statically link toolchain's binaries\n"
yann@2526
   483
fi
yann@2526
   484
add_to_kconfig_list static_link_ok
yann@2526
   485
yann@2526
   486
# Library checks
yann@2527
   487
libs_exts="so dylib a"
yann@2527
   488
yann@2509
   489
ncurses_hdrs="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"
yann@2527
   490
ncurses_libs="libncursesw libncurses libcurses"
yann@2509
   491
has_or_abort lib="${ncurses_libs}"                                          \
yann@2527
   492
             lib_exts="${libs_exts}"                                        \
yann@2509
   493
             inc="${ncurses_hdrs}"                                          \
yann@2506
   494
             err="The 'ncurses' library is needed fo the menuconfig frontend"
yann@1106
   495
yann@2527
   496
has_or_abort lib="libstdc++"            \
yann@2527
   497
             lib_exts="${libs_exts}"    \
yann@2506
   498
             err="The 'libstdc++' library is needed to build gcc"
yann@2499
   499
yann@2500
   500
# Yes, we may be checking twice for libstdc++.a
yann@2500
   501
# The first is because we need one instance of libstdc++ (shared or static)
yann@2500
   502
# because it is needed for PPL; the second is because the static version is
yann@2500
   503
# required for static-linking, and if missing, the option is removed.
yann@2527
   504
has_or_warn  lib="libstdc++"    \
yann@2527
   505
             lib_exts="a"       \
yann@2500
   506
             err="static 'libstdc++' is needed to statically link the toolchain's executables" \
yann@2500
   507
             kconfig=has_static_libstdcxx
yann@2500
   508
yann@2527
   509
has_or_warn  inc="expat.h"              \
yann@2527
   510
             lib="libexpat"             \
yann@2527
   511
             lib_exts="${libs_exts}"    \
benoit@2508
   512
             err="The 'expat' header file and library are needed to link cross-gdb's executables" \
benoit@2508
   513
             kconfig=has_expat
benoit@2508
   514
benoit@2508
   515
# Yes, we may be checking twice for libexpat.a
benoit@2508
   516
# The first is because we need one instance of libexpat (shared or static)
benoit@2508
   517
# because it is needed for cross-gdb; the second is because the static version
benoit@2508
   518
# is required for static-linking, and if missing, the option is removed.
yann@2527
   519
has_or_warn  lib="libexpat" \
yann@2527
   520
             lib_exts="a"   \
benoit@2508
   521
             err="static 'expat' is needed to statically link cross-gdb's executables" \
benoit@2508
   522
             kconfig=has_static_expat
benoit@2508
   523
benoit@2508
   524
for v in 7 6 5 4; do
yann@2527
   525
    python_incs="${python_incs} python2.${v}/Python.h"
yann@2527
   526
    python_libs="${python_libs} libpython2.${v}"
benoit@2508
   527
done
yann@2527
   528
has_or_warn  inc="${python_incs}"       \
yann@2527
   529
             lib="${python_libs}"       \
yann@2527
   530
             lib_exts="${libs_exts}"    \
benoit@2508
   531
             err="The 'python' header file and library are needed for some features of cross-gdb"
benoit@2508
   532
yann@1106
   533
#---------------------------------------------------------------------
yann@1106
   534
# Compute the version string
yann@376
   535
yann@1576
   536
# If this version is n hg clone, try to get the revision number
yann@435
   537
# If we can't get the revision number, use date
yann@2498
   538
printf "\nComputing version string... "
yann@435
   539
case "${VERSION}" in
Yann@1409
   540
    *+hg|hg)
yann@1740
   541
        REVISION="$( hg id -n 2>/dev/null || true )"
yann@1105
   542
        case "${REVISION}" in
Yann@1409
   543
            "")
yann@1105
   544
                VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
yann@1105
   545
            *)
yann@1430
   546
                VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
yann@1105
   547
                ;;
yann@1105
   548
        esac
yann@1105
   549
        # Arrange to have no / in the directory name, no need to create an
yann@1105
   550
        # arbitrarily deep directory structure
yann@1333
   551
        VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
yann@444
   552
        ;;
yann@435
   553
esac
yann@1740
   554
printf "${VERSION}\n"
yann@435
   555
yann@1106
   556
#---------------------------------------------------------------------
yann@1106
   557
# Compute and check install paths
yann@1106
   558
yann@614
   559
# Now we have the version string, we can build up the paths
yann@554
   560
[ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
yann@1660
   561
[ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
yann@1660
   562
[ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
yann@2026
   563
[ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
yann@554
   564
yann@1660
   565
# Install support files in our own sub-dir, so as not to mangle (system)
yann@1660
   566
# files and dirs, but only if not --local
yann@1660
   567
if [ -z "${LOCAL_set}" ]; then
yann@1660
   568
    LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
yann@1660
   569
    DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
yann@1660
   570
fi
yann@1660
   571
yann@1047
   572
# Check that install PATHs are absolute
yann@1047
   573
for p in BIN LIB DOC MAN; do
yann@1105
   574
    var="${p}DIR"
yann@1105
   575
    eval v='"${'"${var}"'}"'
yann@1105
   576
    case "${v}" in
yann@1105
   577
        /*) ;;
yann@1105
   578
        *)  do_error "'${var}' is not an absolute path: '${v}'"
yann@1105
   579
    esac
yann@1047
   580
done
yann@1047
   581
yann@1106
   582
#---------------------------------------------------------------------
yann@1106
   583
# That's all, folks!
yann@614
   584
yann@641
   585
printf "Building up Makefile... "
yann@1140
   586
var_sed="$( for var_name in ${var_list}; do
yann@1140
   587
                eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
yann@2481
   588
            done
yann@1140
   589
          )"
yann@2481
   590
kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
yann@2481
   591
                                  eval printf \"${k_name}=\${${k_name}} \"
yann@2481
   592
                              done
yann@2481
   593
                            )/"
yann@2481
   594
"${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g"       \
yann@2481
   595
            -e "s,@@LIBDIR@@,${LIBDIR},g"       \
yann@2481
   596
            -e "s,@@DOCDIR@@,${DOCDIR},g"       \
yann@2481
   597
            -e "s,@@MANDIR@@,${MANDIR},g"       \
yann@2481
   598
            -e "s,@@VERSION@@,${VERSION},g"     \
yann@2481
   599
            -e "s,@@DATE@@,${DATE},g"           \
yann@2481
   600
            -e "s,@@LOCAL@@,${LOCAL_set},g"     \
yann@2481
   601
            -e "${var_sed}"                     \
yann@2481
   602
            -e "${kconfig_sed}"                 \
yann@2481
   603
         Makefile.in                            \
yann@2481
   604
         >Makefile
yann@673
   605
echo "done"
yann@185
   606
yann@185
   607
cat <<__EOF__
yann@673
   608
yann@197
   609
crosstool-NG configured as follows:
yann@554
   610
  PREFIX='${PREFIX}'
yann@554
   611
  BINDIR='${BINDIR}'
yann@554
   612
  LIBDIR='${LIBDIR}'
yann@554
   613
  DOCDIR='${DOCDIR}'
yann@554
   614
  MANDIR='${MANDIR}'
yann@1106
   615
yann@1106
   616
Now run:
yann@1106
   617
  make
yann@185
   618
__EOF__
yann@1298
   619
if [ "${LOCAL_set}" != "y" ]; then
yann@1297
   620
    printf "  make install\n"
yann@1297
   621
fi