#!/bin/csh
#
# Data Assimilation Research Testbed -- DART
# Copyright 2004-2007, Data Assimilation Research Section
# University Corporation for Atmospheric Research
# Licensed under the GPL -- www.gpl.org/licenses/gpl.html
#
# <next few lines under version control, do not edit>
# $URL: http://subversion.ucar.edu/DAReS/DART/trunk/models/lorenz_84/work/mkmf_filter $
# $Id: mkmf_filter 2691 2007-03-11 18:18:09Z thoar $
# $Revision: 2691 $
# $Date: 2007-03-11 12:18:09 -0600 (Sun, 11 Mar 2007) $

# usage: mkmf_filter [ -mpi ]
#  without any args, builds filter without mpi libraries, and it will run
#  as a normal executable. if -mpi is given, it will be compiled with the mpi
#  libraries and can run with multiple cooperating processes.

if ( $#argv > 0 ) then
  if ("$argv[1]" == "-mpi") then
    setenv usingmpi 1
  else
    echo "Unrecognized argument to mkmf_filter: $argv[1]"
    echo "Usage: mkmf_filter [ -mpi ]"
    echo " default is to generate a Makefile without MPI support."
    exit -1
  endif
else
  setenv usingmpi 0
endif


# make a backup copy of the path_names file, and then use
# sed to make sure it includes either the non-mpi subroutines,
# or the subroutines which really call mpi.
cp -f path_names_filter path_names_filter.back

if ( $usingmpi ) then

  echo "Making Makefile with MPI"
  touch using_mpi_for_filter
  sed -e 's;/null_mpi_util;/mpi_util;' path_names_filter.back >! path_names_filter
  setenv wrapper_arg -w

else

  echo "Making Makefile without MPI"
  rm -f using_mpi_for_filter
  sed -e 's;/mpi_util;/null_mpi_util;' path_names_filter.back >! path_names_filter
  setenv wrapper_arg ""

endif

# remove temp file and now really call mkmf to generate makefile
rm -f path_names_filter.back

../../../mkmf/mkmf -p filter -t ../../../mkmf/mkmf.template -c"-Duse_netCDF" \
        -a "../../.." ${wrapper_arg} path_names_filter

