#!/bin/csh
#
#  13 Mar 06 - script to compile the GAMESS quantum chemistry code.
#
#  Invoke this script by 'compall >& compall.log &'.
#  UNIX compilers are sometimes slow, so start this up, and go for tea.
#
#  ----- The next two lines require your attention.
#  1. Choose your machine, the legal values for TARGET are
#      amd64,axp64,compaq-sc,cray-pvp,cray-t3e,cray-x1,cray-xd1,cray-xt3,
#      fuji-pp32,fuji-pp64,hpux32,hpux64,ibm32,ibm64,ibm64-sp,ibm-bg,
#      linux-ia64,linux-pc,mac32,macG5,necsx,sgi32,sgi64,sun32,sun64
#  2. Choose your GAMESS directory tree.
#
set TARGET=ibm64
chdir /u1/mike/gamess
#
#  ----- and now the script begins...
#
date
#
if (!(-e object)) mkdir object
#
#  For some Cray systems, we will compile actvte.x automatically
#
chdir tools
if ($TARGET == cray-x1) then
   sed -e "s/\*UNX/    /" actvte.code > actvte.tmp
   sed -e "s/\*CRY/    /" actvte.tmp > actvte.f
   rm actvte.tmp
   ftn -Ocommand -o actvte.x actvte.f
   rm actvte.f
endif
if ($TARGET == cray-xt3) then
   sed -e "s/\*UNX/    /" actvte.code > actvte.f
   ftn -o actvte.x actvte.f
   rm actvte.f
endif
if ($TARGET == cray-xd1) then
   sed -e "s/\*UNX/    /" actvte.code > actvte.f
   pgf90 -o actvte.x actvte.f
   rm actvte.f
endif
chdir ..
#
#  Check to see if the installer has built actvte.x by hand.
#
if (!(-x tools/actvte.x)) then
   echo You did not compile the source code activator actvte.x
   echo Please read and follow the directions in $cwd/misc/readme.unix
   exit 8
endif
#
#  Compile a little bit of C to allow for runtime memory allocation.
#  1. we must select the name of the C compiler, often it is simply cc.
#  2. we must select the #define in zunix.c, and maybe other options.
#
set CCOMP=cc
if (($TARGET == axp64) && (`uname` == Linux)) set CCOMP=ccc
if  ($TARGET == amd64)      set CCOMP='pgcc -Mipa=fast,safe -Mprof=func'
if  ($TARGET == cray-xd1)   set CCOMP='pgcc -fastsse -tp amd64'
if  ($TARGET == fuji-pp32)  set CCOMP=fcc
if  ($TARGET == fuji-pp64)  set CCOMP=fcc
if (($TARGET == ibm64) && (`uname` == AIX))   set CCOMP='xlc'
if (($TARGET == ibm64) && (`uname` == Linux)) set CCOMP='gcc'
if  ($TARGET == ibm-bg)     set CCOMP='/opt/ibmcmp/vac/7.0/bin/blrts_xlc'
if  ($TARGET == linux-ia64) set CCOMP=icc
if  ($TARGET == necsx)      set CCOMP=c++
#
unset extraflags
if ($TARGET == amd64)        set extraflags='-DLINUXIA64'
if ($TARGET == axp64)        set extraflags='-DCOMPAQ'
if ($TARGET == compaq-sc)    set extraflags='-DCOMPAQ'
if ($TARGET == cray-pvp)     set extraflags='-DCRAY'
if ($TARGET == cray-t3e)     set extraflags='-DCRAY'
if ($TARGET == cray-x1)      set extraflags='-DCRAYX1'
if ($TARGET == cray-xd1)     set extraflags='-DCRAYXD1'
if ($TARGET == cray-xt3)     set extraflags='-DCRAYXT3 -fast -tp amd64'
if ($TARGET == fuji-pp32)    set extraflags='-DSUN32'
if ($TARGET == fuji-pp64)    set extraflags='-DSUN64 -KV9'
if ($TARGET == hpux32)       goto skip-zunix
if ($TARGET == hpux64)       goto skip-zunix
if ($TARGET == ibm32)        set extraflags='-DIBM32'
if ($TARGET == ibm64) then
   if(`uname` == AIX)        set extraflags='-DIBM64 -q64'
   if(`uname` == Linux)      set extraflags='-DIBMPPC64 -m64'
endif
if ($TARGET == ibm64-sp)     set extraflags='-DIBM64 -q64'
if ($TARGET == ibm-bg) \
        set extraflags='-DIBMBG -I/bgl/BlueLight/ppcfloor/bglsys/include'
if ($TARGET == linux-ia64)   set extraflags='-DLINUXIA64'
if ($TARGET == linux-pc)     set extraflags='-DLINUX -m32'
if ($TARGET == mac32)        set extraflags='-DLINUX -DCLK_TCK=100'
if ($TARGET == macG5)        set extraflags='-DLINUX'
if ($TARGET == necsx)        set extraflags='-DNECSX -size_t64'
if ($TARGET == sgi32)        set extraflags='-DSGI32 -n32'
if ($TARGET == sgi64)        set extraflags='-DSGI64 -64'
if ($TARGET == sun32) then
   if(`uname -p` == sparc)   set extraflags='-DSUN32 -xarch=v8plus'
   if(`uname -p` == i386)    set extraflags='-DSUN32 -xarch=pentium_pro'
endif
if ($TARGET == sun64) then
   if(`uname -p` == sparc)   set extraflags='-DSUN64 -xarch=v9'
   if(`uname -p` == i386)    set extraflags='-DSUN64 -xarch=amd64'
endif
#
#     defend against possibly mistyped compilation target
#
if ($?extraflags == 0) then
   echo The compall script does not select a correct TARGET machine type.
   echo What you typed when editing this script was $TARGET
   exit 4
endif
#
#     Compile the memory allocation C code
#
set echo
$CCOMP -c $extraflags source/zunix.c
unset echo
mv zunix.o object/zunix.o
#
skip-zunix:
#
#  If we do not have the BLAS in a system library, then compile a plain
#  vanilla FORTRAN version of the BLAS routines, supplied with GAMESS.
#  In some cases, the linking script will use a library if one is found,
#  in which case some of the blas.o files produced here may never be used.
#
if ($TARGET == axp64)      ./comp blas
if ($TARGET == ibm64)      ./comp blas
if ($TARGET == linux-ia64) ./comp blas
if ($TARGET == linux-pc)   ./comp blas
if ($TARGET == sun32)      ./comp blas
if ($TARGET == sun64)      ./comp blas
#
#  Sometimes we need a wrapper to pass 64 bit integers in GAMESS to 
#  system BLAS libraries that expect 32 bit args (see 'comp' hacking)
#
if ($TARGET == fuji-pp64)  ./comp blaswrap
if ($TARGET == ibm64)      ./comp blaswrap
if ($TARGET == ibm64-sp)   ./comp blaswrap
if ($TARGET == sgi64)      ./comp blaswrap
if ($TARGET == sun64)      ./comp blaswrap
#
#  If this is a vector machine, we must compile the vectorized routines
#
if ($TARGET == cray-pvp) ./comp vector
if ($TARGET == cray-x1)  ./comp vector
if ($TARGET == necsx)    ./comp vector
#
#  ---------- now, compile all of the individual source files -----------
#
./comp aldeci
./comp algnci
./comp basccn
./comp basecp
./comp basext
./comp bashuz
./comp bashz2
./comp basn21
./comp basn31
./comp baspcn
./comp bassto
./comp ccaux
./comp ccqaux
./comp ccquad
./comp ccsdt
./comp cisgrd
./comp cphf
./comp cpmchf
./comp cprohf
./comp chgpen
./comp cosmo
./comp ddilib
./comp delocl
./comp demrpt
./comp dft
./comp dftaux
./comp dftexc
./comp dftfun
./comp dftgrd
./comp dftint
./comp dgeev
./comp dgesvd
./comp dmulti
./comp drc
./comp ecp
./comp ecpder
./comp ecplib
./comp ecppot
./comp efchtr
./comp efdrvr
./comp efelec
./comp efgrd2
./comp efgrda
./comp efgrdb
./comp efgrdc
./comp efinp
./comp efinta
./comp efintb
./comp efpaul
./comp efpcm
./comp efpcov
./comp efpfmo
./comp eigen
./comp eomcc
./comp ffield
./comp fmo
./comp fmoint
./comp fmoio
./comp fmogrd
./comp fmolib
./comp fmoprp
./comp frfmt
./comp fsodci
./comp gamess
./comp globop
./comp gradex
./comp grd1
./comp grd2a
./comp grd2b
./comp grd2c
./comp guess
./comp gugdga
./comp gugdgb
./comp gugdm
./comp gugdm2
./comp gugdrt
./comp gugem
./comp gugsrt
./comp gvb
./comp hess
./comp hss1a
./comp hss1b
./comp hss2a
./comp hss2b
./comp inputa
./comp inputb
./comp inputc
./comp int1
./comp int2a
./comp int2b
./comp int2c
./comp int2d
./comp int2f
./comp int2g
./comp int2r
./comp int2s
./comp int2t
./comp int2u
./comp int2v
./comp int2w
./comp int2x
./comp iolib
./comp lagran
./comp local
./comp loccd
./comp locpol
./comp mcpinp
./comp mcpint
./comp mcpl10
./comp mcpl20
./comp mcpl30
./comp mcpl40
./comp mcpl50
./comp mcpl60
./comp mcpl70
./comp mcpl80
./comp mccas
./comp mcjac
./comp mcqdpt
./comp mcqdwt
./comp mcqud
./comp mcscf
./comp mctwo
./comp mdefp
./comp mexing
./comp morokm
./comp mm23
./comp mp2
./comp mp2ddi
./comp mp2grd
./comp mpcdat
./comp mpcgrd
./comp mpcint
./comp mpcmol
./comp mpcmsc
./comp mthlib
./comp nameio
./comp neostb
./comp nmr
./comp ordint
./comp ormas1
./comp parley
./comp pcm
./comp pcmcav
./comp pcmcv2
./comp pcmder
./comp pcmdis
./comp pcmief
./comp pcmpol
./comp pcmvch
./comp prpel
./comp prplib
./comp prppop
./comp qeigen
./comp qfmm
./comp qmfm
./comp qmmm
./comp qrel
./comp raman
./comp rhfuhf
./comp rxncrd
./comp ryspol
./comp scflib
./comp scfmi
./comp scrf
./comp sobrt
./comp soffac
./comp solib
./comp sozeff
./comp statpt
./comp surf
./comp svpchg
./comp svpinp
./comp svpleb
./comp symorb
./comp symslc
./comp tdhf
./comp tdx
./comp tdxio
./comp tdxitr
./comp tdxni
./comp tdxprp
./comp trans
./comp trfdm2
./comp trnstn
./comp trudge
./comp umpddi
./comp unport
./comp vibanl
./comp vbdum
./comp vscf
./comp zapddi
./comp zheev
./comp zmatrx
#
#      optional SIMOMM method using Tinker MM code
set TINKER=false
if ($TINKER == true) then
   ./comp Libtad
   ./comp Libteac
   ./comp Libtedl
   ./comp Libtemo
   ./comp Libterx
   ./comp Libtfi
   ./comp Libtjo
   ./comp Libtpr
   ./comp Libtsx
   ./comp Tdrive
   ./comp Tinkin
   ./comp Toys
endif
#
#      optional Valence Bond method using VB2000 code
set VB2000=false
if ($VB2000 == true) then
   ./comp vb2000
   ./comp vb2gms
endif
#
unset echo
echo ------------------- done with all compilations --------------------
date
time
