#!/bin/csh
#
#   15 Apr 2002 - MWS
#
#   Compile and link all GAMESS graphics programs.
#   Use this file by: complink >& complink.log &
#
#   The next four lines require your attention.
#
#   If you don't have Xwindows or PostScript at your place,
#       then just set that version false.
#   Legal TARGETs are:
#       compaq-axp, cray, fuji-vpp, hp9000, ibm, linux-pc, sgi, sun.
#
set xwversion=true
set psversion=true
set TARGET=ibm
#
#   The next three sections (compiler name, X11 library location,
#   and C compiler flags) will need to be modified if your system
#   is not already one of the valid targets.  
#
#   Pick compiler name and optimization level.
#
if ($TARGET == compaq-axp) set FORT='f77 -O4 -static' # PLTORB big arrays
if ($TARGET == cray)       set FORT='cf77'
if ($TARGET == fuji-vpp)   set FORT='frt -Wv,-p2200 -Ab'
if ($TARGET == hp9000)     set FORT='f90 +O2 +U77'
if ($TARGET == ibm)        set FORT='xlf -O2'
#-----ARGET == linux-pc)   set FORT='g77 -O2 -Wno-globals -fno-globals'
if ($TARGET == linux-pc)   set FORT='gfortran -O2 -std=legacy'
if ($TARGET == sgi)        set FORT='f77 -O2'
if ($TARGET == sun)        set FORT='f77 -O3'
#
#   The only X library we need is Xlib itself (no toolkits)
#
set XWLIBS='-lX11'
if ($TARGET == fuji-vpp) set XWLIBS='-lX11 -lsocket -lm -lnsl'
if ($TARGET == hp9000)   set XWLIBS='-Wl,-L/usr/lib/X11 -lX11 -Wl,-L/lib -lm'
if ($TARGET == linux-pc) set XWLIBS='-Wl,-L/usr/X11R6/lib -lX11'
#
set PSLIBS=' '
#--if ($TARGET == hp9000)   set PSLIBS='-Wl,-L/lib -lm'
#
#   Select the FORTRAN-calling-C "convention".
#   Pick nothing      if your FORTRAN expects lower case names
#   Pick -DCAPS       if your FORTRAN expects upper case names
#   pick -DUNDERSCORE if your FORTRAN expects lower case with _ postfixed
#
#   Select the "getenv" declaration.
#   Pick -DANSI  if your man page says "char *getenv(const char *name )"
#   Pick nothing if your man page says "char *getenv( )"
#
if ($TARGET == compaq-axp) set CFLAGS='-DUNDERSCORE -DANSI'
if ($TARGET == cray)       set CFLAGS='-DCAPS       -DANSI'
if ($TARGET == fuji-vpp)   set CFLAGS='-DUNDERSCORE -DANSI'
if ($TARGET == hp9000)     set CFLAGS='-I/usr/include/X11R5'
if ($TARGET == ibm)        set CFLAGS='             -DANSI'
if ($TARGET == linux-pc)   set CFLAGS='-DUNDERSCORE -DANSI'
if ($TARGET == sgi)        set CFLAGS='-DUNDERSCORE -DANSI'
if ($TARGET == sun)        set CFLAGS='-DUNDERSCORE -DANSI'
#
#   ---- Nothing below here should be changed ----
#
#   Compile the various FORTRAN utility routines.
#
echo '======================= utilities ========================'
cp ../source/frfmt.src               frfmt.f
cp kontrs.code                       kontrs.f
sed -e "/*UNX/s//    /" utils.code > utils.f
if ($TARGET == cray) then
   mv utils.f utils.junk
   sed -e "/*CRY/s//    /" utils.junk > utils.f
   rm -f utils.junk
endif
#
$FORT -c frfmt.f
$FORT -c kontrs.f
$FORT -c utils.f
rm -f *.f
#
#   Then compile and link the 4 programs.
#
if ($xwversion == true) then
   echo '================= Compiling XW versions =================='
   cc -c $CFLAGS -DUNIX xwindows.c
   echo '======================= xw-dendif ========================'
   sed -e "/*XW /s//    /" -e "/*UNX/s//    /" dendif.code > dendif.f
   $FORT -o dendif.xw.x dendif.f \
       frfmt.o kontrs.o utils.o xwindows.o $XWLIBS
   echo '======================= xw-mepmap ========================'
   sed -e "/*XW /s//    /" -e "/*UNX/s//    /" mepmap.code > mepmap.f
   $FORT -o mepmap.xw.x mepmap.f \
       frfmt.o kontrs.o utils.o xwindows.o $XWLIBS
   echo '======================= xw-molplt ========================'
   sed -e "/*XW /s//    /" -e "/*UNX/s//    /" molplt.code > molplt.f
   $FORT -o molplt.xw.x molplt.f \
       frfmt.o          utils.o xwindows.o $XWLIBS
   echo '======================= xw-pltorb ========================'
   sed -e "/*XW /s//    /" -e "/*UNX/s//    /" pltorb.code > pltorb.f
   $FORT -o pltorb.xw.x pltorb.f \
       frfmt.o kontrs.o utils.o xwindows.o $XWLIBS
   rm -f *.f
endif
#
if ($psversion == true) then
   echo '================= Compiling PS versions =================='
   cc -c $CFLAGS postscr.c
   echo '======================= ps-dendif ========================'
   sed -e "/*PS /s//    /" -e "/*UNX/s//    /" dendif.code > dendif.f
   $FORT -o dendif.ps.x dendif.f \
       frfmt.o kontrs.o utils.o postscr.o $PSLIBS
   echo '======================= ps-mepmap ========================'
   sed -e "/*PS /s//    /" -e "/*UNX/s//    /" mepmap.code > mepmap.f
   $FORT -o mepmap.ps.x mepmap.f \
       frfmt.o kontrs.o utils.o postscr.o $PSLIBS
   echo '======================= ps-molplt ========================'
   sed -e "/*PS /s//    /" -e "/*UNX/s//    /" molplt.code > molplt.f
   $FORT -o molplt.ps.x molplt.f \
       frfmt.o          utils.o postscr.o $PSLIBS
   echo '======================= ps-pltorb ========================'
   sed -e "/*PS /s//    /" -e "/*UNX/s//    /" pltorb.code > pltorb.f
   $FORT -o pltorb.ps.x pltorb.f \
       frfmt.o kontrs.o utils.o postscr.o $PSLIBS
   rm -f *.f
endif
#
rm -f *.o
date
time
