scripts/patch-renumber.sh
author Bryan Hundven <bryanhundven@gmail.com>
Sun Jun 26 03:26:54 2011 -0700 (2011-06-26)
changeset 2515 364b06df9e3a
parent 1622 9ad2a3fd1fcc
child 2838 822af73497bf
permissions -rwxr-xr-x
glibc: Refactor startfiles/headers into do_libc_backend()

Refactor the contents of 'do_libc_start_files()' and 'do_libc()' into a
parameterized 'do_libc_backend()'. 'do_libc_start_files()' and 'do_libc()'
call 'do_libc_backend()' with either 'libc_mode=startfiles' or
'libc_mode=final' (respectively) so that the startfiles/headers and
the final libc builds are configured and built with the same options.

One example of where this is needed is when building a mips toolchain.
Previously, if you were building an n32 toolchain, you wouldn't have
noticed an issue, because if '-mabi' is not in CFLAGS, n32 is the
default:

http://sourceware.org/git/?p=glibc-ports.git;a=blob;f=sysdeps/mips/preconfigure;hb=HEAD

But when trying to build an o32 or n64 toolchain the build would
have failed. This is because (e)glibc expects "-mabi={o32,n32,n64}" to be
in CFLAGS, but was not previously provided in 'do_libc_start_files()'.
The build failure would happen in the shared-core gcc when it tries to
configure an n64 or o32 gcc with an n32 libc.

A simpler solution would have been to just add TARGET_CFLAGS to configure
in 'do_libc_start_files()', but this way makes configure and make
consistent for both steps.

Signed-off-by: Bryan Hundven <bryanhundven@gmail.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@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