#! /bin/csh -f

# This script does a complete install of the Brown software distribution
# It should be run in the directory corresponding to /pro ($PRO).
# It should be run while running X11.

set X11info = (X11LIBS=-lX11 X11INCL=/usr/include X11LIBDIR=/usr/lib/X11)
set OTHERinfo = (OPTIMIZE=1)

if ($?DISPLAY == 0) then
echo you must be running X11 for this script to work.
exit (1)
endif

echo setting PRO and ARCH and path
setenv PRO `pwd`
setenv ARCH `arch`
set path = ($PRO/bwe/cmd $PRO/bwe/cmd/$ARCH $PRO/bin $path)

if (! -e lib) then
   echo making lib
   mkdir lib
endif

if (! -e include) then
   echo making include
   mkdir include
endif

if (! -e bin) then
   echo making bin and cmd
   mkdir bin
   ln -s bin cmd
endif

if (! -e threads) then
   echo installing dummy threads package
   (cd threads.dummy; ./thread.install)
else
   echo installing threads
   (cd $PRO/threads/src/$ARCH; make PRO=$PRO ARCH=$ARCH )
   rm -f $PRO/include/thread.h
   cp $PRO/threads/thread.h $PRO/include
   cp $PRO/threads/$ARCH/libthread.a $PRO/lib
   ranlib $PRO/lib/libthread.a
endif

if (-e gnumake) then
   echo making gnumake
   (cd gnumake; make PRO=$PRO ARCH=$ARCH )
endif

if (-e dl) then
   echo making dl
   (cd $PRO/dl/src; make PRO=$PRO ARCH=$ARCH $OTHERinfo newmachine)
endif

if (-e idyl) then
   echo building IDYL
   (cd idyl/src; make newmachine PRO=$PRO ARCH=$ARCH )
   setenv USE_IDYL 1
endif

if (-e bwe) then
   echo building BWE
   (cd bwe; ./INSTALL )
endif

if (-e field) then
   echo building FIELD
   (cd field; ./INSTALL )
endif

if (-e tango) then
   echo building TANGO
   (cd tango; ./INSTALL )
endif

if (-e pertlayout) then
   echo making pertlayout
   (cd pertlayout; make PRO=$PRO ARCH=$ARCH )
endif

if (-e garden) then
   echo building GARDEN
   (cd garden; ./INSTALL )
endif

echo done installation
