#!/bin/bash
#
# Build NWChem
# ============
#
# This script compiles a statically linked executable of NWChem
# with the gcc and gfortran compilers. This script expects to run
# in the top level NWChem directory (i.e. above src).
#
# The script takes at most one argument. This way you can use to
# build NWChem by simply invoking 
#
#    ./contrib/distro-tools/build_nwchem
#
# and similarly clean everything up by invoking
#
#    ./contrib/distro-tools/build_nwchem realclean
#
# Other builds can be generated by changing the compiler options and
# the environment variables as needed.
#
# The main advantages of this script are:
# 1. That you have a record of exactly how you compiled a binary.
# 2. You don't need any environment variables set in your general user
#    environment, allowing you full flexibility to switch between
#    different builds in different directories without getting caught
#    out by variable settings you forgot about.
#
export NWCHEM_TOP=`pwd`
export NWCHEM_TARGET=LINUX64
export NWCHEM_MODULES="all"
export NWCHEM_EXECUTABLE=$NWCHEM_TOP/bin/LINUX64/nwchem
export LDOPTIONS="-static -static-libgcc -static-libgfortran"
option=$1
if [ $1 == "python" ]; then
  export PYTHONVERSION=2.4
  export PYTHONHOME=/usr
  export PYTHONPATH=./:$NWCHEM_TOP/contrib/python/
  export NWCHEM_MODULES="$NWCHEM_MODULES python"
  echo "Building NWChem including Python $PYTHONVERSION"
  echo "===================================="
  option=""
elif [ $1 == "python64" ]; then
  export USE_PYTHON64=yes
  export PYTHONVERSION=2.4
  export PYTHONHOME=/usr
  export PYTHONPATH=./:$NWCHEM_TOP/contrib/python/
  export NWCHEM_MODULES="$NWCHEM_MODULES python"
  echo "Building NWChem including Python $PYTHONVERSION"
  echo "===================================="
  option=""
else
  echo "Building NWChem"
  echo "==============="
fi
cd $NWCHEM_TOP/src
make DIAG=PAR FC=gfortran CC=gcc LDOPTIONS="$LDOPTIONS" nwchem_config
make DIAG=PAR FC=gfortran CC=gcc LDOPTIONS="$LDOPTIONS" $option
