:
#
# $Id: makeconfig,v 2.0 90/09/19 20:13:46 paul Rel $
#
# $Log:	makeconfig,v $
# Revision 2.0  90/09/19  20:13:46  paul
# Initial 2.0 release
# 
#

case $CONFIG in
'')
    if test ! -f config.sh; then
	ln ../config.sh . || \
	ln ../../config.sh . || \
	ln ../../../config.sh . || \
	(echo "Can't find config.sh."; exit 1)
    fi
    . config.sh
    ;;
esac
case "$0" in
*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
esac

tmp=/tmp/mc$$
rmlist="$tmp"
trap 'echo " "; $rm -f $rmlist; exit 1' 1 2 3

: where is the source
src=..
tune=$src/tune.h
release=$src/release.h

: is package complete
if $test ! -f $tune; then
    echo "Can't find tune.h."
    exit 1
fi

: things we can tell from tune.h
cppout=".cppout"
tuneout=".tune"
rmlist="$cppout $tuneout $rmlist"
$cppstdin -I$src -I. $cppminus <<EOS >$cppout
#include <$tune>
#include <$release>
console=CONSOLE
defaults=DEFAULTS
issue=ISSUE
login=LOGIN
connect=DEF_CONNECT
#ifdef	LOGUTMP
logutmp="$define"
#endif
#ifdef	TRS16
trs16="$define"
#endif
#ifdef	TRYMAIL
trymail="$define"
notify=NOTIFY
#endif
#ifdef	WARNCASE
warncase="$define"
#endif
release=RELEASE
date=DATE
EOS
$sed 's/[ 	]//' <$cppout >$tuneout
chmod +x $tuneout
. $tuneout

defaults=`$echo $defaults | $sed 's;/\%s;;'`
$sed 's;\\;\\\\;g' <<EOS >$tmp
$connect
EOS
connect=`cat $tmp`

: things we cannot tell from tune.h
if $test ! -d /usr/lib/terminfo; then
    termcap="$define"
fi
systems=L.sys
if $test -f /usr/lib/uucp/Systems; then
    systems=Systems
fi
gtab=`basename $gettytab`

: name the man pages
case "$xenix" in
"$define")
    cmd=C; mcmd=M; system=S; library=S; file=F; misc=M
    ;;
"$undef")
    cmd=1; mcmd=1m; system=2; library=3; file=4; misc=7
    ;;
esac

$cat <<EOC >config.m4
.\" +----------
.\" | local GETTY configurations
.\"
.\" define(\`_cmd_section_', $cmd)
.\" define(\`_mcmd_section_', $mcmd)
.\" define(\`_system_section_', $system)
.\" define(\`_library_section_', $library)
.\" define(\`_file_section_', $file)
.\" define(\`_misc_section_', $misc)
.\" define(\`_console_', $console)
.\" define(\`_defaults_', $defaults)
.\" define(\`_gettytab_', $gettytab)
.\" define(\`_gtab_', $gtab)
.\" define(\`_issue_', $issue)
.\" define(\`_login_', $login)
.\" define(\`_utmp_', $utmp)
.\" define(\`_wtmp_', $wtmp)
.\" define(\`_systems_', $systems)
.\" define(\`_connect_', $connect)
.\" define(\`RELEASE', $release)
.\" define(\`DATE', $date)
.\"
EOC

case "$logutmp" in
"$define") $cat <<EOC >>config.m4
.\" define(\`logutmp')
EOC
;;
esac
case "$termcap" in
"$define") $cat <<EOC >>config.m4
.\" define(\`termcap')
EOC
;;
esac
case "$trs16" in
"$define") $cat <<EOC >>config.m4
.\" define(\`trs16')
EOC
;;
esac
case "$trymail" in
"$define") $cat <<EOC >>config.m4
.\" define(\`trymail')
.\" define(\`_notify_', $notify)
EOC
;;
esac
case "$ttytype" in
"/*") $cat <<EOC >>config.m4
.\" define(\`ttytype', $ttytype)
EOC
;;
esac
case "$warncase" in
"$define") $cat <<EOC >>config.m4
.\" define(\`warncase')
EOC
;;
esac

$rm -f $rmlist
# grrr, don't ask
$rm -f $cppout
$rm -f $tuneout
