#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

config.status: configure
	./configure --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info \
				--with-newpki-include=/usr/include/newpki


build: config.status
	dh_testdir

	$(MAKE)

clean:
	dh_testdir
	dh_testroot
	debconf-updatepo

	# Add here commands to clean up after the build process.
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f config.log
	rm -f publication/file/config.status publication/file/config.log
	rm -f publication/ldap/config.status publication/ldap/config.log
#	rm -f po/fr.gmo config.log

#ifneq "$(wildcard /usr/share/misc/config.sub)" ""
#	cp -f /usr/share/misc/config.sub config.sub
#endif
#ifneq "$(wildcard /usr/share/misc/config.guess)" ""
#	cp -f /usr/share/misc/config.guess config.guess
#endif

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep 
	dh_installdirs

	$(MAKE) install DESTDIR=$(CURDIR)/debian/newpki-server libdir=/usr/lib/newpki-server

	install -p -o root -g root -m 644 $(CURDIR)/debian/overrides $(CURDIR)/debian/newpki-server/usr/share/lintian/overrides/newpki-server

	install -m 755 -d $(CURDIR)/debian/newpki-server/usr/share/man/man1/
	install -m 644 $(CURDIR)/docs/newpki-server.1.gz $(CURDIR)/debian/newpki-server/usr/share/man/man1/
	gunzip $(CURDIR)/debian/newpki-server/usr/share/man/man1/newpki-server.1.gz

	install -m 644 $(CURDIR)/publication/file/src/publication_file_crl.xml $(CURDIR)/debian/newpki-server/etc/newpki/
	install -m 644 $(CURDIR)/publication/file/src/publication_file_cert.xml $(CURDIR)/debian/newpki-server/etc/newpki/
	install -m 644 $(CURDIR)/publication/ldap/src/publication_ldap_crl.xml $(CURDIR)/debian/newpki-server/etc/newpki/
	install -m 644 $(CURDIR)/publication/ldap/src/publication_ldap_cert.xml $(CURDIR)/debian/newpki-server/etc/newpki/

	find $(CURDIR)/debian/newpki-server/usr/lib/newpki-server -name "*.la" -delete
	find $(CURDIR)/debian/newpki-server/usr/lib/newpki-server -name "*.so.0.0.0" -exec chrpath -d {} \;

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# 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_installinit
#	dh_installcron
#	dh_installinfo
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_python
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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