#!/usr/bin/make -f
# debian/rules for cameleon package
# Copyright (C) 2006 Sylvain Le Gall <gildor@debian.org>
#
# 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, 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.

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/ocaml.mk
include /usr/share/cdbs/1/class/autotools.mk
include $(CURDIR)/debian/mk/docbook-manpage.mk

PACKAGE := cameleon
DESTDIR := $(CURDIR)/debian/$(PACKAGE)

PACKAGE_DEV := libcameleon-ocaml-dev
DESTDIR_DEV := $(CURDIR)/debian/$(PACKAGE_DEV)

PACKAGE_DOC := cameleon-doc
DESTDIR_DOC := $(CURDIR)/debian/$(PACKAGE_DOC)

OCAMLDOC_PLUGINSDIR := $(DESTDIR)/$(shell ocamldoc -customdir)

DEB_MAKE_CLEAN_TARGET    := distclean

DEB_MAKE_BUILD_TARGET    := depend all doc

DEB_MAKE_INSTALL_TARGET  := install                                      \
                            DESTDIR='$(DESTDIR)'                         \
			    OCAMLDOC_PLUGINSDIR='$(OCAMLDOC_PLUGINSDIR)'

DEB_CONFIGURE_EXTRA_FLAGS = --prefix=/usr --datadir=/usr/share/cameleon \
                            --mandir=/usr/share/man                     \
                            --libdir=$(OCAML_STDLIB_DIR)/cameleon

DEB_STRIP_EXCLUDE := .byte

PO4A_SOURCES := $(CURDIR)/debian/xml-man/po4a/po4a.cfg

DOCBOOK_MANPAGE_SOURCES := $(CURDIR)/debian/xml-man/en/cam-config2.byte.xml  \
                           $(CURDIR)/debian/xml-man/en/cameleon2.byte.xml    \
                           $(CURDIR)/debian/xml-man/en/cam-mktop2.xml        \
                           $(CURDIR)/debian/xml-man/en/dbforge2.byte.xml     \
                           $(CURDIR)/debian/xml-man/en/dbforge2.gui.byte.xml \
                           $(CURDIR)/debian/xml-man/en/docbrowser2.byte.xml  \
                           $(CURDIR)/debian/xml-man/en/ocamlcvs2.byte.xml    \
                           $(CURDIR)/debian/xml-man/en/report2.byte.xml      \
                           $(CURDIR)/debian/xml-man/en/report2.gui.byte.xml  \
                           $(CURDIR)/debian/xml-man/en/tmpl_engine.byte.xml  \
                           $(CURDIR)/debian/xml-man/en/chamo.byte.xml        \
                           $(CURDIR)/debian/xml-man/en/ocamltdl2.byte.xml    \
                           $(CURDIR)/debian/xml-man/en/tdl.byte.xml	     \
                           $(CURDIR)/debian/xml-man/en/tdl_export.byte.xml   \
                           $(CURDIR)/debian/xml-man/en/make_my_chamo.xml     \
                           $(CURDIR)/debian/xml-man/en/tdl2html.byte.xml     \
                           $(CURDIR)/debian/xml-man/en/ocamlrss2.byte.xml    \
                           $(CURDIR)/debian/xml-man/en/rss_export.byte.xml   \
                           $(CURDIR)/debian/xml-man/en/tdl_svn.byte.xml

DOCBOOK_MANPAGE_EXTRA_SOURCES := $(CURDIR)/debian/xml-man/en/license.xml      \
                                 $(CURDIR)/debian/xml-man/en/refentryinfo.xml

OCAML_OCAMLDOC_PACKAGES_DOCBASE := cameleon-doc
OCAML_DHOCAML_FLAGS := -Xodoc_tdl.cma

# These cannot be erased by debian/clean mechanisms becore they are touched
# by upstream `make clean'
clean::
	-$(RM) '$(CURDIR)/src/custop/custop_installation.ml'

install/cameleon install/cameleon-doc install/libcameleon-ocaml-dev:: cameleon-install-extra

cameleon-install-extra: common-install-indep common-install-arch
	VERSION=$(DEB_NOEPOCH_VERSION); \
	VERSION=$${VERSION%%-*}; \
	sed -i "s/@VERSION@/$$VERSION/g" '$(CURDIR)/debian/META.cameleon'
	# Remove unused binaries
	$(RM) $(DESTDIR)/usr/bin/*.x
	# Move documentation (cameleon-doc)
	mv $(DESTDIR)/$(OCAML_STDLIB_DIR)/cameleon/*.odoc \
	  '$(DESTDIR_DOC)/$(OCAML_STDLIB_DIR)/cameleon'
	# Install library (libcameleon-ocaml-dev)
	mv '$(DESTDIR)/$(OCAML_STDLIB_DIR)/cameleon' \
	  '$(DESTDIR_DEV)/$(OCAML_STDLIB_DIR)'

.PHONY: cameleon-install-extra

MAKE_MY_CHAMO := $(DESTDIR)/usr/bin/make_my_chamo
install/cameleon::
	mv '$(MAKE_MY_CHAMO)' '$(MAKE_MY_CHAMO).tmp'
	(echo '#!/bin/sh'; cat '$(MAKE_MY_CHAMO).tmp') > '$(MAKE_MY_CHAMO)'
	$(RM) '$(MAKE_MY_CHAMO).tmp'
