#= Makefile for dcpam/libsrc
#
# Authors::   Yasuhiro MORIKAWA
# Version::   $Id: Makefile,v 1.17 2015/02/06 11:25:12 yot Exp $
# Tag Name::  $Name:  $
# Copyright:: Copyright (C) GFD Dennou Club, 2004-2007. All rights reserved.
# License::   See COPYRIGHT[link:../COPYRIGHT]
#
######################################################################
#
#== Settings

DIRDEPTH=..
INCLUDEFILE = $(DIRDEPTH)/Config.mk
include $(INCLUDEFILE)

LIBDIRS		= setup util saturate prepare_data io surface_properties \
		  sltt dynamics radiation \
		  phy_implicit vdiffusion cumulus lscond surface_flux \
		  dryconv_adjust held_suarez_1994 \
		  gwdrag sosi

#		  tt_fv
#		  vdiffusion_jma
#		  radiation_rrtmg

# RUNDIRS		= main
# BINS		= 

# End Settings
######################################################################

all: serial zonal mpi

serial: 
	@for i in $(LIBDIRS) ; do \
	  cd $$i || exit 1; \
	  $(MAKE) || exit 1; \
	  cd .. ; \
	done

zonal: 
	@for i in $(LIBDIRS) ; do \
	  cd $$i || exit 1; \
	  $(MAKE) SYSCPPFLAGS=-DAXISYMMETRY MODDIR=$(DIRDEPTH)/$(MODZONALDIR) DCPAMLIB=$(DCPAMZONALLIB) || exit 1; \
	  cd .. ; \
	done

mpi: 
	@for i in $(LIBDIRS) ; do \
	  cd $$i || exit 1; \
	  $(MAKE) SYSCPPFLAGS=-DLIB_MPI MODDIR=$(DIRDEPTH)/$(MODMPIDIR) DCPAMLIB=$(DCPAMMPILIB) || exit 1; \
	  cd .. ; \
	done

doc:
	@for i in $(LIBDIRS) $(RUNDIRS) ; do \
	  cd $$i || exit 1; \
	  $(MAKE) $@ || exit 1; \
	  cd .. ; \
	done

clean: depend.touch
	@for i in $(LIBDIRS) ; do \
	  cd $$i || exit 1; \
	  $(MAKE) $@ || exit 1; \
	  cd .. ; \
	done

clean.all: depend.touch
	@for i in $(LIBDIRS) ; do \
	  cd $$i || exit 1; \
	  $(MAKE) clean || exit 1; \
	  cd .. ; \
	done

clean.doc:
	@for i in $(LIBDIRS) ; do \
	  cd $$i || exit 1; \
	  $(MAKE) $@ || exit 1; \
	  cd .. ; \
	done

install: lib install-lib install-mod exec install-exec

install-lib:
	test -d $(INSTLIBDIR) || $(INSTALLDIR) $(INSTLIBDIR)
	$(INSTALL) $(LIBDIR)/$(DCPAMLIB) $(INSTLIBDIR)

install-mod:
	test -d $(INSTMODDIR) || $(INSTALLDIR) $(INSTMODDIR)
	$(INSTALL) $(MODDIR)/$(MODS) $(INSTMODDIR)

install-exec:
	test -d $(INSTBINDIR) || $(INSTALLDIR) $(INSTBINDIR)
	@for i in $(BINS) ; do \
	  $(INSTALL) $(BINDIR)/$$i $(INSTBINDIR) ;\
	  echo $(INSTALL) $(BINDIR)/$$i $(INSTBINDIR) ;\
	done

depend: 
	@for i in $(LIBDIRS) ; do \
	  cd $$i || exit 1; \
	  $(MAKE) $@ || exit 1; \
	  cd .. ; \
	done

depend.touch:
	@for i in $(LIBDIRS) ; do \
	  touch $${i}/depend; \
	done

clean.depend: 
	@for i in $(LIBDIRS) ; do \
	  $(RM) $${i}/depend; \
	done

tags: tags.local #tags.dir

#tagssm: tagssm.local tagssm.dir
#
tags.local:
	$(TAGS) $(wildcard */*.f90 */*.F90)

#tagssm.local:
#	@$(TAGS) dcpam.f90 $(SUBDIRSSM:%=%/*.f90)
#
#tags.dir:
#	@for i in $(SUBDIRS) ; do \
#	  cd $$i || exit 1; \
#	  $(MAKE) tags ; \
#	  cd .. ; \
#	done
#
#tagssm.dir:
#	@for i in $(SUBDIRSSM) ; do \
#	  cd $$i || exit 1; \
#	  $(MAKE) tags ; \
#	  cd .. ; \
#	done

