#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/ocaml/ocamlvars.mk
include /usr/share/ocaml/ocamlinit.mk

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O3
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

%:
	dh $@ --with ocaml

.PHONY: override_dh_auto_build
override_dh_auto_build:
	$(MAKE) libagrep.a agrep.cma
ifneq ($(OCAML_OPT_ARCH),)
	$(MAKE) agrep.cmxa
endif

.PHONY: override_dh_clean
override_dh_clean:
	rm -rf debian/doc

.PHONY: override_dh_auto_install
override_dh_auto_install:
	mkdir -p debian/tmp/$(OCAML_STDLIB_DIR)/agrep
	# Default install doesn't handle no-ocamlopt platforms
	cp $(wildcard *.cmi *.cma *.cmxa *.a *.so *.mli) debian/tmp/$(OCAML_STDLIB_DIR)/agrep
	mkdir -p debian/doc/html
	$(OCAML_OCAMLDOC) -html -m A -keep-code -d debian/doc/html agrep.mli
