-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreinplace-check
executable file
·90 lines (77 loc) · 2.18 KB
/
reinplace-check
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
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
readonly PAGER=${PAGER:-less}
readonly PAGER_DIFF=${PAGER_DIFF:-$PAGER}
readonly PATHFIX=$(make -V USES | grep pathfix >/dev/null; echo $?)
readonly PATHFILE=$(make -V PATHFIX_MAKEFILEIN)
readonly PKGNAME=$(make -V PKGNAME 2>/dev/null)
readonly cmd=${1:-check}
valid_reinplace_file() {
local filename path=$1 pattern
#TODO Makefile.in may be changed by REINPLACE_CMD too, fix it
if [ $PATHFIX -eq 0 ]; then
filename=$(basename "${path%.bak}")
for pattern in $PATHFIX_PATTERNS; do
[ "$filename" = "$pattern" ] && return 1
done
fi
case $path in *.libtool.bak|*ltmain.sh.bak) return 1 ;; esac
}
if [ "$cmd" != "check" -a "$cmd" != "show" ]; then
<< EOF >&2 cat
Usage: ${0##*/} [check]
${0##*/} show [patterns]
check - print files not modified by REINPLACE_CMD (default operation)
show - display diff(1) of modified files with names matching patterns or
all files if patterns was not specified
EOF
exit 1
fi
if [ ! "$PKGNAME" ]; then
echo "===> This is not port directory" >&2
exit 1
fi
flavors=$(make -V FLAVORS | sed 's,^ ,,')
if [ "$flavors" ]; then
for f in $flavors; do
[ -f "$(make FLAVOR=$f -V CONFIGURE_COOKIE)" ] || continue
wrkdirs="$wrkdirs $(basename "$(make FLAVOR=$f -V WRKDIR)")"
done
else
[ -f "$(make -V CONFIGURE_COOKIE)" ] &&
wrkdirs=$(basename "$(make -V WRKDIR)")
fi
if [ ! "$wrkdirs" ]; then
echo "===> No suitable work directory found, run make configure first" >&2
exit 1
fi
for dir in $wrkdirs; do
bak_files=$(find "$dir" -name "*.bak" -print)
[ "$bak_files" ] && files="$files $bak_files"
done
[ "$files" ] || exit 0
[ $PATHFIX -eq 0 ] &&
PATHFIX_PATTERNS=$(make -V PATHFIX_MAKEFILEIN -V PATHFIX_CMAKELISTSTXT)
if [ "$cmd" = "show" ]; then
shift
patterns=$*
for file in $files; do
valid_reinplace_file "$file" || continue
if [ "$patterns" ]; then
matched=0
for p in $patterns; do
case ${file%.bak} in *$p*)
matched=1
break
esac
done
[ $matched -eq 1 ] || continue
fi
diff -u "$file" "${file%.bak}"
done | $PAGER_DIFF
else
for file in $files; do
valid_reinplace_file "$file" || continue
cmp -s "$file" "${file%.bak}" &&
echo "File ${file%.bak} seems to be unmodified"
done
fi