#!/usr/bin/make -f

#export DH_VERBOSE=1

include /usr/share/ocaml/ocamlvars.mk

ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  confflags += --build $(DEB_HOST_GNU_TYPE)
else
  confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

override_dh_auto_clean:
# Update the PO, as suggested in "man 7 po-debconf"
	debconf-updatepo
# Add here commands to clean up after the build process.
	$(MAKE) clean distclean
	$(MAKE) -C debian/xml-man clean
	$(MAKE) -C debian/utils clean
	-$(RM) config/trying
	-$(RM) packages/rpm/Makefile
	-$(RM) *.ini *.ini.old
	-$(RM) config/confdefs.h

override_dh_auto_configure:
	cd config; autoconf
	./configure $(confflags) $(shell dpkg-buildflags --export=configure) \
	  --enable-gui=newgui2 \
	  --enable-directconnect \
          --disable-magic \
	  --disable-fasttrack

override_dh_auto_build:
	$(MAKE) utils.$(OCAML_BEST) $(OCAML_BEST)
ifeq ($(OCAML_BEST),byte)
	cp mlnet.byte mlnet
	cp mlgui.byte mlgui
	cp mlguistarter.byte mlguistarter
endif
# Check that the compilation has succeeded
	test -x mlnet
	test -x mlgui
# Make manpages
	$(MAKE) -C debian/xml-man all
# Build utilities
	make -C debian/utils TARGET=$(OCAML_BEST)

override_dh_auto_install:
	$(RM) $(CURDIR)/debian/mldonkey-server/usr/share/doc/mldonkey-server/distrib/Copying.txt
	$(RM) $(CURDIR)/debian/mldonkey-server/usr/share/doc/mldonkey-server/distrib/GeoIP_LICENSE.txt

override_dh_installinit:
	dh_installinit -a -pmldonkey-server --error-handler=init_error -- start 98 2 3 4 5 . stop 20 0 1 6 .

override_dh_strip:
ifeq ($(OCAML_BEST),opt)
	dh_strip -a
endif

%:
	dh $@ --with ocaml
