yann@756: #!/bin/sh yann@756: # Yes, this intends to be a true POSIX script file. yann@1175: set -e yann@756: yann@756: myname="$0" yann@756: yann@1175: # Parse the tools' paths configuration yann@1623: # It is expected that this script is only to be run from the yann@1623: # source directory of crosstool-NG, so it is trivial to find yann@1623: # paths.mk (we can't use ". paths.mk", as POSIX states that yann@1623: # $PATH should be searched for, and $PATH most probably doe yann@1623: # not include "."), hence the "./". yann@1623: . "./paths.mk" yann@1175: yann@756: doUsage() { yann@756: cat <<_EOF_ yann@1622: Usage: ${myname} [sed_re] yann@1622: Renumbers all patches found in 'src_dir', starting at 'base', with an yann@1622: increment of 'inc', and puts the renumbered patches in 'dst_dir'. yann@1622: Leading digits are replaced with the new indexes, and a subsequent '_' yann@1622: is replaced with a '-'. yann@1608: If 'sed_re' is given, it is interpreted as a valid sed expression, and yann@1622: is be applied to the patch name. yann@1622: If the environment variable FAKE is set to 'y', then nothing gets done, yann@1622: the command to run is only be printed, and not executed (so you can yann@1622: check beforehand). yann@1622: 'dst_dir' must not yet exist. yann@1608: Eg.: yann@1622: patch-renumber.sh patches/gcc/4.2.3 patches/gcc/4.2.4 100 10 yann@1622: patch-renumber.sh /some/dir/my-patches patches/gcc/4.3.1 100 10 's/(all[_-])*(gcc[-_])*//;' yann@756: _EOF_ yann@756: } yann@756: yann@1622: [ $# -lt 4 -o $# -gt 5 ] && { doUsage; exit 1; } yann@756: yann@1622: src="${1}" yann@1622: dst="${2}" yann@1622: cpt="${3}" yann@1622: inc="${4}" yann@1622: sed_re="${5}" yann@1622: if [ ! -d "${src}" ]; then yann@1622: printf "%s: '%s': not a directory\n" "${myname}" "${src}" yann@1622: exit 1 yann@1622: fi yann@1622: if [ -d "${dst}" ]; then yann@1622: printf "%s: '%s': directory already exists\n" "${myname}" "${dst}" yann@1622: exit 1 yann@1608: fi yann@1608: yann@1622: Q= yann@1622: if [ -n "${FAKE}" ]; then yann@1622: printf "%s: won't do anything: FAKE='%s'\n" "${myname}" "${FAKE}" yann@1622: Q="echo" yann@1622: fi yann@1622: yann@1622: ${Q} mkdir -pv "${dst}" yann@1622: for p in "${src}/"*.patch*; do yann@756: [ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; } yann@1608: newname="$(printf "%03d-%s" \ yann@1608: "${cpt}" \ yann@1608: "$( basename "${p}" \ yann@1608: |"${sed}" -r -e 's/^[[:digit:]]+[-_]//' \ yann@1608: -e "${sed_re}" \ yann@1608: )" \ yann@1192: )" yann@1622: ${Q} cp -v "${p}" "${dst}/${newname}" yann@756: cpt=$((cpt+inc)) yann@756: done