aboutsummaryrefslogtreecommitdiffstats
path: root/unix/makepatch.sh
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2017-11-03 18:45:20 +0800
committerAaron LI <aly@aaronly.me>2017-11-03 18:45:20 +0800
commit5a8b44ee3328464a673c2be2e21873fb02f1425b (patch)
tree192c3cc96018a26a85ec470aad1f814ea989a947 /unix/makepatch.sh
parent08aa61a60172326f4ea70834cd28817c0c397421 (diff)
downloadatoolbox-5a8b44ee3328464a673c2be2e21873fb02f1425b.tar.bz2
Add several more collected scripts
Diffstat (limited to 'unix/makepatch.sh')
-rwxr-xr-xunix/makepatch.sh61
1 files changed, 61 insertions, 0 deletions
diff --git a/unix/makepatch.sh b/unix/makepatch.sh
new file mode 100755
index 0000000..86804ab
--- /dev/null
+++ b/unix/makepatch.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+#
+# Automatically make the patches for the updated files by find
+# the corresponding '*.orig' files through the given directory.
+#
+# Based on the 'makepatch' target of FreeBSD 'Mk/bsd.port.mk'.
+#
+#
+# Aaron LI
+# Created: 2015-10-13
+# Updated: 2015-12-07
+#
+# ChangeLog:
+# 2015-12-06:
+# * Drop option '-s' for `find`
+# 2015-12-07:
+# * Replace 'workdir' with 'srcdir'
+# * Make find to search 'srcdir' instead of '.'
+#
+
+case "$1" in
+ -[hH]*|--[hH]*)
+ echo "Usage: $0 [srcdir] [patchdir]"
+ echo ""
+ echo "Both 'srcdir' and 'patchdir' default to be ."
+ exit 1
+ ;;
+esac
+
+SRCDIR=${1:-.}
+PATCHDIR=${2:-.}
+
+if [ ! -d "${PATCHDIR}" ]; then
+ mkdir ${PATCHDIR}
+fi
+
+PATCH_PATH_SEPARATOR="_"
+
+for f in `find ${SRCDIR}/ -type f -name '*.orig'`; do
+ _SEEN="NO"
+ ORIG=${f#./}
+ NEW=${ORIG%.orig}
+ if cmp -s ${ORIG} ${NEW}; then
+ # The two files are identical
+ continue
+ fi
+ PATCH=`echo ${NEW} | sed -e \
+ "s|${PATCH_PATH_SEPARATOR}|&&|g" -e "s|/|${PATCH_PATH_SEPARATOR}|g"`
+ OUT="${PATCHDIR}/patch-${PATCH}"
+ if test -f "${OUT}"; then
+ echo WARNING: patch already exists: \"${OUT}\"
+ else
+ echo diff -udp ${ORIG} ${NEW} '>' ${OUT}
+ TZ=UTC diff -udp ${ORIG} ${NEW} | sed -e \
+ '/^---/s|\.[0-9]* +0000$| UTC|' -e \
+ '/^+++/s|\([[:blank:]][-0-9:.+]*\)*$||' > ${OUT}
+ fi
+done
+
+exit 0
+