#!/bin/sh
# This script makes a preliminary .cvsignore in the current dir by
# adding some standard stuff according to Makefile.am. People with
# srcdir==builddir will hopefully get another useful but untested
# feature.. ;-) [rastajoe]

function addignore() {
	test -f .cvsignore || \
	( touch .cvsignore && echo "created new .cvsignore" && cvs add .cvsignore )
	grep -q "^$1\$" .cvsignore || \
	( echo "$1" >> .cvsignore && echo "added $1 to .cvsignore" )
}

if test -f Makefile.am; then
	addignore Makefile
	addignore Makefile.in

	bins=`grep _PROGRAMS Makefile.am | grep -v '^#' | sed -e 's/.*=\s*//'`
	if ! test -z "$bins"; then
		for prog in $bins; do
			addignore "$prog"
		done
	fi

	libs=`grep _LTLIBRARIES Makefile.am | grep -v '^#' | sed -e 's/.*=\s*//'`
	if ! test -z "$libs"; then
		for lib in $libs; do
			meta_unload="${lib%.la}"_la_meta_unload.cpp
			test -f $meta_unload && addignore $meta_unload
		done
	fi
else
	echo "No Makefile.am found!"
fi

