scripts/addToolVersion.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Jan 06 18:42:41 2010 +0100 (2010-01-06)
changeset 1696 f04fb2d52023
parent 1692 068c809cc646
child 1721 4ff4eeb061e5
permissions -rwxr-xr-x
complibs/mpfr: add latest version 2.4.2

Note: the MPFR site happens to be down at the time I wrote
this message, and happens to be down quite often.

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