1#!/bin/sh
2
3case "$AM_SRCDIR" in
4"")
5	AM_SRCDIR="."
6	;;
7*)
8	;;
9esac
10
11fix=n
12status=0
13case "$1" in
14"-fix")
15	fix=y
16	;;
17esac
18
19for inc in src/*.h; do
20	package=xcb-`basename $inc .h`
21	pcin="$AM_SRCDIR"/$package.pc.in
22	if [ -f $pcin ]; then
23		included=`grep '# *include' $inc |
24			sed -e 's/[^<"]*[<"]//' -e 's/[>"]//' |
25			grep -v 'xcb.h\|xproto.h'`
26		requires=`grep '^Requires.private:' $pcin`
27		missing=""
28		for i in $included; do
29			ibase=`basename $i .h`
30			r="xcb-$ibase"
31			rpcin="$AM_SRCDIR"/$r.pc.in
32			if [ -f $rpcin ]; then
33				m="$r"
34				for has in $requires; do
35					if [ $has = $r ]; then
36						m=""
37					fi
38				done
39				case "$m" in
40				"")
41					;;
42				*)
43					case "$missing" in
44					"")
45						missing=$m
46						;;
47					*)
48						missing="$missing $m"
49						;;
50					esac
51					;;
52				esac
53			fi
54		done
55		case "$missing" in
56		"")
57			;;
58		*)
59			if [ "$fix" = "y" ]; then
60			    echo $package adding dependency on $missing
61			    sed -i '/^Requires.private:/s/$/ '"$missing"'/' $pcin
62			else
63			    echo $package missing $missing
64			    status=1
65			fi
66			;;
67		esac
68	fi
69done
70exit $status
71