diff options
author | Alexey Neyman <stilor@att.net> | 2017-03-20 23:01:44 -0700 |
---|---|---|
committer | Alexey Neyman <stilor@att.net> | 2017-03-21 14:03:31 -0700 |
commit | 3906acc00779dd31df84d4f555ecbc0d920e89f3 (patch) | |
tree | ac69867347a99d54203e77dd3f8d373fdbd6dbbd /maintainer | |
parent | 80daed99de7fb7f3b7a42f8bfd169fa9a44b63f0 (diff) | |
download | crosstool-ng-3906acc00779dd31df84d4f555ecbc0d920e89f3.tar.gz crosstool-ng-3906acc00779dd31df84d4f555ecbc0d920e89f3.tar.bz2 crosstool-ng-3906acc00779dd31df84d4f555ecbc0d920e89f3.zip |
Move some scripts to a new directory, maintainer
... which are not of much interest to the end user.
Signed-off-by: Alexey Neyman <stilor@att.net>
Diffstat (limited to 'maintainer')
-rwxr-xr-x | maintainer/addToolVersion.sh | 238 | ||||
-rwxr-xr-x | maintainer/patch-renumber.sh | 68 | ||||
-rwxr-xr-x | maintainer/patch-rework.sh | 196 |
3 files changed, 502 insertions, 0 deletions
diff --git a/maintainer/addToolVersion.sh b/maintainer/addToolVersion.sh new file mode 100755 index 00000000..38c2e552 --- /dev/null +++ b/maintainer/addToolVersion.sh @@ -0,0 +1,238 @@ +#!/bin/sh +set -e + +# Adds a new version to one of the toolchain component +myname="$0" + +# Parse the tools' paths configuration +# It is expected that this script is only to be run from the +# source directory of crosstool-NG, so it is trivial to find +# paths.sh (we can't use ". paths.sh", as POSIX states that +# $PATH should be searched for, and $PATH most probably doe +# not include "."), hence the "./". +. "./paths.sh" + +doHelp() { + cat <<-EOF + Usage: ${myname} <--tool> <[options] version [...]> ... + 'tool' in one of: + gcc, binutils, glibc, uClibc, uClibc-ng, newlib, linux, gdb, + duma, strace, ltrace, libelf, gmp, mpfr, isl, cloog, mpc, + mingw-w64, expat, ncurses, musl, gettext, zlib, libiconv + + Valid options for all tools: + --stable, -s, +x (default) + mark the version as being stable (as opposed to experimental, below) + + --experimental, -x, +s + mark the version as being experimental (as opposed to stable, above) + + --current, -c, +o (default) + mark the version as being cuurent (as opposed to obsolete, below) + + --obsolete, -o, +c + mark the version as being obsolete (as opposed to current, above) + + Note: setting a new tool resets to the defaults: 'stable' and 'current'. + + 'version' is a valid version for the specified tool. + + Examples: + add stable current version 2.6.19.2 to linux kernel: + ${myname} --linux 2.6.19.2 + + add experimental obsolete version 2.3.5 and stable current versions 2.6.1 + and 2.6.2 to glibc, add stable obsolete version 3.3.3 to gcc: + ${myname} --glibc -x -o 2.3.5 -s -c 2.6.1 2.6.2 --gcc -o 3.3.3 +EOF +} + +# Extract field $3 from version $1 with separator $2 +getVersionField() { + local version="$1" + local sep="$2" + local field="$3" + + echo "${version}${sep}${sep}${sep}${sep}" |cut -d ${sep} -f ${field} +} + +# Effectively add a version to the specified tool +# $cat : tool category +# $tool : tool name +# $tool_prefix : tool directory prefix +# $EXP : set to non empty if experimental, to empty otherwise +# OBS : set to non empty if obsolete, to empty otherwise +# $1 : version string to add +addToolVersion() { + local version="$1" + local file="$2" + local config_ver_option + local exp_obs_prompt + local deps v ver_M ver_m ver_p + local SedExpr1 SedExpr2 + + [ -f "${file}" ] || return 0 + + v=$(echo "${version}" |"${sed}" -r -e 's/-/_/g; s/\./_/g;') + + config_ver_option="${cat}_V_${v}" + + # Check for existing version: it can be legitimitate for an end-user + # to try adding a new version if the one he/she wants is not listed. + # But it can be the case where the version is hidden behind either one + # of EXPERIMENTAL or OBSOLETE, so warn if the version is already listed. + if ${grep} -E "^config ${config_ver_option}$" "${file}" >/dev/null 2>&1; then + echo "'${tool}': version '${version}' already present:" + ${grep} -A1 -B0 -n \ + -E "^(config ${config_ver_option}| {4}prompt \"${version}\")$" \ + "${file}" /dev/null + return 0 + fi + + SedExpr1="${SedExpr1}config ${config_ver_option}\n" + SedExpr1="${SedExpr1} bool\n" + SedExpr1="${SedExpr1} prompt \"${version}" + case "${EXP},${OBS}" in + ,) ;; + ,*) exp_obs_prompt=" (OBSOLETE)" + deps=" depends on OBSOLETE" + ;; + *,) exp_obs_prompt=" (EXPERIMENTAL)" + deps=" depends on EXPERIMENTAL" + ;; + *) exp_obs_prompt=" (EXPERIMENTAL, OBSOLETE)" + deps=" depends on EXPERIMENTAL \\&\\& OBSOLETE" + ;; + esac + [ -n "${exp_obs_prompt}" ] && SedExpr1="${SedExpr1}${exp_obs_prompt}" + SedExpr1="${SedExpr1}\"" + [ -n "${deps}" ] && SedExpr1="${SedExpr1}\n${deps}" + case "${tool}" in + gcc) + # Extract 'M'ajor and 'm'inor from version string + ver_M=$(getVersionField "${version}" . 1) + ver_m=$(getVersionField "${version}" . 2) + if [ ${ver_M} -ge 4 ] && [ ${ver_m} -ge 2 ]; then + SedExpr1="${SedExpr1}\n select CC_GCC_${ver_M}_${ver_m}" + fi + ;; + binutils) + # Extract 'M'ajor, 'm'inor, sometimes 'p'atch from version string + # TODO: Rework this + ver_M=$(getVersionField "${version}" . 1) + ver_m=$(getVersionField "${version}" . 2) + ver_p=$(getVersionField "${version}" . 3) + if [ ${ver_M} -eq 2 -a ${ver_m} -eq 27 ]; then + SedExpr1="${SedExpr1}\n select BINUTILS_2_27_or_later" + elif [ ${ver_M} -eq 2 -a ${ver_m} -eq 26 ]; then + SedExpr1="${SedExpr1}\n select BINUTILS_2_26_or_later" + elif [ ${ver_M} -eq 2 -a ${ver_m} -eq 25 -a ${ver_p} -eq 1 ]; then + SedExpr1="${SedExpr1}\n select BINUTILS_2_25_1_or_later" + elif [ ${ver_M} -eq 2 -a ${ver_m} -eq 25 -a -z ${ver_p} ]; then + SedExpr1="${SedExpr1}\n select BINUTILS_2_25_or_later" + elif [ ${ver_M} -eq 2 -a ${ver_m} -eq 24 ]; then + SedExpr1="${SedExpr1}\n select BINUTILS_2_24_or_later" + elif [ ${ver_M} -eq 2 -a ${ver_m} -eq 23 -a ${ver_p} -eq 2 ]; then + SedExpr1="${SedExpr1}\n select BINUTILS_2_23_2_or_later" + fi + ;; + uClibc) + # uClibc-0.9.33.2 needs some love + ver_M=$(getVersionField "${version}" . 1) + ver_m=$(getVersionField "${version}" . 2) + ver_p=$(getVersionField "${version}" . 3) + if [ ${ver_M} -eq 0 -a ${ver_m} -eq 9 -a ${ver_p} -eq 33 ]; then + SedExpr1="${SedExpr1}\n select LIBC_UCLIBC_0_9_33_2_or_later" + fi + ;; + uClibc-ng) + # uClibc-ng-1.0.15 changed threading configuration, no longer compatible + # with the rest of uClibc gang. + ver_M=$(getVersionField "${version}" . 1) + ver_m=$(getVersionField "${version}" . 2) + ver_p=$(getVersionField "${version}" . 3) + if [ ${ver_M} -eq 1 -a ${ver_m} -eq 0 -a ${ver_p} -eq 15 ]; then + SedExpr1="${SedExpr1}\n select LIBC_UCLIBC_NG_1_0_15_or_later" + fi + ;; + gdb) + # gdb-7.0 and above have special handling + ver_M=$(getVersionField "${version}" . 1) + ver_m=$(getVersionField "${version}" . 2) + if [ ${ver_M} -ge 7 ]; then + if [ ${ver_m} -ge 2 ]; then + SedExpr1="${SedExpr1}\n select GDB_7_2_or_later" + else + SedExpr1="${SedExpr1}\n select GDB_7_0_or_later" + fi + fi + ;; + esac + SedExpr2=" default \"${version}\" if ${config_ver_option}" + "${sed}" -r -i -e 's/^(# CT_INSERT_VERSION_BELOW)$/\1\n\n'"${SedExpr1}"'/;' "${file}" + "${sed}" -r -i -e 's/^(# CT_INSERT_VERSION_STRING_BELOW)$/\1\n'"${SedExpr2}"'/;' "${file}" +} + +cat= +tool= +tool_prefix= +VERSION= +EXP= +OBS= + +if [ $# -eq 0 ]; then + doHelp + exit 1 +fi + +while [ $# -gt 0 ]; do + case "$1" in + # Tools: + --gcc) EXP=; OBS=; cat=CC_GCC; tool=gcc; tool_prefix=cc; dot2suffix=;; + --binutils) EXP=; OBS=; cat=BINUTILS; tool=binutils; tool_prefix=binutils; dot2suffix=;; + --glibc) EXP=; OBS=; cat=LIBC_GLIBC; tool=glibc; tool_prefix=libc; dot2suffix=;; + --uClibc) EXP=; OBS=; cat=LIBC_UCLIBC; tool=uClibc; tool_prefix=libc; dot2suffix=;; + --uClibc-ng)EXP=; OBS=; cat=LIBC_UCLIBC_NG; tool=uClibc; tool_prefix=libc; dot2suffix=;; + --newlib) EXP=; OBS=; cat=LIBC_NEWLIB; tool=newlib; tool_prefix=libc; dot2suffix=;; + --mingw-w64)EXP=; OBS=; cat=WINAPI; tool=mingw; tool_prefix=libc; dot2suffix=;; + --musl) EXP=; OBS=; cat=LIBC_MUSL; tool=musl; tool_prefix=libc; dot2suffix=;; + --linux) EXP=; OBS=; cat=KERNEL; tool=linux; tool_prefix=kernel; dot2suffix=;; + --gdb) EXP=; OBS=; cat=GDB; tool=gdb; tool_prefix=debug; dot2suffix=;; + --duma) EXP=; OBS=; cat=DUMA; tool=duma; tool_prefix=debug; dot2suffix=;; + --strace) EXP=; OBS=; cat=STRACE; tool=strace; tool_prefix=debug; dot2suffix=;; + --ltrace) EXP=; OBS=; cat=LTRACE; tool=ltrace; tool_prefix=debug; dot2suffix=;; + --gmp) EXP=; OBS=; cat=GMP; tool=gmp; tool_prefix=companion_libs; dot2suffix=;; + --mpfr) EXP=; OBS=; cat=MPFR; tool=mpfr; tool_prefix=companion_libs; dot2suffix=;; + --isl) EXP=; OBS=; cat=ISL; tool=isl; tool_prefix=companion_libs; dot2suffix=;; + --cloog) EXP=; OBS=; cat=CLOOG; tool=cloog; tool_prefix=companion_libs; dot2suffix=;; + --mpc) EXP=; OBS=; cat=MPC; tool=mpc; tool_prefix=companion_libs; dot2suffix=;; + --libelf) EXP=; OBS=; cat=LIBELF; tool=libelf; tool_prefix=companion_libs; dot2suffix=;; + --expat) EXP=; OBS=; cat=EXPAT; tool=expat; tool_prefix=companion_libs; dot2suffix=;; + --ncurses) EXP=; OBS=; cat=NCURSES; tool=ncurses; tool_prefix=companion_libs; dot2suffix=;; + --gettext) EXP=; OBS=; cat=GETTEXT; tool=gettext; tool_prefix=companion_libs; dot2suffix=;; + --libiconv) EXP=; OBS=; cat=LIBICONV; tool=libiconv; tool_prefix=companion_libs; dot2suffix=;; + --zlib) EXP=; OBS=; cat=ZLIB; tool=zlib; tool_prefix=companion_tools; dot2suffix=;; + --make) EXP=; OBS=; cat=MAKE; tool=make; tool_prefix=companion_tools; dot2suffix=;; + --m4) EXP=; OBS=; cat=M4; tool=m4; tool_prefix=companion_tools; dot2suffix=;; + --autoconf) EXP=; OBS=; cat=AUTOCONF; tool=autoconf; tool_prefix=companion_tools; dot2suffix=;; + --automake) EXP=; OBS=; cat=AUTOMAKE; tool=automake; tool_prefix=companion_tools; dot2suffix=;; + --libtool) EXP=; OBS=; cat=LIBTOOL; tool=libtool; tool_prefix=companion_tools; dot2suffix=;; + + # Tools options: + -x|--experimental|+s) EXP=1;; + -s|--stable|+x) EXP=;; + -o|--obsolete|+c) OBS=1;; + -c|--current|+o) OBS=;; + + # Misc: + -h|--help) doHelp; exit 0;; + -*) echo "Unknown option: '$1' (use -h/--help for help)."; exit 1;; + + # Version string: + *) [ -n "${tool}" ] || { doHelp; exit 1; } + file_base="config/${tool_prefix}/${tool}.in" + addToolVersion "$1" "${file_base}${dot2suffix}" + ;; + esac + shift +done diff --git a/maintainer/patch-renumber.sh b/maintainer/patch-renumber.sh new file mode 100755 index 00000000..c9650ce9 --- /dev/null +++ b/maintainer/patch-renumber.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# Yes, this intends to be a true POSIX script file. +set -e + +myname="$0" + +# Parse the tools' paths configuration +# It is expected that this script is only to be run from the +# source directory of crosstool-NG, so it is trivial to find +# paths.sh (we can't use ". paths.sh", as POSIX states that +# $PATH should be searched for, and $PATH most probably doe +# not include "."), hence the "./". +. "./paths.sh" + +doUsage() { + cat <<_EOF_ +Usage: ${myname} <src_dir> <dst_dir> <base> <inc> [sed_re] + Renumbers all patches found in 'src_dir', starting at 'base', with an + increment of 'inc', and puts the renumbered patches in 'dst_dir'. + Leading digits are replaced with the new indexes, and a subsequent '_' + is replaced with a '-'. + If 'sed_re' is given, it is interpreted as a valid sed expression, and + is be applied to the patch name. + If the environment variable FAKE is set to 'y', then nothing gets done, + the command to run is only be printed, and not executed (so you can + check beforehand). + 'dst_dir' must not yet exist. + Eg.: + patch-renumber.sh patches/gcc/4.2.3 patches/gcc/4.2.4 100 10 + patch-renumber.sh /some/dir/my-patches patches/gcc/4.3.1 100 10 's/(all[_-])*(gcc[-_])*//;' +_EOF_ +} + +[ $# -lt 4 -o $# -gt 5 ] && { doUsage; exit 1; } + +src="${1}" +dst="${2}" +cpt="${3}" +inc="${4}" +sed_re="${5}" +if [ ! -d "${src}" ]; then + printf "%s: '%s': not a directory\n" "${myname}" "${src}" + exit 1 +fi +if [ -d "${dst}" ]; then + printf "%s: '%s': directory already exists\n" "${myname}" "${dst}" + exit 1 +fi + +Q= +if [ -n "${FAKE}" ]; then + printf "%s: won't do anything: FAKE='%s'\n" "${myname}" "${FAKE}" + Q="echo" +fi + +${Q} mkdir -pv "${dst}" +for p in "${src}/"*.patch*; do + [ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; } + newname="$(printf "%03d-%s" \ + "${cpt}" \ + "$( basename "${p}" \ + |${sed} -r -e 's/^[[:digit:]]+[-_]//' \ + -e "${sed_re}" \ + )" \ + )" + ${Q} cp -v "${p}" "${dst}/${newname}" + cpt=$((cpt+inc)) +done diff --git a/maintainer/patch-rework.sh b/maintainer/patch-rework.sh new file mode 100755 index 00000000..d05d2c18 --- /dev/null +++ b/maintainer/patch-rework.sh @@ -0,0 +1,196 @@ +#!/bin/sh + +# Get our required options +base="$1" +src="$2" +dst="$3" +shift 3 + +# The remainder is for diff +diff="$@" + +do_help() { + cat <<-_EOF_ + ${0##*/}: transform a patchset of non-p1 patches into -p1 patches + + Usage: + ${0##*/} <basedir> <src> <dst> [diffopts ...] + + Where: + basedir + points to the directory of the component to patch + + src + points to the directory containing the existing patchset + to transform + + dst + points to the directory where to put transformed patches + + diffopts + optional options to pass to diff, for debug purposes. You + should not need it + + Example: + Transform Gentoo patches against gcc-4.4.2 (some of which are + -p0, -p1 or even -p2 patches) into all -p1 patches: + + tar xjf gcc-4.4.2.tar.bz2 + patch-rework.sh gcc-4.4.2 \\ + /path/to/gentoo/gcc/patches \\ + gcc-4.4.2.patches + _EOF_ +} + +# Sanity checks +if [ -z "${base}" \ + -o ! -d "${base}" \ + -o ! -d "${src}" \ + -o -e "${dst}" -a ! -d "${dst}" \ + ]; then + do_help + exit 1 +fi + +mkdir -p "${dst}" +base="${base%%/}" +src="$( cd "${src}"; pwd )" +dst="$( cd "${dst}"; pwd )" + +# This function checks that the files listed in the file in "$1" +# do exist, at the given depth-stripping level (aka diff -p#) +do_check_files_at_depth() { + local flist="$1" + local depth="$2" + local ret=0 # 0: OK, !0: KO + + exec 6<&0 + exec 7<"${flist}" + + while read f; do + f="$( echo "${f}" |sed -r -e "s:^([^/]+/){${depth}}::;" )" + [ -f "${f}" ] || ret=1 + done </dev/fd/7 + + exec 7<&- + exec <&6 + + return ${ret} +} + +# Iterate through patches +for p in "${src}/"*.patch; do + pname="$( basename "${p}" )" + + printf "Handling patch '${pname}'...\n" + + printf " creating reference..." + cp -a "${base}" "${base}.orig" + printf " done\n" + + printf " retrieving patch comment..." + comment="$( awk ' +BEGIN { mark=0; } +$0~/^diff --/ { nextfile; } +$1=="---" { mark=1; next; } +$1=="+++" && mark==1 { nextfile; } +{ mark=0; print; } +' "${p}" )" + printf " done\n" + + printf " creating patched file list..." + diffstat -f 4 -r 2 -u -p 0 "${p}" \ + |head -n -1 \ + |awk '{ for(i=NF;i>=NF-5;i--) { $(i) = ""; } print; }' \ + |sort \ + >"diffstat.orig" + printf " done\n" + + cd "${base}" + + # Check all files exist, up to depth 3 + printf " checking depth:" + d=0 + while [ $d -lt 4 ]; do + printf " ${d}" + if do_check_files_at_depth "../diffstat.orig" ${d}; then + printf " ok, using depth '${d}'\n" + break + fi + d=$((d + 1)) + done + if [ ${d} -ge 4 ]; then + printf "\n" + printf " checking depth failed\n" + read -p " --> enter patch depth (or Ctrl-C to abort): " d + fi + + # Store the original list of files touched by the patch, + # removing the $d leading components + sed -r -e "s:^([^/]+/){${d}}::;" "../diffstat.orig" >"${dst}/${pname}.diffstat.orig" + + # Apply the patch proper, and check it applied cleanly. + # We can't check with --dry-run because of patches that + # contain multiple accumulated patches onto a single file. + printf " applying patch..." + if ! patch -g0 -F1 -f -p${d} <"${p}" >"../patch.out" 2>&1; then + printf " ERROR\n\n" + cd - >/dev/null + printf "There was an error while applying:\n --> ${p} <--\n" + printf "'${base}' was restored to the state it was prior to applying this faulty patch.\n" + printf "Here's the 'patch' command, and its output:\n" + printf " ----8<----\n" + printf " patch -g0 -F1 -f -p${d} <'${p}'\n" + sed -r -e 's/^/ /;' "patch.out" + printf " ----8<----\n" + exit 1 + fi + printf " done\n" + + printf " removing '.orig' files..." + find . -type f -name '*.orig' -exec rm -f {} + + printf " done\n" + + cd - >/dev/null + + printf " re-diffing the patch..." + printf "%s\n\n" "${comment}" >"${dst}/${pname}" + diff -durN "${base}.orig" "${base}" >>"${dst}/${pname}" + printf " done\n" + + if [ -n "${diff}" ]; then + printf " applying diff filter..." + filterdiff -x "${diff}" "${dst}/${pname}" >"tmp-diff" + mv "tmp-diff" "${dst}/${pname}" + printf " done\n" + fi + + printf " creating new patched file list..." + diffstat -f 4 -r 2 -u -p 1 "${dst}/${pname}" \ + |head -n -1 \ + |awk '{ for(i=NF;i>=NF-5;i--) { $(i) = ""; } print; }' \ + |sort \ + >"${dst}/${pname}.diffstat.new" + printf " done\n" + + printf " removing temporary files/dirs..." + rm -f "patch.out" + rm -f "diffstat.tmp" + rm -f "diffstat.orig" + rm -rf "${base}.orig" + printf " done\n" +done + +# Scan all new patches to see if they touch +# more files than the original patches +printf "\nChecking resulting patchset:\n" +for p in "${dst}/"*.patch; do + pname="$( basename "${p}" )" + + if ! cmp "${p}.diffstat.orig" "${p}.diffstat.new" >/dev/null; then + printf " --> '${pname}' differ in touched files <--\n" + else + rm -f "${p}.diffstat.orig" "${p}.diffstat.new" + fi +done +printf " done.\n" |