#! /bin/csh

setenv  CC /usr/local/bin/gcc
setenv  FC /usr/local/bin/gfortran
setenv F90 /usr/local/bin/gfortran
setenv CXX /usr/local/bin/g++

setenv PREFIX /usr/local
setenv HDF5DIR /opt/local

make clean
make distclean

if ( -d ${PREFIX} ) then
   echo "Installing into ${PREFIX} at "`date`
else   
   mkdir ${PREFIX}
   echo "Installing into ${PREFIX} at "`date`
endif

rm -fv macros.make config.status config.log config.cache

if ( -e $PREFIX/lib/libnetcdf.a ) then
   # Build the Fortran interface - after the C interface.
   # We are installing into the same place.

   ./configure CC=${CC} FC=${FC} F90=${F90} CXX=${CXX} \
            CPPFLAGS="-gdwarf-2 -I$HDF5DIR/include -I$PREFIX/include" \
             LDFLAGS="-gdwarf-2 -L$HDF5DIR/lib     -L$PREFIX/lib" \
              FFLAGS="-gdwarf-2" \
              CFLAGS="-gdwarf-2" \
                LIBS="-lnetcdf" \
            --prefix=${PREFIX} || exit 1

   make         || exit 2
   make check   || exit 3
   make install || exit 5

else

   # Build the C interface first.
   ./configure CC=${CC} FC=${FC} F90=${F90} CXX=${CXX} \
            CPPFLAGS="-gdwarf-2 -I$HDF5DIR/include" \
             LDFLAGS="-gdwarf-2 -L$HDF5DIR/lib" \
              FFLAGS="-gdwarf-2" \
              CFLAGS="-gdwarf-2" \
            --prefix=${PREFIX} || exit 1

   make         || exit 2
   make check   || exit 3
   make install || exit 5

endif

echo "Finished at "`date`
