#!/usr/bin/make -f
# debian/rules for cadaver
#
# Written by Sebastian Harl <sh@tokkee.org>.

# Uncomment this to turn on verbose mode.
#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)

CFLAGS = -Wall -g

BUILDDIR = ./debian/build/

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

include /usr/share/dpatch/dpatch.make

$(BUILDDIR)/config.status: configure $(DPATCH_STAMPFN)
	dh_testdir
	
	for file in config.guess config.sub; do \
		mv $$file $$file.upstream; \
		ln -s /usr/share/misc/$$file .; \
	done
	
	[ -e $(BUILDDIR) ] || mkdir $(BUILDDIR)
	cd $(BUILDDIR) && LDFLAGS="-L/usr/lib" PKG_CONFIG_PATH="/usr/lib/pkgconfig" ../../configure --host=$(DEB_HOST_GNU_TYPE) \
	                --build=$(DEB_BUILD_GNU_TYPE) \
			--prefix=/usr --mandir=\$${prefix}/share/man \
			--enable-warnings --enable-netrc --with-ssl=ssl --with-libxml2 #--with-neon=/usr/

build: build-stamp

build-stamp: $(BUILDDIR)/config.status
	dh_testdir
	dh_clean
	
	cp -r ./src/ $(BUILDDIR)
	$(MAKE) -C $(BUILDDIR)
	
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	
	rm -rf $(BUILDDIR)
	rm -f po/*.gmo
	
	for file in config.guess config.sub; do \
		if [ -e $$file.upstream ]; then \
			rm -f $$file; \
			mv $$file.upstream $$file; \
		fi \
	done
	
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	
	$(MAKE) -C $(BUILDDIR) DESTDIR=$(CURDIR)/debian/tmp install 
	
	dh_install -s
	

# Must not depend on anything. This is to be called by
# binary-arch/binary-indep
# in another 'make' thread.
binary-common:
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
#	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

# Build architecture independant packages using the common target.
binary-indep: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-s binary-common

binary: binary-indep binary-arch
.PHONY: build clean install binary-indep binary-arch binary

