#! /bin/sh
# 
# This script builds the reference manual pages for the directory given as the
# argument.
# The full format is:
# mkref toolsdirectory directorytoprocess
#
# It is intended that this is called by buildref; it is not user-friendly.
#
# Get the manual section:
#echo $2
TOOLS="$1"
DIR="$2"
EXT="8"
if [ -r "$DIR/mansec" ]; then 
EXT=`cat $DIR/mansec`
fi
DOCTEXT=$TOOLS/doc/doctext
DOC2LT=$TOOLS/doc/doc2lt

# Create the destiation directory if necessary
if [ -r $TOOLS/ref/ref$EXT ]; then
    OK=dummy
else
    mkdir $TOOLS/ref/ref$EXT
fi

# Because sh doesn't discard patterns that don't match any file name,
# we do that here
FILE=`echo $DIR/*.[ch]`
if [ "$FILE" = "$DIR/*.[ch]" ]; then
    # did not expand the name
    OK=dummy
else
    echo "doctext $DIR"
    $DOCTEXT -latex -mpath $TOOLS/ref/ref$EXT -ext $EXT -I $DIR/pubinc $DIR/*.[ch] 
fi
if [ -r $DIR/readme ]; then 
    $DOCTEXT -latex -mpath $TOOLS/ref/ref$EXT -ext $EXT $DIR/readme 
fi
