blob: 6cdc7c4fc51ffdeb048b7ef78821d61f43cdb172 (
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
set -eu
cmdfile=$1
output=$2
description=$3
shift 3
rebuild=false
if [ ! -e "$output" ] || [ ! -e "$cmdfile" ]; then
rebuild=true
fi
while [ "$#" -gt 0 ] && [ "$1" != "--" ]; do
prerequisite=$1
shift
if [ "$prerequisite" != FORCE ] && [ -e "$prerequisite" ] && \
[ "$prerequisite" -nt "$output" ]; then
rebuild=true
fi
done
[ "$#" -gt 0 ] || { echo "run-if-changed: missing --" >&2; exit 2; }
shift
signature=$(printf '%s\0' "$@" | cksum)
old_signature=
if [ -e "$cmdfile" ]; then
old_signature=$(cat "$cmdfile")
fi
if [ "$signature" != "$old_signature" ]; then
rebuild=true
fi
if [ "$rebuild" = true ]; then
printf ' %s\n' "$description"
mkdir -p "$(dirname "$output")" "$(dirname "$cmdfile")"
"$@"
tmp="$cmdfile.tmp.$$"
printf '%s\n' "$signature" > "$tmp"
mv -f "$tmp" "$cmdfile"
fi
|