#!/usr/bin/make -f

#export DH_VERBOSE=1

ifeq ($(shell test -x /usr/bin/ocamlopt -o -x /usr/bin/ocamlopt.opt && echo true),true)
  OCAMLC = ocamlopt
  OCAMLOBJECT = cmx
  OCAMLARCHIVE = cmxa
  OCAMLCUSTOM = 
  OCAMLSTRIP =
  OCAMLDEPS = ocaml:Depends=
else
  OCAMLC = ocamlc
  OCAMLOBJECT = cmo
  OCAMLARCHIVE = cma
  OCAMLCUSTOM = -custom
  OCAMLSTRIP = -Xmtasc
  OCAMLDEPS = ocaml:Depends=ocaml-base-nox-$(shell ocamlfind ocamlc -version)
endif

ifeq ($(shell test -x /usr/bin/camlp4o.opt && echo true),true)
  CAMLP4 = camlp4o.opt
else ifeq ($(shell test -x /usr/bin/camlp4o && echo true),true)
  CAMLP4 = camlp4o
endif

%:
	dh $@ --parallel

override_dh_auto_build:
	$(MAKE) -f ocaml/mtasc/doc/Makefile C=$(OCAMLC) O=$(OCAMLOBJECT) A=$(OCAMLARCHIVE) CU=$(OCAMLCUSTOM) CP=$(CAMLP4)
	cp ocaml/mtasc/doc/CHANGES.txt NEWS

override_dh_auto_test:
	./ocaml/mtasc/mtasc -v -swf helloworld.swf -main -header 640:480:20 ocaml/mtasc/doc/HelloWorld.as
	./ocaml/mtasc/mtasc -version 8 -v -swf helloworld.swf -main -header 640:480:20 ocaml/mtasc/doc/HelloWorld.as

override_dh_auto_clean:
	[ ! -f ocaml/mtasc/doc/Makefile ] || $(MAKE) -f ocaml/mtasc/doc/Makefile clean

override_dh_auto_install:
	$(MAKE) -f ocaml/mtasc/doc/Makefile install PREFIX=/usr DESTDIR=debian/mtasc

override_dh_strip:
	dh_strip $(OCAMLSTRIP)

override_dh_gencontrol:
	dh_gencontrol -- -V$(OCAMLDEPS)

UPSTREAM_VERSION = $(shell dpkg-parsechangelog | sed -n 's/Version: \(.*\)-[^-]*/\1/p')

get-orig-source:
	sh debian/maketarball --upstream-version $(UPSTREAM_VERSION)
