forked from libxsmm/libxsmm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.state.sh
executable file
·67 lines (64 loc) · 2.51 KB
/
.state.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env sh
###############################################################################
# Copyright (c) Intel Corporation - All rights reserved. #
# This file is part of the LIBXSMM library. #
# #
# For information on the license, see the LICENSE file. #
# Further information: https://github.com/libxsmm/libxsmm/ #
# SPDX-License-Identifier: BSD-3-Clause #
###############################################################################
# Hans Pabst (Intel Corp.)
###############################################################################
# shellcheck disable=SC2086
MKDIR=$(command -v mkdir)
DIFF=$(command -v diff)
UNIQ=$(command -v uniq)
SED=$(command -v sed)
TR=$(command -v tr)
if [ "${MKDIR}" ] && [ "${SED}" ] && [ "${TR}" ] && [ "${DIFF}" ] && [ "${UNIQ}" ]; then
# ensure proper permissions
if [ "${UMASK}" ]; then
UMASK_CMD="umask ${UMASK};"
eval "${UMASK_CMD}"
fi
if [ "$1" ]; then
STATEFILE=$1/.state
${MKDIR} -p "$1"
shift
else
STATEFILE=.state
fi
STATE=$(${TR} '?' '\n' | ${TR} '"' \' | ${SED} -e 's/^ */\"/' -e 's/ */ /g' -e 's/ *$/\\n\"/')
TOUCH=$(command -v touch)
if [ -e "${STATEFILE}" ]; then
if [ "$@" ]; then
EXCLUDE="-e /\($(echo "$@" | ${SED} "s/[[:space:]][[:space:]]*/\\\|/g" | ${SED} "s/\\\|$//")\)/d"
fi
# BSD's diff does not support --unchanged-line-format=""
STATE_DIFF=$(printf "%s\n" "${STATE}" \
| ${DIFF} "${STATEFILE}" - 2>/dev/null | ${SED} -n 's/[<>] \(..*\)/\1/p' \
| ${SED} -e 's/=..*$//' -e 's/\"//g' -e '/^$/d' ${EXCLUDE} | ${UNIQ})
RESULT=$?
if [ "0" != "${RESULT}" ] || [ "${STATE_DIFF}" ]; then
if [ "" = "${NOSTATE}" ] || [ "0" = "${NOSTATE}" ]; then
printf "%s\n" "${STATE}" >"${STATEFILE}"
fi
echo "$0 ${STATE_DIFF}"
# only needed to execute body of .state-rule
if [ "${TOUCH}" ]; then ${TOUCH} "$0"; fi
fi
else # difference must not be determined
if [ "" = "${NOSTATE}" ] || [ "0" = "${NOSTATE}" ]; then
printf "%s\n" "${STATE}" >"${STATEFILE}"
fi
echo "$0"
# only needed to execute body of .state-rule
if [ "${TOUCH}" ]; then ${TOUCH} "$0"; fi
fi
elif [ ! "${DIFF}" ]; then
>&2 echo "ERROR: please install diffutils - diff command is missing!"
exit 1
else
>&2 echo "ERROR: missing prerequisites!"
exit 1
fi