scripts/addToolVersion.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Dec 30 15:36:22 2009 +0100 (2009-12-30)
changeset 1669 61edd9d19e3c
parent 1607 a119153ca777
child 1692 068c809cc646
permissions -rwxr-xr-x
scripts/functions: add aria2, a powerfull downloader

aria2 is a powerfull downloader that is capable of chunking and
parallel retrieval.

Due to li;itations in crosstool-NG retrieval facilities, it's not possible
to take fully advantage of aria2. It might happen that, in the future,
those limitations get lifted away, so we can take use features such as
parallel downloading from more than one server at the same time. For now,
it should still speed up downloads thanks to parallel downloading of chunks.
yann@1173
     1
#!/bin/sh
yann@1174
     2
set -e
yann@1
     3
yann@1
     4
# Adds a new version to one of the toolchain component
yann@1
     5
myname="$0"
yann@1
     6
yann@1174
     7
# Parse the tools' paths configuration
yann@1623
     8
# It is expected that this script is only to be run from the
yann@1623
     9
# source directory of crosstool-NG, so it is trivial to find
yann@1623
    10
# paths.mk (we can't use  ". paths.mk", as POSIX states that
yann@1623
    11
# $PATH should be searched for, and $PATH most probably doe
yann@1623
    12
# not include "."), hence the "./".
yann@1623
    13
. "./paths.mk"
yann@1174
    14
yann@1
    15
doHelp() {
yann@1
    16
    cat <<-EOF
yann@1173
    17
Usage: ${myname} <tool> <[options] version [...]> ...
yann@1
    18
  'tool' in one of:
yann@858
    19
    --gcc, --binutils, --glibc, --eglibc, --uClibc, --linux,
yann@245
    20
    --gdb, --dmalloc, --duma, --strace, --ltrace, --libelf
yann@1380
    21
    --gmp, --mpfr, --ppl, --cloog
yann@1
    22
yann@96
    23
  Valid options for all tools:
yann@1173
    24
    --stable, -s, +x   (default)
yann@1225
    25
      mark the version as being stable (as opposed to experimental, below)
yann@43
    26
yann@1173
    27
    --experimental, -x, +s
yann@1225
    28
      mark the version as being experimental (as opposed to stable, above)
yann@1173
    29
yann@1173
    30
    --current, -c, +o   (default)
yann@1225
    31
      mark the version as being cuurent (as opposed to obsolete, below)
yann@1173
    32
yann@1173
    33
    --obsolete, -o, +c
yann@1225
    34
      mark the version as being obsolete (as opposed to current, above)
yann@1173
    35
yann@1173
    36
  Note: setting a new tool resets to the defaults: 'stable' and 'current'.
yann@96
    37
yann@1
    38
  'version' is a valid version for the specified tool.
yann@1
    39
yann@1
    40
  Examples:
yann@1173
    41
    add stable current version 2.6.19.2 to linux kernel:
yann@858
    42
      ${myname} --linux 2.6.19.2
yann@1
    43
yann@1173
    44
    add experimental obsolete version 2.3.5 and stable current versions 2.6.1
yann@1173
    45
    and 2.6.2 to glibc, add stable obsolete version 3.3.3 to gcc:
yann@1173
    46
      ${myname} --glibc -x -o 2.3.5 -s -c 2.6.1 2.6.2 --gcc -o 3.3.3
yann@1
    47
EOF
yann@1
    48
}
yann@1
    49
yann@1173
    50
# Effectively add a version to the specified tool
yann@1173
    51
# $cat          : tool category
yann@1173
    52
# $tool         : tool name
yann@1173
    53
# $tool_prefix  : tool directory prefix
yann@1173
    54
# $EXP          : set to non empty if experimental, to empty otherwise
yann@1173
    55
# #OBS          : set to non empty if obsolete, to empty otherwise
yann@1173
    56
# $1            : version string to add
yann@1173
    57
addToolVersion() {
yann@1173
    58
    local version="$1"
yann@1173
    59
    local file
yann@1200
    60
    local config_ver_option
yann@1173
    61
    local exp_obs_prompt
yann@1173
    62
    local deps v ver_M ver_m
yann@1173
    63
    local SedExpr1 SedExpr2
yann@1173
    64
yann@1173
    65
    file="config/${tool_prefix}/${tool}.in"
yann@1174
    66
    v=$(echo "${version}" |"${sed}" -r -e 's/-/_/g; s/\./_/g;')
yann@1173
    67
yann@1200
    68
    config_ver_option="${cat}_V_${v}"
yann@1200
    69
yann@1200
    70
    # Check for existing version: it can be legitimitate for an end-user
yann@1200
    71
    # to try adding a new version if the one he/she wants is not listed.
yann@1200
    72
    # But it can be the case where the version is hidden behind either one
yann@1200
    73
    # of EXPERIMENTAL or OBSOLETE, so warn if the version is already listed.
yann@1200
    74
    if (GREP_OPTIONS= grep -E "^config ${config_ver_option}$" "${file}" >/dev/null 2>&1); then
yann@1200
    75
        echo "'${tool}': version '${version}' already present:"
yann@1200
    76
        GREP_OPTIONS= grep -A3 -B0 -E "^config ${config_ver_option}$" "${file}"
yann@1200
    77
        return 0
yann@1200
    78
    fi
yann@1200
    79
yann@1200
    80
    SedExpr1="${SedExpr1}config ${config_ver_option}\n"
yann@1173
    81
    SedExpr1="${SedExpr1}    bool\n"
yann@1173
    82
    SedExpr1="${SedExpr1}    prompt \"${version}"
yann@1173
    83
    case "${EXP},${OBS}" in
yann@1173
    84
        ,)  ;;
yann@1536
    85
        ,*) exp_obs_prompt=" (OBSOLETE)"
yann@1535
    86
            deps="    depends on OBSOLETE"
yann@1173
    87
            ;;
yann@1536
    88
        *,) exp_obs_prompt=" (EXPERIMENTAL)"
yann@1535
    89
            deps="    depends on EXPERIMENTAL"
yann@1173
    90
            ;;
yann@1536
    91
        *)  exp_obs_prompt=" (EXPERIMENTAL, OBSOLETE)"
yann@1535
    92
            deps="    depends on EXPERIMENTAL \\&\\& OBSOLETE"
yann@1173
    93
            ;;
yann@1173
    94
    esac
yann@1173
    95
    [ -n "${exp_obs_prompt}" ] && SedExpr1="${SedExpr1}${exp_obs_prompt}"
yann@1535
    96
    SedExpr1="${SedExpr1}\""
yann@1535
    97
    [ -n "${deps}" ] && SedExpr1="${SedExpr1}\n${deps}"
yann@1173
    98
    if [ "${tool}" = "gcc" ]; then
yann@1173
    99
        # Extract 'M'ajor and 'm'inor from version string
yann@1173
   100
        ver_M=$(echo "${version}...." |cut -d . -f 1)
yann@1173
   101
        ver_m=$(echo "${version}...." |cut -d . -f 2)
yann@1173
   102
        if [    ${ver_M} -gt 4                          \
yann@1173
   103
             -o \( ${ver_M} -eq 4 -a ${ver_m} -ge 3 \)  ]; then
yann@1535
   104
            SedExpr1="${SedExpr1}\n    select CC_GCC_4_3_or_later"
yann@1441
   105
        fi
yann@1441
   106
        if [    ${ver_M} -gt 4                          \
yann@1441
   107
             -o \( ${ver_M} -eq 4 -a ${ver_m} -ge 4 \)  ]; then
yann@1535
   108
            SedExpr1="${SedExpr1}\n    select CC_GCC_4_4_or_later"
yann@1173
   109
        fi
yann@1173
   110
    fi
yann@1173
   111
    SedExpr2="    default \"${version}\" if ${cat}_V_${v}"
yann@1542
   112
    "${sed}" -r -i -e 's/^(# CT_INSERT_VERSION_BELOW)$/\1\n\n'"${SedExpr1}"'/;' "${file}"
yann@1535
   113
    "${sed}" -r -i -e 's/^(# CT_INSERT_VERSION_STRING_BELOW)$/\1\n'"${SedExpr2}"'/;' "${file}"
yann@1173
   114
}
yann@1173
   115
yann@96
   116
cat=
yann@1
   117
tool=
yann@1
   118
tool_prefix=
yann@1
   119
VERSION=
yann@43
   120
EXP=
yann@96
   121
OBS=
yann@1
   122
yann@1173
   123
if [ $# -eq 0 ]; then
yann@1173
   124
    doHelp
yann@1173
   125
    exit 1
yann@1173
   126
fi
yann@1173
   127
yann@1173
   128
while [ $# -gt 0 ]; do
yann@1173
   129
    case "$1" in
yann@96
   130
        # Tools:
yann@1173
   131
        --gcc)      EXP=; OBS=; cat=CC;        tool=gcc;      tool_prefix=cc;;
yann@1607
   132
        --binutils) EXP=; OBS=; cat=BINUTILS;  tool=binutils; tool_prefix=binutils;;
yann@1173
   133
        --glibc)    EXP=; OBS=; cat=LIBC;      tool=glibc;    tool_prefix=libc;;
yann@1173
   134
        --eglibc)   EXP=; OBS=; cat=LIBC;      tool=eglibc;   tool_prefix=libc;;
yann@1173
   135
        --uClibc)   EXP=; OBS=; cat=LIBC;      tool=uClibc;   tool_prefix=libc;;
yann@1173
   136
        --linux)    EXP=; OBS=; cat=KERNEL;    tool=linux;    tool_prefix=kernel;;
yann@1173
   137
        --gdb)      EXP=; OBS=; cat=GDB;       tool=gdb;      tool_prefix=debug;;
yann@1173
   138
        --dmalloc)  EXP=; OBS=; cat=DMALLOC;   tool=dmalloc;  tool_prefix=debug;;
yann@1173
   139
        --duma)     EXP=; OBS=; cat=DUMA;      tool=duma;     tool_prefix=debug;;
yann@1173
   140
        --strace)   EXP=; OBS=; cat=STRACE;    tool=strace;   tool_prefix=debug;;
yann@1173
   141
        --ltrace)   EXP=; OBS=; cat=LTRACE;    tool=ltrace;   tool_prefix=debug;;
yann@1173
   142
        --libelf)   EXP=; OBS=; cat=LIBELF;    tool=libelf;   tool_prefix=tools;;
yann@1318
   143
        --gmp)      EXP=; OBS=; cat=GMP;       tool=gmp;      tool_prefix=companion_libs;;
yann@1318
   144
        --mpfr)     EXP=; OBS=; cat=MPFR;      tool=mpfr;     tool_prefix=companion_libs;;
yann@1324
   145
        --ppl)      EXP=; OBS=; cat=PPL;       tool=ppl;      tool_prefix=companion_libs;;
yann@1380
   146
        --cloog)    EXP=; OBS=; cat=CLOOG;     tool=cloog;    tool_prefix=companion_libs;;
yann@1173
   147
yann@96
   148
        # Tools options:
yann@1173
   149
        -x|--experimental|+s)   EXP=1;;
yann@1173
   150
        -s|--stable|+x)         EXP=;;
yann@1173
   151
        -o|--obsolete|+c)       OBS=1;;
yann@1173
   152
        -c|--current|+o)        OBS=;;
yann@1173
   153
yann@96
   154
        # Misc:
yann@1173
   155
        -h|--help)  doHelp; exit 0;;
yann@1173
   156
        -*)         echo "Unknown option: '$1' (use -h/--help for help)."; exit 1;;
yann@1173
   157
yann@1173
   158
        # Version string:
yann@1173
   159
        *)  [ -n "${tool}" ] || { doHelp; exit 1; }
yann@1173
   160
            addToolVersion "$1"
yann@1173
   161
            ;;
yann@1
   162
    esac
yann@1173
   163
    shift
yann@1
   164
done