#!/bin/sh
CPPOPTIONS=
if [ "$1" = "--cppoptions" ] ; then
	CPPOPTIONS="$2"
	shift
	shift
fi
if [ $# -lt 2 ] ; then
	echo tlccversion [ --cppoptions \"options\" ] source_file.tlcc ... [ output_file ]
	echo Extract the version of every TLMP component used by the
	echo source files
	exit 1
else
	CPP=/lib/cpp
	if [ ! -x $CPP ] ; then
		CPP=cpp
	fi
	TMPFILE=/tmp/version.tmp.$$
	rm -f $TMPFILE
	touch $TMPFILE
	while [ $# -gt 1 ]
	do
		if [ "$1" != "*.tlcc" ] ; then
			$CPP -dM $CPPOPTIONS $1 >>$TMPFILE 2>/dev/null
		fi
		shift
	done
	grep "define[ 	]*_TLMP_" $TMPFILE | sed 's/#define//' | sort | uniq | sed s/_TLMP_// >$1
	rm $TMPFILE
fi

