scripts/patch-renumber.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Mar 20 00:02:21 2011 +0100 (2011-03-20)
changeset 2339 730e2d63296b
parent 1622 9ad2a3fd1fcc
child 2838 822af73497bf
permissions -rwxr-xr-x
scripts: leave changelog in build dir, copy to install dir

Users tend to look for the build log in the current working directory,
rather than in the toolchain's installation dir. While bundling the build
log in the toolchain installation dir is nice for distribution and review,
it can be easier to have the build log readily available in the working
directory, as it is quicker to get to it.

So, the build log stays in the working directory until the toolchain is
completely and successfully built, and then a (compressed) copy is made.

Reported-by: Trevor Woerner <twoerner@gmail.com>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
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@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@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