#= Makefile for gtool5 top directory
#
# Authors::   Eizi TOYODA, Yasuhiro MORIKAWA
# Version::   $Id: Makefile,v 1.5 2008-10-20 09:49:49 morikawa Exp $
# Tag Name::  $Name: gtool5-20090301 $
# Copyright:: Copyright (C) GFD Dennou Club, 2004-2008. All rights reserved.
# License::   See COPYRIGHT[link:COPYRIGHT]
#
#vi: set ts=8 sw=4:
#
######################################################################
#
#== Settings
#
# [JAPANESE] Ƽ

INCLUDEFILE = Config.mk
include $(INCLUDEFILE) # Include file              (optional)
                       # [JA] 󥯥롼ɥե (Ǥ)

GuideFiles = INSTALL HISTORY INSTALL_netcdf CREDITS
                       # Documentation located in top directory       (optional)
                       # ȥåץǥ쥯ȥ֤ɥȥե (Ǥ)

# End Settings  [JA] ܤޤ
######################################################################

######################################################################
#== Set GuideRDFiles
GuideRDFiles = $(GuideFiles:%=%.rd)
GuideJA      = $(GuideFiles:%=%.htm)
GuideEN      = $(GuideFiles:%=%.htm.en)

##########################################################################
#== Rules
#
all:
	cd src; $(MAKE) $@
	cd gt5frt; $(MAKE) $@

doc: guide
	cd src; $(MAKE) $@
	cd doc; $(MAKE)

install: all mkprefix
	cd src;    $(MAKE) $@
	cd gt5frt; $(MAKE) $@

mkprefix:
	test -d $(prefix) || $(INSTALLDIR) $(prefix)
	test -d $(exec_prefix) || $(INSTALLDIR) $(exec_prefix)

install-doc:
	cd doc ; $(MAKE) install
	$(INSTALL) $(GuideJA) $(GuideEN) $(GuideFiles) ChangeLog COPYRIGHT $(prefix)

clean:
	cd src; $(MAKE) $@
	cd gt5frt; $(MAKE) $@
	cd test; $(MAKE) $@

distclean: clean
	-$(RM) -f config.status chkfort.cfg chkgmake.cfg
	-$(RM) -f config.cache config.log Config.mk
	-$(RM) -f autom4te.cache/*
	-$(RMDIR) autom4te.cache
	@echo ""
	@echo "    Removing Config.mk,"
	@echo "      you should rerun ./configure to build gtool5."
	@echo ""

clean-doc: clean-guide
	cd src; $(MAKE) $@
	cd doc; $(MAKE) clean

test-f: all
	cd test; $(MAKE) $@

test: all
	cd test; $(MAKE) $@

test-c: all
	cd test; $(MAKE) $@

test-installed:
	cd gt5frt; $(MAKE) $@

test-installed-c:
	cd gt5frt; $(MAKE) $@

test-mpi: mpi-check all
	cd test; $(MAKE) $@

test-mpi-c: mpi-check all
	cd test; $(MAKE) $@

test-mpi-installed: mpi-check
	cd gt5frt; $(MAKE) $@

mpi-check:
	@test -n "$(MPIEXEC)" || \
	    eval 'echo ; echo "  Error: \$$MPIEXEC is not specified."; echo "         If you want to build gtool5 with MPI library, "; echo "         specify --with-mpiexec to configure."; echo  ; exit 1'
	@test -n "$(MPIEXECPROCOPT)" || \
	    eval 'echo ; echo "  Error: \$$MPIEXECPROCOPT is not specified."; echo "         \$$MPIEXEC=$(MPIEXEC) is unknown MPI executable command, "; echo "         so edit \$$MPIEXECPROCOPT in Config.mk directly."; echo  ; exit 1'


tags:
	perl src/f90tags src/*.f90

guide:
	@for file in $(GuideFiles) ; do \
	    echo $(CP) $${file} $${file}.rd ;\
	    $(CP) $${file} $${file}.rd ;\
	done
	$(MAKE) -f Makefile.rd2html
	$(RM) $(GuideRDFiles)

clean-guide:
	@if [ ! X"$(wildcard $(GuideJA) $(GuideEN) $(GuideRDFiles))" = X"" ]; then \
	    echo $(RM) $(wildcard $(GuideJA) $(GuideEN) $(GuideRDFiles)) ;\
	    $(RM) $(wildcard $(GuideJA) $(GuideEN) $(GuideRDFiles)) ;\
	fi

cl:
	@cvs2cl.pl --help > /dev/null 2>&1 || \
	    echo -e \
		"\n" \
		"    cvs2cl.pl is not found.\n" \
		"    Please get from http://www.red-bean.com/cvs2cl/\n"
	@cvs2cl.pl --help > /dev/null 2>&1 && \
	    echo -e \
		"This file is generated automatically by\n" \
		"\n" \
		"    cvs2cl.pl -r -b -t --fsf -w --header <This header>\n" \
		"\n" \
		`cvs2cl.pl --version` "\n" \
		"This script is available from "      \
		"http://www.red-bean.com/cvs2cl/\n\n" \
		    | cvs2cl.pl -r -b -t --fsf -w --header -
	rm ChangeLog.bak
	@echo -e "\n" "ChangeLog is Updated." "\n"

create-configure:
	@if [ ! -x /usr/bin/autoconf ]; then \
		echo -n "autoconf(1) is not valid. "; \
		echo "This is \"configure\" Generater."; \
		exit 1; \
	fi
	@if [ ! -r configure.in ]; then \
		echo -n "configure.in is not exists or not readable. "; \
		echo "This file needed for creating \"configure\"."; \
		exit 1; \
	fi
	@if [ ! -r aclocal.m4 ]; then \
		echo -n "aclocal.m4 is not exists or not readable. "; \
		echo "This file needed for creating \"configure\"."; \
		exit 1; \
	fi
	/usr/bin/autoconf
	@echo "\"configure\" Generated."
