#! /bin/sh

# create an initialization procedure from a list of .o files

cookie=">>>use usg format"

# see if param.h defines "USG"
cat param.h > /tmp/munch$$.c
cat >> /tmp/munch$$.c <<!
#ifdef USG
$cookie
#endif
!
if (cc -E /tmp/munch$$.c | grep "^$cookie" > /dev/null)
then
	TYPE=USG
else
	TYPE=BSD
fi
rm -f /tmp/munch$$.c


echo '/* Do not modify this file.  It is created automatically by "munch". */'
echo 'void initialize_all_files () {'

case $TYPE in
	BSD)
		nm $* | \
		grep 'T __initialize_' | \
		sed -e 's/^.*T _\(.*\)/    \1 ();/'
		;;
	USG)
		# for usg use nm -p, grep for _initialize, 
		# don't delete leading '_'
		nm -p $* | \
		grep 'T _initialize_' | \
		sed -e 's/^.*T \(.*\)/    \1 ();/'
		;;
	*)
		echo unknown object file type $TYPE
		;;
esac

echo '}'
