#!/usr/bin/make -f
# -*- makefile -*-

#export DH_VERBOSE=1

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

CONFFLAGS := --prefix=/usr --mandir=/usr/share/man
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
	CONFFLAGS += --build=$(DEB_BUILD_GNU_TYPE)
else
	CONFFLAGS += --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE)
endif

configure: configure-stamp
configure-stamp:
	dh_testdir
	./configure $(CONFFLAGS) $(shell dpkg-buildflags --export=configure)
	touch configure-stamp
build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp: configure-stamp  
	dh_testdir
	$(MAKE)
	touch $@
clean:
	dh_testdir
	dh_testroot
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f build-stamp configure-stamp config.log
	dh_clean 
install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	# Add here commands to install the package into debian/mlmmj.
	$(MAKE) DESTDIR=$(CURDIR)/debian/mlmmj install
	rm $(CURDIR)/debian/mlmmj/usr/bin/mlmmj-make-ml.sh
	install -m 755 -D $(CURDIR)/debian/mlmmj-make-ml.Debian \
		$(CURDIR)/debian/mlmmj/usr/share/doc/mlmmj/mlmmj-make-ml.Debian
	dh_install -s
# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	# mlmmj-php-web
	install -m 644 -D $(CURDIR)/contrib/web/php-user/mlmmj.php \
		$(CURDIR)/debian/mlmmj-php-web/usr/share/mlmmj-php-web/mlmmj.php
	install -m 644 -D $(CURDIR)/contrib/web/php-user/README \
		$(CURDIR)/debian/mlmmj-php-web/usr/share/doc/mlmmj-php-web/README
	install -m 644 -D $(CURDIR)/contrib/web/php-user/example.html \
		$(CURDIR)/debian/mlmmj-php-web/usr/share/doc/mlmmj-php-web/examples/examples.html
	# mlmmj-php-web-admin
	install -d $(CURDIR)/debian/mlmmj-php-web-admin/usr/share/mlmmj-php-web-admin
	install -m 644 $(CURDIR)/contrib/web/php-admin/htdocs/*.php \
		$(CURDIR)/debian/mlmmj-php-web-admin/usr/share/mlmmj-php-web-admin/
	install -m 644 $(CURDIR)/contrib/web/php-admin/htdocs/dot.htaccess \
		$(CURDIR)/debian/mlmmj-php-web-admin/usr/share/mlmmj-php-web-admin/.htaccess
	install -m 644 -D $(CURDIR)/contrib/web/php-admin/README \
		$(CURDIR)/debian/mlmmj-php-web-admin/usr/share/doc/mlmmj-php-web-admin/README
	install -d $(CURDIR)/debian/mlmmj-php-web-admin/usr/share/mlmmj-php-web-admin/conf
	install -d $(CURDIR)/debian/mlmmj-php-web-admin/usr/share/mlmmj-php-web-admin/templates
	install -m 644 $(CURDIR)/contrib/web/php-admin/conf/* \
		$(CURDIR)/debian/mlmmj-php-web-admin/usr/share/mlmmj-php-web-admin/conf/
	install -m 644 $(CURDIR)/contrib/web/php-admin/templates/* \
		$(CURDIR)/debian/mlmmj-php-web-admin/usr/share/mlmmj-php-web-admin/templates/
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb
# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
#       dh_install
#       dh_installmenu
	dh_installdebconf       
#       dh_installlogrotate
#       dh_installemacsen
#       dh_installpam
#       dh_installmime
#       dh_python
#       dh_installinit
	dh_installcron
#       dh_installinfo
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#       dh_perl
#       dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb
binary: binary-indep binary-arch
.PHONY: build build-arch build-indep clean binary-indep binary-arch binary install configure
