summaryrefslogtreecommitdiff
path: root/dviware/umddvi/misc/getdep.sh
blob: 348df53ffdfea3741ae6675e15a19affab573ecc (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
: getdep - get dependency lists.

: change ":" comments to "#" comments if your shell supports those;
: the result will run faster.

: find cpp
cpp=unknown
for where in /lib /usr/lib /bin /usr/bin; do
	if test -f $where/cpp; then cpp=$where/cpp; break; fi
done
if test $cpp = unknown; then
	echo "I cannot find cpp, sorry" 1>&2; exit 1
fi

: handle arguments
incl=
for i
do
	case "$i" in
	-I*)
		incl="$incl $i";;
	*)
		: assume source file
		: put '$dep' in front of dependencies
		dep=`echo "$i" | sed -e 's,/,\\\\/,g' -e 's/\.c$/.o/'`
		: Find includes, remove leading numerics, remove ./,
		: remove double quotes, and remove trailing numerics.
		: Sort that, discarding duplicates, and add '$dep'.
		$cpp $incl "$i" | grep "^#" |
		sed -e 's/# [0-9]* //' -e 's,"./,",' -e 's/"\(.*\)"/\1/' \
		    -e 's/ [ 0-9]*$//' |
		sort -u | sed -e "s/^/$dep: /";;
	esac
done