#!/usr/bin/make -f
#-*- makefile -*-
# Made with the aid of dh_make, by Craig Small
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# Some lines taken from debmake, by Christoph Lameter.

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

export DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)

DDEBUG=`if (echo $(DEB_BUILD_OPTIONS) | grep -q debug) then \
			echo "--enable-debug"; \
		else \
			echo ""; \
		fi`

configure: configure-stamp
configure-stamp:
	dh_testdir
	aclocal
	autoheader
	automake --foreign --add-missing
	autoconf
	./configure --prefix=/usr \
               --enable-ssl \
               --enable-spoof-source \
               --enable-tcp-wrapper \
               $(DDEBUG) \
               --mandir=/usr/share/man \
               --sysconfdir=/etc/syslog-ng \
               --enable-dynamic-linking \
               --localstatedir=/var/lib/syslog-ng

	touch $@

build: build-stamp
build-stamp: configure
	dh_testdir
	$(MAKE) 
#	(cd doc; $(MAKE) reference/syslog-ng.html.tar.gz)

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f configure-stamp build-stamp

	# Add here commands to clean up after the build process.
	[ ! -f Makefile ] || $(MAKE) distclean 
	rm -f tests/functional/test.conf tests/functional/test-output.log
	rm -f config.log
	rm -f depcomp aclocal.m4 install-sh missing mkinstalldirs configure
	rm -f doc/reference/syslog-ng.html.tar.gz
	rm -f doc/reference/syslog-ng.html/index.html src/cfg-grammar.c
	rm -f src/cfg-grammar.h src/cfg-lex.c ylwrap
	find . -name Makefile.in | xargs rm -f

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_install
#	dh_installdirs
	dh_installdocs NEWS

	# Add here commands to install the package into debian/syslog-ng/ .
	$(MAKE) install DESTDIR=`pwd`/debian/syslog-ng

	# Fix config file for kfreebsd-*
ifeq ($(DEB_HOST_ARCH_OS), kfreebsd)
	sed -i 's/\/dev\/log/\/var\/run\/log/' debian/syslog-ng/etc/syslog-ng/syslog-ng.conf
endif
#	install -d -m 700 debian/syslog-ng/usr/share/doc/syslog-ng/html
	rm -f debian/syslog-ng/usr/share/doc/syslog-ng/INSTALL
	rmdir debian/syslog-ng/usr/libexec/
#	(cd debian/syslog-ng/usr/share/doc/syslog-ng/html; tar -xzvf ../../../../../../../doc/reference/syslog-ng.html.tar.gz; mv syslog-ng.html/* .; rmdir syslog-ng.html)

# 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_installexamples
	dh_installinit --no-start -- defaults 10 90
	dh_installcron
	dh_installlogrotate
	dh_installlogcheck
	dh_installchangelogs ChangeLog
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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