#!/usr/bin/make -f
# debian/rules for confluence

#export DH_VERBOSE=1

ifeq ($(wildcard /usr/bin/ocamlopt),)
OCAML_DEP = ocaml-base-nox-$(shell ocamlc -version)
endif

build: build-stamp 

build-stamp:
	dh_testdir
	if [ -x /usr/bin/ocamlopt ]; then \
	$(MAKE) PREFIX=$(CURDIR)/debian/confluence/usr OCAMLC=ocamlc OCAMLOPT=ocamlopt; \
	else \
	$(MAKE) -C src PREFIX=$(CURDIR)/debian/confluence/usr OCAMLC=ocamlc fnf.byte cf.byte doc; \
	fi
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	$(MAKE) clean
	dh_clean cf.1 fnf.1

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs
	if [ -x /usr/bin/ocamlopt ]; then \
	$(MAKE) install PREFIX=$(CURDIR)/debian/confluence/usr OCAMLC=ocamlc OCAMLOPT=ocamlopt; \
	else \
	$(MAKE) -C src install-byte PREFIX=$(CURDIR)/debian/confluence/usr && \
	$(MAKE) install-cf PREFIX=$(CURDIR)/debian/confluence/usr; \
	fi
	find $(CURDIR)/debian/confluence/usr/share/confluence/ -name "*.cf" -exec chmod 644 {} \;
	$(CURDIR)/debian/confluence/usr/bin/cf  | txt2man -s 1 -t cf  > cf.1

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_install
	dh_installchangelogs 
	dh_installdocs
	dh_installexamples
	dh_installman cf.1 debian/manpages/fnf.1
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol -- -Vocaml:Depends=$(OCAML_DEP)
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install 
