scripts/patch-renumber.sh
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Sun May 11 23:43:52 2014 +0200 (2014-05-11)
changeset 3320 78af1c99bc6d
parent 1623 f935634ef900
permissions -rwxr-xr-x
scripts/functions: add target_endian_le and target_endian_be

We currently define target_endian_el and target_endian_eb to be the
tuple extension depending on endianness, defined to be respectively
'el' or 'eb' according to the endianness.

Some architecture do not use 'el' or 'eb', but use 'le' or 'be'.

Provide that as well, as two new variables: target_endian_le and
target_endian_be.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Cody P Schafer <dev@codyps.com>
yann@756
     1
#!/bin/sh
yann@756
     2
# Yes, this intends to be a true POSIX script file.
yann@1175
     3
set -e
yann@756
     4
yann@756
     5
myname="$0"
yann@756
     6
yann@1175
     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@2838
    10
# paths.sh (we can't use  ". paths.sh", 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@2838
    13
. "./paths.sh"
yann@1175
    14
yann@756
    15
doUsage() {
yann@756
    16
  cat <<_EOF_
yann@1622
    17
Usage: ${myname} <src_dir> <dst_dir> <base> <inc> [sed_re]
yann@1622
    18
    Renumbers all patches found in 'src_dir', starting at 'base', with an
yann@1622
    19
    increment of 'inc', and puts the renumbered patches in 'dst_dir'.
yann@1622
    20
    Leading digits are replaced with the new indexes, and a subsequent '_'
yann@1622
    21
    is replaced with a '-'.
yann@1608
    22
    If 'sed_re' is given, it is interpreted as a valid sed expression, and
yann@1622
    23
    is be applied to the patch name.
yann@1622
    24
    If the environment variable FAKE is set to 'y', then nothing gets done,
yann@1622
    25
    the command to run is only be printed, and not executed (so you can
yann@1622
    26
    check beforehand).
yann@1622
    27
    'dst_dir' must not yet exist.
yann@1608
    28
    Eg.:
yann@1622
    29
      patch-renumber.sh patches/gcc/4.2.3 patches/gcc/4.2.4 100 10
yann@1622
    30
      patch-renumber.sh /some/dir/my-patches patches/gcc/4.3.1 100 10 's/(all[_-])*(gcc[-_])*//;'
yann@756
    31
_EOF_
yann@756
    32
}
yann@756
    33
yann@1622
    34
[ $# -lt 4 -o $# -gt 5 ] && { doUsage; exit 1; }
yann@756
    35
yann@1622
    36
src="${1}"
yann@1622
    37
dst="${2}"
yann@1622
    38
cpt="${3}"
yann@1622
    39
inc="${4}"
yann@1622
    40
sed_re="${5}"
yann@1622
    41
if [ ! -d "${src}" ]; then
yann@1622
    42
    printf "%s: '%s': not a directory\n" "${myname}" "${src}"
yann@1622
    43
    exit 1
yann@1622
    44
fi
yann@1622
    45
if [ -d "${dst}" ]; then
yann@1622
    46
    printf "%s: '%s': directory already exists\n" "${myname}" "${dst}"
yann@1622
    47
    exit 1
yann@1608
    48
fi
yann@1608
    49
yann@1622
    50
Q=
yann@1622
    51
if [ -n "${FAKE}" ]; then
yann@1622
    52
    printf "%s: won't do anything: FAKE='%s'\n" "${myname}" "${FAKE}"
yann@1622
    53
    Q="echo"
yann@1622
    54
fi
yann@1622
    55
yann@1622
    56
${Q} mkdir -pv "${dst}"
yann@1622
    57
for p in "${src}/"*.patch*; do
yann@756
    58
    [ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; }
yann@1608
    59
    newname="$(printf "%03d-%s"                                     \
yann@1608
    60
                      "${cpt}"                                      \
yann@1608
    61
                      "$( basename "${p}"                           \
yann@1608
    62
                          |"${sed}" -r -e 's/^[[:digit:]]+[-_]//'   \
yann@1608
    63
                                       -e "${sed_re}"               \
yann@1608
    64
                        )"                                          \
yann@1192
    65
              )"
yann@1622
    66
    ${Q} cp -v "${p}" "${dst}/${newname}"
yann@756
    67
    cpt=$((cpt+inc))
yann@756
    68
done