#!/bin/sh
# $Id: check-ncu-pconfig,v 1.2 2019/10/05 22:02:21 tom Exp $
# check if ncurses*-config matches ncurses*.pc
failed() {
	echo "? $*" >&2
	exit 1
}

report_config() {
	NCFG=misc/ncurses-config 
	if test -s $NCFG
	then
		echo "** reporting script $NCFG"
		chmod +x $NCFG
		for ncfg in cflags libs libs-only-l libs-only-L libs-only-other
		do
			echo ".. $ncfg"
			$NCFG --$ncfg
		done
	fi
}

report_package() {
	for npkg in "$@"
	do
		test -s $npkg || continue
		NPKG=`basename $npkg .pc`
		echo "** reporting pkg-config with $NPKG"
		for ncfg in cflags libs libs-only-l libs-only-L libs-only-other
		do
			echo ".. $ncfg"
			PKG_CONFIG_PATH=`pwd`/misc pkg-config $NPKG --$ncfg
		done
	done
}

not_ncurses() {
	failed "not in ncurses build-tree"
}

case `pwd` in
*/ncurses*)
	[ -d ncurses ] || not_ncurses
	[ -d misc ] || not_ncurses
	;;
*)
	not_ncurses
	;;
esac

report_config >misc/config.log
report_package misc/ncurses[wt]*.pc misc/ncurses[0-9]*.pc >misc/package.log

if test -s misc/config.log
then
	cat misc/config.log
	if test -s misc/package.log
	then
		cat misc/package.log
		echo "..diff:"
		diff -u misc/config.log misc/package.log
		report_package misc/*.pc
	fi
elif test -s misc/package.log
then
	cat misc/package.log
fi
rm -f misc/*.log
# vile:ts=4 sw=4
