#= Makefile for dcpam/src
#
# Authors::   Yasuhiro MORIKAWA
# Version::   $Id: Makefile,v 1.12 2010-08-04 08:11:02 takepiro Exp $
# Tag Name::  $Name: dcpam5-20110926 $
# 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 \
		  dynamics radiation \
		  phy_implicit vdiffusion cumulus lscond surface_flux \
		  dryconv_adjust held_suarez_1994
RUNDIRS		= main
BINS		= 

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

all: lib exec

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

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

test:
	@for i in $(LIBDIRS) $(RUNDIRS) ; do \
	  cd $$i || exit 1; \
	  $(MAKE) $@ || 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) $(RUNDIRS) ; do \
	  cd $$i || exit 1; \
	  $(MAKE) $@ || exit 1; \
	  cd .. ; \
	done

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

clean.doc:
	@for i in $(LIBDIRS) $(RUNDIRS) ; 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) $(RUNDIRS) ; do \
	  cd $$i || exit 1; \
	  $(MAKE) $@ || exit 1; \
	  cd .. ; \
	done

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

clean.depend: 
	@for i in $(LIBDIRS) $(RUNDIRS) ; 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

