configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Jun 27 21:03:40 2011 +0200 (2011-06-27)
changeset 2526 e5fb003a354c
parent 2525 00054087dab2
child 2527 a65f56df62de
permissions -rwxr-xr-x
configure: disable static linking on Darwin

Static liunking is not supported on Darwin, so hide the corresponding
options when the build machine is Darwin.

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