#!/usr/bin/make -f

include /usr/share/ocaml/ocamlvars.mk
include /usr/share/dpkg/pkg-info.mk
export DEB_VERSION_UPSTREAM
export OCAMLBUILD_BEST

MAN_NAME_SECTION="Tool merging math and logic for executable definitions"

%:
	dh $@ --with ocaml

override_dh_auto_build:
	$(MAKE)

# Some files generated from the lem library, so they don't have .mli files and
# if for documentation purposes it's better to refer to the .lem source files.
# The $(cp) will copy these files which already available .mli file, but this should
# be harmless. See README.Debian and https://github.com/rems-project/lem/issues/34
execute_after_dh_auto_install:
	cp $(CURDIR)/ocaml-lib/_build_num/*.ml $(CURDIR)/debian/tmp/lem_num/
	cp $(CURDIR)/ocaml-lib/_build_zarith/*.ml $(CURDIR)/debian/tmp/lem_zarith/
	help2man $(CURDIR)/debian/tmp/bin/lem --name=$(MAN_NAME_SECTION) --version-string=$(DEB_VERSION_UPSTREAM) > debian/lem.1

override_dh_auto_clean:
	rm -rf bin/lem
	rm -rf lem
	rm -rf src/main.native
	rm -rf src/_build
	rm -rf src/version.ml
	rm -rf src/share_directory.ml
	rm -rf coq-lib/lem_*.v
	rm -rf library/ocaml-build-dir*
	rm -rf ocaml-lib/lem_*.ml
	rm -rf ocaml-lib/_build_num
	rm -rf ocaml-lib/_build_zarith
	rm -rf hol-lib/lemTheory.sml
	rm -rf hol-lib/lem_*.sml
	rm -rf html-lib/*.html
	rm -rf isabelle-lib/Lem_*.thy
	rm -rf tex-lib/lem-libs*.tex
	dh_clean
