###############################################################################
#                                                                             #
#  TakTuk, a middleware for adaptive large scale parallel remote executions   #
#  deployment. Perl implementation, copyright(C) 2006 Guillaume Huard.        #
#                                                                             #
#  This program is free software; you can redistribute it and/or modify       #
#  it under the terms of the GNU General Public License as published by       #
#  the Free Software Foundation; either version 2 of the License, or          #
#  (at your option) any later version.                                        #
#                                                                             #
#  This program is distributed in the hope that it will be useful,            #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of             #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              #
#  GNU General Public License for more details.                               #
#                                                                             #
#  You should have received a copy of the GNU General Public License          #
#  along with this program; if not, write to the Free Software                #
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA #
#                                                                             #
#  Contact: Guillaume.Huard@imag.fr                                           #
#           ENSIMAG - Laboratoire ID                                          #
#           51 avenue Jean Kuntzmann                                          #
#           38330 Montbonnot Saint Martin                                     #
#                                                                             #
###############################################################################

.PHONY: commit clean_doc

# flags to aclocal if Makefile rules trigger it
ACLOCAL_AMFLAGS=-I acinclude

PERL_MODULE=Perl-Module/lib/TakTuk.pm

all: $(PERL_MODULE) taktuk-light

docdir = ${datadir}/doc
pkgdocdir = ${docdir}/@PACKAGE@
htmldocdir = ${pkgdocdir}/html
pkgconfigdir = $(libdir)/pkgconfig

dist_bin_SCRIPTS = taktuk
pkgconfig_DATA= taktuk.pc
pkgdoc_DATA= COPYING AUTHORS README NEWS ChangeLog

SUBDIRS=C-Module tests

if TAKTUK_GENDOC_HTML
dist_htmldoc_DATA=taktuk.html taktukcomm.html
endif
if TAKTUK_GENDOC_MAN
dist_man1_MANS=taktuk.man
dist_man3_MANS=taktukcomm.man
endif


if TAKTUK_NOPERL
install-exec-hook:
	@echo;echo WARNING: perl is required for taktuk execution;echo;
endif

taktuk.man: taktuk.pod
	$(POD2MAN) --name=TAKTUK --section=1 \
	     --center="TakTuk Deployment Engine" $^ >$@

taktukcomm.man: taktukcomm.pod
	$(POD2MAN) --name=TAKTUKCOMM --section=3 \
	     --center="TakTuk Library Functions Manual" $^ >$@

%.html: %.pod
	$(POD2HTML) --title="TakTuk" $^ >$@
	$(RM) pod2htmd.tmp pod2htmi.tmp

CLEANFILES = taktuk-light
taktuk-light: taktuk
	echo "#!/usr/bin/perl" >$@
	sed -e "s/^ *//g;s/  */ /g;s/^ *#.*$$//g;/^$$/d" $^ >>$@
	chmod u+x $@

CLEANFILES += $(PERL_MODULE)
$(PERL_MODULE): taktuk DISCLAIMER
	mkdir -p $(dir $@)
	cat $(filter %DISCLAIMER,$^) >$@
	./$(filter %taktuk,$^) -p taktuk >>$@

commit: $(PERL_MODULE)
	svn commit

DISTCLEANFILES = $(dist_htmldoc_DATA) $(dist_man1_MANS) $(dist_man3_MANS)

EXTRA_DIST = taktukcomm.pod taktuk.pod sample_session.txt \
             Perl-Module/Makefile.PL Perl-Module/MANIFEST.SKIP \
             Perl-Module/lib/TakTuk.pm DISCLAIMER \
	     Bugs bootstrap
