#!/bin/sh
# -*- shell-script -*-

. ${HOME}/.preparerc

# defaults
license=GPL
com_err=no
install=no
test_harness=no

for arg do
    case $arg in
    --license=*) # Select license to use
	license=`echo $arg | sed 's/.*=//'`
	;;
    --com_err) # Add com_err support files
	com_err=yes
	;;
    --install) # Add INSTALL file
	install=yes
	;;
    --test) # Add test-harness.c
	test_harness=yes
	;;
    esac
done

# License file...
filelist="COPYING.${license}:COPYING"

# The INSTALL file...
if [ ${install} = yes ]; then
    filelist="${filelist} INSTALL"
fi

# The com_err support files...
if [ ${com_err} = yes ]; then
    filelist="${filelist} comp_et-sh.in"
fi

# The test-harness.c file...
if [ ${test_harness} = yes ]; then
    if [ ! -d "tests" ]; then
	mkdir tests
    fi
    filelist="${filelist} test-harness.c:tests/test-harness.c"
fi

# Now find each file and link to it
for file in ${filelist}; do
    ifile="${commondir}/`echo ${file} | sed 's/:.*//'`"
    ofile=`echo ${file} | sed 's/.*://'`

    if [ ! -r "${ifile}" ]; then
	echo "Cannot locate required file ${ifile}" >&2
	exit 1
    fi

    if [ -r "${ofile}" ]; then
	rm -f ${ofile}
    fi

    ln -s ${ifile} ${ofile}
done
