#!/usr/bin/make -f

OCAMLABI := $(shell ocamlc -version)

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	rm -rf $(CURDIR)/build
	rm -f $(CURDIR)/zeroinstall/__init__.pyc
	rm -f $(CURDIR)/zeroinstall/__pycache__
	dh_clean 

build: build-arch
build-indep:
build-arch: build-stamp

build-stamp:
	dh_testdir
	if [ -x /usr/bin/ocamlopt ]; then \
		make -C $(CURDIR) ocaml TYPE=native; \
	else \
		make -C $(CURDIR) ocaml TYPE=byte; \
	fi
	touch $@

install: build-stamp
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	python3 $(CURDIR)/setup.py install --install-layout=deb --root=$(CURDIR)/debian/zeroinstall-injector
	python $(CURDIR)/setup.py install --force --install-layout=deb --root=$(CURDIR)/debian/zeroinstall-injector
	rm -r $(CURDIR)/debian/zeroinstall-injector/usr/man
	if [ -x /usr/bin/ocamlopt ]; then \
		dh_strip; dh_shlibdeps; \
	fi

binary-arch: build-stamp install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
	dh_installman 0launch.1 0alias.1 0store.1 0store-secure-add.1 0desktop.1 0install.1
	dh_compress
	dh_fixperms
	dh_python3
	dh_python2
	dh_ocaml
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-indep: build-stamp install
# We have nothing to do by default.

binary: binary-indep binary-arch

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