#!/bin/sh
#
# @(#)configure	1.10 1/7/97 15:07:22 /users/sccs/src/win/s.configure
#
# Script for checking contents prior to building library, including
# making of important links/files.
#
# This file is part of Willows Twin.
# 
# http://www.willows.com
#

DIRS="xdos readline debugger intp32 pal/x11 multimedia/mmsystem dll commctrl commdlg shell bmp win"

if [ "x$TARGET" = "x" ]
then 
     TARGET=`uname`
     echo "TARGET not set, assuming $TARGET"
fi

TWINDIR=`pwd`
TWINSRC=win
TWINVER=

if [ ! -f $TWINDIR/makeinclude/Makefile.$TARGET ] 
then
	cd makeinclude
	sh setup TWINDIR=$TWINDIR
	cd ..
fi

if [ -f $TWINDIR/makeinclude/Makefile.$TARGET$COMPILER ]
then 
	echo "Configuring for $TARGET"
	if [ "x$COMPILER" != "x" ]
	then
		echo "Using alternative compiler: $COMPILER"
	fi
else
	echo "Makefile.$TARGET$COMPILER does not exist"
	echo "use one of the existing targets as a template"
	echo "and try again."
	exit
fi

error=0
echo "Verifying installation"
echo "1. Checking directories"

for f in  $DIRS
do 
	if [ -d $f ]
	then
		echo "    $f exists."
	else
		echo "error: $f not found."
		error=1
	fi
	if [ "$error" = "1" ]
	then 
		echo "please fix above errors and try again."
		exit
	fi	
done

echo "2. Building initial dependencies"
for f in $DIRS
do 
	echo "    $f"
	touch $f/Makedepend.$TARGET
done

echo "3. Checking tools"
for f in rc
do
	ans=`which $f`
	echo "    $f is $ans"		
done

echo "4. Current configuration saved in config.twin"
echo "   Source the file config.twin to setup environment"
echo "   variables before running make. Specifically,"
echo "   TARGET   is set to $TARGET" 
echo "   COMPILER is set to $COMPILER" 
echo "   TWINDIR  is set to $TWINDIR"
echo "   TWINSRC  is set to $TWINDIR"
echo "   TWINOPT  is set to OPT, you may optionally set it to one of..."
echo "           OPT  to build optimized release version of library."
echo "           DBG  to build library with debug symbol table."
echo "           PROF to build profiling version of library."

	echo "#/bin/sh"  >config.twin
	echo "# setup environment variables for twin" >>config.twin 
	echo "export TARGET=Linux" >>config.twin

	echo "export TWINDIR=$TWINDIR" >>config.twin
 	echo "export TWINSRC=win" >>config.twin

	echo "export TWINOPT=DBG" >>config.twin
	echo "export TWINOPT=OPT" >>config.twin

	echo "export TWIN_APISIZE=32" >>config.twin
	echo "unset TWIN_APISIZE" >>config.twin

	echo "export LD_LIBRARY_PATH=$TWINDIR/$TWINSRC" >>config.twin

echo "5. Verify clean installation by running make clean"
echo "6. Build and install resource compiler, sources are in ./bin/rc"
echo "7. Setup system dependencies by running make depend"
echo "8. Build the library, and test program by running make"

