-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmakedeps.yash
78 lines (69 loc) · 2.01 KB
/
makedeps.yash
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
67
68
69
70
71
72
73
74
75
76
77
78
# This script updates *.d files.
# (C) 2007-2020 magicant
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if [ -z "${YASH_VERSION-}" ]
then
printf '%s: This script must be executed by yash.\n' "$0" >&2
exit 126
fi
check () {
if ! [ -f "$1.d" ] || ! [ -s "$1.d" ] || [ "$1.c" -nt "$1.d" ]
then
return 1
fi
for dep in $(sed -e '1s/^.*://' -e 's/\\$//' "$1.d")
do
if ! [ -f "$dep" ]
then
printf '%s: "%s" depends on non-existent file "%s".\n' \
"$0" "$1.d" "$dep" >&2
exit 1
fi
if [ "$dep" -nt "$1.d" ]
then
return 1
fi
done
return 0
}
for file do
case $file in
(*.c)
if ! [ -f "$file" ]
then
printf '%s: "%s" is not a regular file.\n' "$0" "$file" >&2
exit 1
fi
file=${file%.c}
if ! check "$file"
then
printf '%s -std=c99 -MM "%s.c" >|"%s.d"\n' "${CC-gcc}" "$file" "$file"
if ${CC-gcc} -std=c99 -MM "${file}.c" >|"${file}.d"
then
:
else
exitstatus=$?
printf '%s: cannot update "%s".\n' "$0" "${file}.d" >&2
exit "$exitstatus"
fi
fi
;;
(*)
printf '%s: "%s" is not a C source file.\n' "$0" "$file" >&2
exit 1
;;
esac
done
# vim: set ft=sh ts=8 sts=4 sw=4 et tw=80: