#! /bin/sh
# @(#)genStarTable	1.1 11/24/92
# This script generates a file that references every star mentioned in
# the PL_SRCS variable in the makefile.

cat > /tmp/$$.hdr << EOF
/* This file contains a table of the official $1 stars.  Its purpose is
 * to force the linker to retrieve the corresponding stars from their
 * library.
 *
 * DO NOT EDIT THIS FILE!  It is generated automatically from the
 * make.template file's definition of PL_SRCS.
 */

#define STR extern char *

EOF

pp=ZZZ
if [ $# = 2 ]
then pp=$2
fi

sed -n	-e "s/$1/STR star_nm_${1}/g" \
	-e "s/$pp/STR star_nm_${pp}/g" \
	-e 's?PL_SRCS.*?/\* declare symbols \*/?' \
	-e "s/\.pl/;/g" \
	-e "s/[\\]//" \
	-e "/^.. declare/,/^\$/p" make.template > /tmp/$$.p1

sed -n	-e "s/$1/\&star_nm_${1}/g" \
	-e "s/$pp/\&star_nm_${pp}/g" \
	-e 's?PL_SRCS.*=?static char\*\* nm_table[] = {?' \
	-e "s/\.pl/,/g" \
	-e "s/[\\]//" \
	-e "/^static char/,/^\$/p" make.template > /tmp/$$.p2

cat /tmp/$$.hdr /tmp/$$.p1 /tmp/$$.p2
echo '};'

rm  /tmp/$$.hdr /tmp/$$.p1 /tmp/$$.p2

