#! /bin/csh

setenv F90 /fs/local/bin/pgf90
setenv  FC /fs/local/bin/pgf90
setenv  CC /fs/local/bin/pgcc
#setenv CPP /fs/local/bin/pgcpp
setenv CXX /fs/local/bin/pgCC

setenv HDFDIR /contrib/hdf5-1.8.9/pgi-11.5-0

setenv PREFIX /contrib/netcdf-4.2.1.1/pgi-11.5-0

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

make clean
make distclean

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} CXX= FC=${FC} F90=${F90} \
               CPPFLAGS="-I$HDFDIR/include -I$PREFIX/include -DpgiFortran" \
                 CFLAGS="-I$HDFDIR/include -I$PREFIX/include" \
                LDFLAGS="-L$HDFDIR/lib     -L$PREFIX/lib" \
                   LIBS="-lnetcdf" \
               --prefix=${PREFIX} || exit 1
   make                           || exit 2
   make check                     || exit 3
   make install                   || exit 4

else

   # Build the C interface first.
   ./configure CC=${CC} CXX=${CXX} FC=${FC} F90=${F90} \
               CPPFLAGS="-I$HDFDIR/include -DpgiFortran" \
                 CFLAGS="-I$HDFDIR/include" \
                LDFLAGS="-L$HDFDIR/lib" \
               --prefix=${PREFIX} || exit 1
   make                           || exit 2
   make check                     || exit 3
   make install                   || exit 4
endif

