#!/bin/bash
# =============================================================================
# 
# @(#) $Id: config,v 0.7.4.2 2001/02/18 09:44:08 brian Exp $
# 
# -----------------------------------------------------------------------------
# 
# Copyright (C) 1997-2001  Brian Bidulock <bidulock@dallas.net>
# 
# All Rights Reserved.
# 
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# 
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
# 
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 675 Mass
# Ave, Cambridge, MA 02139, USA.
# 
# -----------------------------------------------------------------------------
# 
# Last Modified $Date: 2001/02/18 09:44:08 $ by $Author: brian $
# 
# $Log: config,v $
# Revision 0.7.4.2  2001/02/18 09:44:08  brian
# Added new working branch.
#
# Revision 0.7.4.1  2001/02/18 09:32:46  brian
# Started new working branch.
#
# Revision 0.7.2.1  2001/02/02 12:49:09  brian
# Stab at working out includes on new compilers.
#
# Revision 0.7  2001/02/02 08:15:09  brian
# Configuration script for OpenSS7 STREAMS.
#
# =============================================================================

echo -en "\n\
OpenSS7 STREAMS Configuration Script\n\
\$Id: config,v 0.7.4.2 2001/02/18 09:44:08 brian Exp $\n\
\n"

if [ -e "./.config.in" ]; then
    . "./.config.in"
fi

if [ "$LISROOT..." = "..." ]; then
    LISROOT="/usr/src/LiS"
fi

LISINCL="$LISROOT/include"
LISFILE="$LISINCL/sys/stropts.h"

if [ ! -e $LISFILE ]; then
    echo -en "\
LiS STREAMS must be installed to correctly compile, install\n\
and run this version of the OpenSS7 package.  LiS STREAMS\n\
normally installs in the directory $LISROOT.  This directory\n\
does not exist on your system.  Please provide the root location\n\
of your LiS installation or type 'q' to quit.\n\
\n"
    while [ ! -e $LISFILE ]; do
        echo -en "$LISFILE does not exist, please enter \n\
location of LiS directory (or q to quit): "
        read LISROOT
        echo -en "\n"
        if [ "$LISROOT..." = "q..." ]; then
            exit 1
        fi
        LISINCL="$LISROOT/include"
        LISFILE="$LISINCL/sys/stropts.h"
    done
fi

if [ "$LISLIBROOT..." = "..." ]; then
    LISLIBROOT="/lib"
fi

if [ ! -d $LISLIBROOT ]; then
    echo -en "\
Strange... $LISLIBROOT does not seem to exist on your system.\n\
Is there another directory which may hold the LiS runtime user\n\
libraries?\n\
\n"
    while [ ! -d $LISLIBROOT ]; do
        echo -en "$LISLIBROOT does not exist, please enter \n\
location of LiS library directory (or q to quit): "
        read LISLIBROOT
        echo -en "\n"
        if [ "$LISLIBROOT..." = "q..." ]; then
            exit 1
        fi
    done
fi

if [ "$LISNAME..." = "..." ]; then
    LISNAME=LiS
fi

LISLIBS="$LISLIBROOT/lib$LISNAME.so"
LISLIBA="$LISLIBROOT/lib$LISNAME.a"

while [ ! -e $LISLIBS -a ! -e $LISLIBA ]; do
    echo -en "\
I cannot find $LISNAME.so or $LISNAME.a in $LISLIBROOT.\n\
Is there some other directory in which I can look?\n\
\n"
    echo -en "LiS library directory (or q to quit)[$LISLIBROOT]: "
    read RESULT
    echo -en "\n"
    if [ "$RESULT..." = "q..." ]; then
        exit 1
    fi
    if [ "$RESULT..." = "..." ]; then
        RESULT=$LISLIBROOT
    fi
    LISLIBROOT=$RESULT
    while [ ! -d $LISLIBROOT ]; do
        echo -en "$LISLIBROOT does not exist.\n\
LiS library directory (or q to quit): "
        echo -en "\n"
        read LISLIBROOT
        if [ "$LISLIBROOT..." = "q..." ]; then
            exit 1
        fi
    done
    LISLIBS="$LISLIBROOT/lib$LISNAME.so"
    LISLIBA="$LISLIBROOT/lib$LISNAME.a"
    if [ ! -e $LISLIBS -a ! -e $LISLIBA ]; then
        echo -en "\
I cannot find $LISNAME.so or $LISNAME.a in $LISLIBROOT.\n\
Is there some other name for the library?\n\
\n"
        echo -en "Name of LiS library (or q to quit)[$LISNAME]: "
        read RESULT
        echo -en "\n"
        if [ "$RESULT..." = "q..." ]; then
            exit 1
        fi
        if [ "$RESULT..." = "..." ]; then
            RESULT=$LISNAME
        fi
        LISNAME=$RESULT
        LISLIBS="$LISLIBROOT/lib$LISNAME.so"
        LISLIBA="$LISLIBROOT/lib$LISNAME.a"
    fi
done

LISLFLAGS="-l$LISNAME"

if [ ! "$LISLIBROOT..." = "/lib..." ]; then
    if [ -e /etc/ld.so.conf ]; then
        if $(grep -qs "$LISLIBROOT" /etc/ld.so.conf); then
            LISLFLAGS="-l$LISNAME"
        else
            LISLFLAGS="'-L$LISLIBROOT -l$LISNAME'"
        fi
    fi
fi

MODCONF="/etc/modules.conf"
if [ ! -e $MODCONF ]; then
    if [ -e /etc/conf.modules ]; then
        MODCONF="/etc/conf.modules"
    fi
fi

SDL_UDP_CMAJOR=252
SDT_UDP_CMAJOR=251
SL_UDP_CMAJOR=250
LS_CMAJOR=249

echo "export LISROOT=$LISROOT" >  .config.in
echo "export LISINCL=$LISINCL" >> .config.in
echo "export LISLIBROOT=$LISLIBROOT" >> .config.in
echo "export LISNAME=$LISNAME" >> .config.in
echo "export LISLFLAGS=$LISLFLAGS" >> .config.in
echo "export SDL_UDP_CMAJOR=$SDL_UDP_CMAJOR" >> .config.in
echo "export SDT_UDP_CMAJOR=$SDT_UDP_CMAJOR" >> .config.in
echo "export SL_UDP_CMAJOR=$SL_UDP_CMAJOR" >> .config.in
echo "export LS_CMAJOR=$LS_CMAJOR" >> .config.in
echo "export MODCONF=$MODCONF" >> .config.in

