summaryrefslogtreecommitdiff
path: root/tool/ifchange
blob: 8bfca26703ce222ac5128e2a84e7bd3c02e74e38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
# usage: ifchange target temporary

unset timestamp
if [ "$1" = --timestamp ]; then
    timestamp=yes
    shift
fi
target="$1"
temp="$2"
if [ "$temp" = - ]; then
    temp="tmpdata$$.tmp~"
    cat > "$temp" || exit $?
    trap 'rm -f "$temp"' 0
fi
if cmp "$target" "$temp" >/dev/null 2>&1; then
    echo "$target unchanged"
    rm -f "$temp"
else
    echo "$target updated"
    mv -f "$temp" "$target"
fi
if [ $timestamp ]; then
    touch `dirname "$target"`/.time.`basename "$target"`
fi