#---------------------------------------------------------------------
#     Copyright (C) GFD Dennou Club, 2005. All rights reserved.
#---------------------------------------------------------------------
#= Makefile for gt4f90io top directory
#
#   * Developers: Eizi TOYODA (toyoda), Yasuhiro MORIKAWA (morikawa)
#   * Version: $Id: Makefile,v 1.8 2005/05/30 19:04:09 morikawa Exp $
#   * Tag Name: $Name: gt4f90io-20050530 $
#   * Change History: 
#
#vi: set ts=8 sw=4:

include Config.mk

#== Commands for Guide files
#
RDFORM2HTM = $(RD2HTM_LIB) $(RD2_LIB_FLAG) $(RD2_CSSFLAG)
RDFORM2JA  = $(RDFORM2HTM) $(RD2_JA_FLAG) \
		--with-part=TOPLINK:rd --with-part=JAUPDATE:rd
RDFORM2EN  = $(RDFORM2HTM) $(RD2_EN_FLAG) \
		--with-part=TOPLINK:rd --with-part=ENUPDATE:rd

GuideFiles = INSTALL HISTORY
GuideJA    = $(GuideFiles:%=%.htm.ja)
GuideEN    = $(GuideFiles:%=%.htm.en)

H1ToTitle  = $(RUBY) -e 'body = open(ARGV[0]){|io| io.read}; \
			 if /\<h1.*?\>(.*?)\<\/h1.*?\>/ =~ body then      ;\
			   h1 = $$1 ;\
			   h1 = h1.chomp.gsub!(/\<.*?\>/){|s| s = ""}    ;\
			 end ;\
			 mod = body.gsub(/\<title\>.*<\/title\>/,         \
			                "\<title\>" + h1 + "<\/title\>") ;\
			 out = open(ARGV[0], "w"); out.puts(mod)         ;\
			 out.close'



all:
	cd src; $(MAKE)
	cd gt4frt; $(MAKE) $@

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

install: all
	cd src;    $(MAKE) $@
	cd gt4frt; $(MAKE) $@

install-doc:
	cd doc ; $(MAKE) install

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

distclean: clean
	-rm -f config.status chkfort.cfg config.cache config.log Config.mk
	@echo removing Config.mk, you should rerun configure to build gt4f90io.

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

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

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

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

tags:
	perl src/f90tags src/*.f90

guide: $(GuideJA) $(GuideEN)

clean-guide:
	$(RM) $(GuideJA) $(GuideEN)

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"

%.htm.ja: %
	$(RDFORM2JA) $(@:.htm.ja=) > $@ || rm -f $@
	@echo -n 'Copy <h1> to <title> ..' ; $(H1ToTitle) $@  ; echo 'done'

%.htm.en: %
	$(RDFORM2EN) $(@:.htm.en=) > $@ || rm -f $@
	@echo -n 'Copy <h1> to <title> ..' ; $(H1ToTitle) $@  ; echo 'done'

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."
