2 # usage: ifchange target temporary
4 # Used in generating revision.h via Makefiles.
8 usage: $0 [options] target new-file
10 --timestamp[=file] touch timestamp file. (default: prefixed with ".time".
11 under the directory of the target)
12 --keep[=suffix] keep old file with suffix. (default: '.old')
13 --empty assume unchanged if the new file is empty.
14 --color[=always|auto|never] colorize output.
23 until [ $# -eq 0 ]; do
33 timestamp
=`expr \( "$1" : '[^=]*=\(.*\)' \)`
39 keepsuffix
=`expr \( "$1" : '[^=]*=\(.*\)' \)`
48 color
=`expr \( "$1" : '[^=]*=\(.*\)' \)`
58 echo "$0: unknown option: $1" 1>&2
68 if [ "$#" != 2 ]; then
75 if [ "$temp" = - ]; then
78 trap 'rm -f "$temp"' 0
81 msg_begin
= msg_unchanged
= msg_updated
= msg_reset
=
82 if [ "$color" = always
-o \
( "$color" = auto
-a -t 1 \
) ]; then
84 case "`tput smso 2>/dev/null`" in
86 if [ ${TEST_COLORS:+set} ]; then
87 msg_unchanged
=`expr ":$TEST_COLORS:" : ".*:pass=\([^:]*\):"` ||
:
88 msg_updated
=`expr ":$TEST_COLORS:" : ".*:fail=\([^:]*\):"` ||
:
90 msg_unchanged
="${msg_begin}${msg_unchanged:-32}m"
91 msg_updated
="${msg_begin}${msg_updated:-31;1}m"
92 msg_reset
="${msg_begin}m"
99 case "$target" in */*) targetdir
=`dirname "$target"`;; esac
100 if [ -f "$target" -a ! -${empty:+f}${empty:-s} "$temp" ] ||
cmp "$target" "$temp" >/dev
/null
2>&1; then
101 echo "$target ${msg_unchanged}unchanged${msg_reset}"
104 echo "$target ${msg_updated}updated${msg_reset}"
105 [ x
"${targetdir}" = x -o -d "${targetdir}" ] || mkdir -p "${targetdir}"
106 [ x
"${keepsuffix}" != x -a -f "$target" ] && mv -f "$target" "${target}${keepsuffix}"
107 mv -f "$temp" "$target"
110 if [ -n "${timestamp}" ]; then
111 if [ x
"${timestamp}" = x.
]; then
112 if [ x
"$targetdir" = x
]; then
113 timestamp
=.
time.
"$target"
115 timestamp
="$targetdir"/.
time.
`basename "$target"`