configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Aug 19 22:53:48 2011 +0200 (2011-08-19)
changeset 2620 d9c5b3b75864
parent 2607 dda4742972e2
child 2621 00853d565edf
permissions -rwxr-xr-x
Makefile: introduce PROG_NAME to contain the 'ct-ng' executable name

With the upcomming --program-{prefix,suffix,transform-name} options,
we'll have a need to centralise the actual executable name, that is
now no longer be a constant.

Rather than spread the prefix/suffix through-out the code, just
centralise the name setting in one place. Beside, transform-name
would not be possible without setting the name at a single location.

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