#!/bin/csh
#
#   3 May 12 - script to compile all of 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.
#
#  This script no longer requires customization, as it starts off by
#  reading information about the compilation from a configuration file.
#
if (-e install.info) then
   source install.info
else if (-e ../install.info) then
   source ../install.info
else
   echo "Please run 'config' first, to set up GAMESS compiling information"
   exit 4
endif
#
#        this flag allows compall to exit after compilation of zunix
set makezunix=$1
#
#  the configuration file read just above provides the next two variables.
#
set TARGET=$GMS_TARGET
#AAD this script is run from GMS_BUILD_DIR only which may be the same
#    as GMS_PATH
#chdir $GMS_PATH
#
#  ----- and now the script begins...
#
date
#
if (!(-e object)) mkdir object
#
#  Check to see if the configuration step has built actvte.x 
#
if (!(-x tools/actvte.x)) then
   echo "Something went wrong with 'config', so that the source code"
   echo "activation program was not correctly compiled.  Please repeat"
   echo "the 'config' step, so that tools/actvte.x is created."
   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 == 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 GMS_BG_MODEL=' '
if (($TARGET == ibm-bg) && ($GMS_BG_MODEL == L))  set CCOMP='blrts_xlc'
if (($TARGET == ibm-bg) && ($GMS_BG_MODEL == P))  set CCOMP='bgxlc_r'
if  ($TARGET == linux32)                          set CCOMP='gcc'
if  ($TARGET == linux64)                          set CCOMP='gcc'
if  ($TARGET == necsx)                            set CCOMP='c++'
#
unset extraflags
#
if ($TARGET == axp64)        set extraflags='-DAXP64'
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-xt)      set extraflags='-DLINUX64'
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) then
   if ($GMS_BG_MODEL == L) then
      set extraflags='-DIBMBG -I/bgl/BlueLight/ppcfloor/bglsys/include'
   endif
   if ($GMS_BG_MODEL == P) then
      set extraflags="-DIBMBG -qarch=450d -qtune=450"
      set extraflags="$extraflags -DCLK_TCK=CLOCKS_PER_SEC"
      set extraflags="$extraflags -I/bgsys/drivers/ppcfloor/include"
   endif
endif
if ($TARGET == linux32)      set extraflags='-DLINUX32'
if ($TARGET == linux64)      then
#      Ubuntu uses the non-standard -m flag, its -p replies "unknown"
                         set chip=`uname -p`
   if ($chip == unknown) set chip=`uname -m`
   if ($chip == x86_64) set extraflags='-DLINUX64 -m64'
   if ($chip == ia64)   set extraflags='-DLINUX64'  # this always 64 bits
endif
if ($TARGET == mac32)        set extraflags='-DLINUX32'
if ($TARGET == mac64)    set extraflags='-DLINUX64 -m64 -I/usr/include/malloc'
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) || ($TARGET == sun64)) then
   if ($GMS_SUN_OS_VERNO >= 7) then
      set xxx=$GMS_SUN_FORT_VERNO
      set f90_major=$xxx:r
      set f90_minor=$xxx:e
                                                  set newf90=false
      if (($f90_major == 8) && ($f90_minor >= 3)) set newf90=true
      if  ($f90_major >= 9)                       set newf90=true
   else
      set newf90=false
   endif
   if ($TARGET == sun32) then
      if ($newf90 == true) then
                                   set extraflags='-DSUN32 -m32'
      else
         if(`uname -p` == sparc)   set extraflags='-DSUN32 -xarch=v8plus'
         if(`uname -p` == i386)    set extraflags='-DSUN32 -xarch=pentium_pro'
      endif
   endif
   if ($TARGET == sun64) then
      if ($newf90 == true) then
                                   set extraflags='-DSUN64 -m64'
      else
         if(`uname -p` == sparc)   set extraflags='-DSUN64 -xarch=v9'
         if(`uname -p` == i386)    set extraflags='-DSUN64 -xarch=amd64'
      endif
   endif
endif
#
if (($TARGET == win32) || ($TARGET == win64) || ($TARGET == winazure)) then
   set EXTRA_FLAGS=''
   set MPIFLAG=''
   if ($GMS_FORTRAN == pgfortran) then
     set CCOMP='pgcc'
     set CFLAGS="-v -Bstatic -Minfo=all -Minform=severe"
     if ($GMS_WIN_OPT == baseline) set CFLAGS="$CFLAGS -O0"
     if ($GMS_WIN_OPT == linux)    set CFLAGS="$CFLAGS -O2"
     if ($GMS_WIN_OPT == fast)     set CFLAGS="$CFLAGS -fastsse"
     if ($GMS_WIN_OPT == testing)  set CFLAGS="$CFLAGS $GMS_PGI_OPT"
     if ($GMS_MPI_LIB == msmpi)    set MPIFLAG='-Mmpi=msmpi'
     if ($GMS_MPI_LIB == mpich2)   set MPIFLAG="-I C:\Progra~1\MPICH2\include"
     if ($TARGET == win32)         set extraflags="$GMS_WIN_FLAGS $CFLAGS $GMS_WIN_TP -DWINDOWS32 $MPIFLAG"
     if ($TARGET == win64)         set extraflags="$GMS_WIN_FLAGS $CFLAGS $GMS_WIN_TP -DWINDOWS64 $MPIFLAG"
     if ($TARGET == winazure)      set extraflags="$GMS_WIN_FLAGS $CFLAGS $GMS_WIN_TP -DWINDOWS64 -DWINDOWSAZURE"
   endif
   if ($GMS_FORTRAN == ifort) then
     set CCOMP='icl'
     set CFLAGS="-Dmemget_=MEMGET -Dmemrel_=MEMREL -Dnaptime_=NAPTIME -Dwalltimer_=WALLTIMER"
     if ($GMS_WIN_OPT == baseline) set CFLAGS="$CFLAGS -Od"
     if ($GMS_WIN_OPT == linux)    set CFLAGS="$CFLAGS -O2"
     if ($GMS_WIN_OPT == samara)   set CFLAGS="$CFLAGS -O3"
     if ($GMS_WIN_OPT == fast)     set CFLAGS="$CFLAGS -fast"
     if ($GMS_WIN_OPT == testing)  set CFLAGS="$CFLAGS $GMS_INT_OPT"
     if ($GMS_MPI_LIB == msmpi) then
       if ($?MSMPI_INC) then
         echo "MPI header path: $MSMPI_INC"
         set MPIFLAG=""
         set EXTRA_FLAGS="-I$MSMPI_INC"
       else
         echo "Set MSMPI_INC to the MPI header directory and try again."
         exit 1
       endif
     endif
     if ($GMS_MPI_LIB == mpich2)     set MPIFLAG="-I C:\Progra~1\MPICH2\include"
     if ($TARGET == win32)           set extraflags="$GMS_WIN_TP $CFLAGS $GMS_WIN_FLAGS -DWINDOWS32 $MPIFLAG"
     if ($TARGET == win64)           set extraflags="$GMS_WIN_TP $CFLAGS $GMS_WIN_FLAGS -DWINDOWS64 $MPIFLAG"
     if ($TARGET == winazure)        set extraflags="$GMS_WIN_TP $CFLAGS $GMS_WIN_FLAGS -DWINDOWS64 -DWINDOWSAZURE"
   endif
endif
#
#     defend against possibly mistyped compilation target
#
if ($?extraflags == 0) then
   echo "The compall script does not have a correct TARGET machine type."
   echo "The value you supplied at 'config' time was TARGET=$TARGET"
   exit 4
endif
#
#     Compile the memory allocation C code
#
if ($?GMS_COMP_DRYRUN) set CCOMP="echo ZUNIX:$CCOMP"
#
if (($TARGET == win32) || ($TARGET == win64) || ($TARGET == winazure)) then
  set echo
  $CCOMP -c $extraflags $EXTRA_FLAGS:q -o $GMS_BUILD_DIR/object/zunix.o c:/cygwin/$GMS_PATH/source/zunix.c
  if (-e zunix.obj) mv zunix.obj $GMS_BUILD_DIR/object/zunix.o
  unset echo
else
  set echo
  $CCOMP -c $extraflags -o $GMS_BUILD_DIR/object/zunix.o $GMS_PATH/source/zunix.c
  unset echo
endif
set FAILED=$status
#
if (null$makezunix != null) then
   exit $FAILED
endif
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 == ibm-bg)     ./comp blas
if ($TARGET == linux32)    ./comp blas
if ($TARGET == linux64)    ./comp blas
if ($TARGET == mac64)      ./comp blas
if ($TARGET == sun32)      ./comp blas
if ($TARGET == sun64)      ./comp blas
if ($TARGET == win32)      ./comp blas
if ($TARGET == win64)      ./comp blas
if ($TARGET == winazure)   ./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 == mac64)      ./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
#
#  If we are compiling a serial binary
#
if ($GMS_DDI_COMM == serial) ./comp serial
#
#
#  ---------- now, compile all of the individual source files -----------
#
./comp aldeci
./comp algnci
./comp basccn
./comp basecp
./comp basext
./comp basg3l
./comp basg3x
./comp bashuz
./comp bashz2
./comp baskar
./comp basn21
./comp basn31
./comp baspcn
./comp bassto
./comp ccaux
./comp ccddi
./comp ccqaux
./comp ccquad
./comp ccsdt
./comp ceeis
./comp chgpen
./comp cisgrd
./comp comp
./comp cosmo
./comp cosprt
./comp cphf
./comp cpmchf
./comp cprohf
./comp dccc
./comp dcgrd
./comp dcgues
./comp dcint2
./comp dclib
./comp dcmp2
./comp dcscf
./comp dctran
./comp ddilib
./comp delocl
./comp demrpt
./comp dft
./comp dftaux
./comp dftdis
./comp dftfun
./comp dftgrd
./comp dftint
./comp dftxca
./comp dftxcb
./comp dftxcc
./comp dftxcd
./comp dftxce
./comp dftxcf
./comp dftxcg
./comp dgeev
./comp dgesvd
./comp dmulti
./comp drc
./comp eaipcc
./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 efmo
./comp efpaul
./comp efpcm
./comp efpcov
./comp efpfmo
./comp eftei
./comp eigen
./comp elglib
./comp elgloc
./comp elgscf
./comp excorr
./comp eomcc
./comp ewald
./comp ffield
./comp fmo
./comp fmocp
./comp fmoesd
./comp fmogrd
./comp fmohss
./comp fmoint
./comp fmoio
./comp fmolib
./comp fmomm
./comp fmopbc
./comp fmoprp
./comp frfmt
./comp fsodci
./comp g3
./comp gamess
./comp globop
./comp gmcpt
./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 ivocas
./comp lagran
./comp local
./comp loccd
./comp locpol
./comp lrd
./comp mccas
./comp mcjac
./comp mcpgrd
./comp mcpinp
./comp mcpint
./comp mcpl10
./comp mcpl20
./comp mcpl30
./comp mcpl40
./comp mcpl50
./comp mcpl60
./comp mcpl70
./comp mcpl80
./comp mcqdpt
./comp mcqdwt
./comp mcqud
./comp mcscf
./comp mctwo
./comp mdefp
./comp mexing
./comp mltfmo
./comp mm23
./comp mnsol
./comp morokm
./comp mp2
./comp mp2ddi
./comp mp2grd
./comp mp2gr2
./comp mp2ims
./comp mpcdat
./comp mpcgrd
./comp mpcint
./comp mpcmol
./comp mpcmsc
./comp mpqcst
./comp mthlib
./comp nameio
./comp neostb
./comp nmr
./comp optcix
./comp ordint
./comp ormas1
./comp parley
./comp pcm
./comp pcmcav
./comp pcmcv2
./comp pcmder
./comp pcmdis
./comp pcmief
./comp pcmpol
./comp pcmvch
./comp prpamm
./comp prpel
./comp prplib
./comp prppop
./comp qeigen
./comp qfmm
./comp qmfm
./comp qmmm
./comp qrel
./comp quanpo
./comp raman
./comp rhfuhf
./comp ricab
./comp riint
./comp rimp2
./comp roeom
./comp rohfcc
./comp rxncrd
./comp ryspol
./comp scflib
./comp scfmi
./comp scrf
./comp sfdft
./comp sfgrad
./comp sobrt
./comp soffac
./comp solib
./comp sozeff
./comp statpt
./comp surf
./comp svpchg
./comp svpinp
./comp svpleb
./comp symorb
./comp symslc
./comp tddft
./comp tddefp
./comp tddfun
./comp tddfxc
./comp tddgrd
./comp tddint
./comp tddnlr
./comp tddxca
./comp tddxcc
./comp tddxcd
./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 utddft
./comp vibanl
./comp vscf
./comp vvos
./comp zapddi
./comp zheev
./comp zmatrx
#
#                 five plug-in codes are available:
#      TINKER  is available from the GAMESS web site  (see INTRO.DOC),
#      VB2000  is distributed with GAMESS source code tar file.
#      XMVB    is available by electronic mail        (see INTRO.DOC),
#      NEO     is distributed with GAMESS source code tar file.
#      GPUCODE is distributed with GAMESS source code tar file.
#
#           Select one or more by setting its flag to "true".
#           You can select only one of the VB programs at a time.
#
#      optional Surface Integrated MO/MM method (SIMOMM),
#      using a customized version of the Tinker MM code.
#      To select this plug-in, set "TINKER" true in compall/comp/lked,
#      and if you are adding the Tinker code in after a previous 'compall',
#      recompile -- inputb -- to select the correct number of MM atoms,
#      as well as the file names shown just below.
#
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
#      to select this plug-in, set "VB2000" true in compall/lked.
#      VB2000 is incompatible with XMVB, at most, choose only one of these.
#      in 5/2012, only gfortran/ifort seem to produce working VB2000.
#
                         set VB2000=false
if ($TARGET == linux64)  set VB2000=true
if ($TARGET == linux32)  set VB2000=true
if ($TARGET == mac64)    set VB2000=true
if ($VB2000 == true) then
   ./comp vb2000
   ./comp vb2gms
else
   ./comp vbdum
endif
#
#      optional Valence Bond method, using XMVB code
#      to select this plug-in, set "XMVB" true in compall/lked.
#      XMVB is incompatible with VB2000, at most, choose only one of these.
#
set XMVB=false
if ($XMVB == true) then
   ./comp xmvb
endif
#
#      optional Nuclear-Electronic Orbital method, using NEO code
#      to select this plug-in, set "NEO" true in compall/lked.
#
set NEO=false
if ($NEO == true) then
   ./comp neo
   ./comp neobas
   ./comp neocas
   ./comp neoden
   ./comp neofci
   ./comp neog2a
   ./comp neog2b
   ./comp neog2c
   ./comp neogrd
   ./comp neohf
   ./comp neohss
   ./comp neoint
   ./comp neomp2
   ./comp neonci
   ./comp neoopt
   ./comp neopos
   ./comp neoprp
   ./comp neosym
   ./comp neotrn
   ./comp neovib
endif
#
#      optional code for Nvidia GPU cards (Linux host)
#      to select this plug-in, set "GPUCODE" true in comp/lked, after
#      reading installation requirements ~/gamess/libqc/aaa.readme.1st
#
unset echo
echo ------------------- done with all compilations --------------------
date
time
