#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
# modified by Tamas SZERB <toma@rulez.org>

WAY=`pwd`/debian/oops

#see the debian/dirs what needs to apply these:
#$(WAY)/etc/oops 
DIRS=$(WAY)/var/log/oops \
	$(WAY)/var/spool/oops \
	$(WAY)/var/run/oops

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

# This is the debhelper compatability version to use.
export DH_COMPAT=2

build: build-stamp
build-stamp:
	dh_testdir

	diff /usr/share/misc/config.guess config.guess >/dev/null \
		|| \
		mv config.guess config.guess.old;\
		cp /usr/share/misc/config.guess config.guess;\
		echo "Newer config.guess will be used."

	diff /usr/share/misc/config.sub config.sub >/dev/null \
		|| \
		mv config.sub config.sub.old;\
		cp /usr/share/misc/config.sub config.sub;\
		echo "Newer config.sub will be used."

	./configure \
		--sbindir=/usr/sbin \
		--sysconfdir=/etc/oops \
		--localstatedir=/var/run/oops \
		--libdir=/usr/lib/oops \
		--enable-large-files \
		--with-regexp=pcre \
		--enable-oops-user=proxy \
		--prefix=/usr/lib

	# Add here commands to compile the package.
	$(MAKE) \
		OOPSPATH=/var/spool/oops \
		OOPS_SBINDIR=/usr/sbin \
		OOPS_SYSCONFDIR=/etc/oops \
		OOPS_LOCALSTATEDIR=/var/run/oops \
		OOPS_LIBDIR=/usr/lib/oops

	touch build-stamp

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

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean

	dh_clean
	rm -f `pwd`/debian/oops.conffiles
	if [ -f config.guess.old ]; then \
		mv config.guess.old config.guess;\
	fi
	if [ -f config.sub.old ]; then \
		mv config.sub.old config.sub;\
	fi

install: install-stamp
install-stamp: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/tmp.
	$(MAKE) install \
		OOPSPATH=$(WAY)/var/spool/oops \
		OOPS_SBINDIR=$(WAY)/usr/sbin \
		OOPS_SYSCONFDIR=$(WAY)/etc/oops \
		OOPS_LOCALSTATEDIR=$(WAY)/var/run/oops \
		OOPS_LIBDIR=$(WAY)/usr/lib/oops

	touch install-stamp

# 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_testversion
	dh_testdir
	dh_testroot
	dh_installdebconf	
	dh_installdocs

	dh_installexamples
	wget -T 5 -t 3 http://nrg.martos.bme.hu/release/adfilter \
		-O debian/adfilter && dh_installexamples debian/adfilter \
		|| true

	dh_installmenu
#	dh_installemacsen
#	dh_installpam
	dh_installinit -- defaults 30
#	dh_installcron

	rm -Rf $(WAY)/var/spool/oops/logs
	rm -Rf $(WAY)/usr/lib/oops/modules

	chmod +x `pwd`/debian/cfg.pl
	`pwd`/debian/cfg.pl > $(WAY)/etc/oops/oops.cfg

	#potato?
	if [ -x /usr/bin/dh_installlogrotate ]; then \
		dh_installlogrotate; \
	else \
		mkdir -p $(WAY)/etc/logrotate.d/; \
		cp `pwd`/debian/oops.logrotate $(WAY)/etc/logrotate.d/oops; \
	fi

	dh_installpam
	dh_installmanpages
	dh_installinfo
#	dh_undocumented
	dh_installchangelogs
	dh_link
#debug:
	dh_strip
#:debug
	dh_compress

	dh_fixperms
	#see the debian/dirs and DIRS what needs to apply these:
	find $(DIRS) -type d -exec chown proxy:proxy {} \;
	find $(DIRS) -type d -exec chmod 750 {} \;
	find $(DIRS) -type f -exec chown proxy:proxy {} \;
	find $(DIRS) -type f -exec chmod 640 {} \;

#	# You may want to make some executables suid here.
#	dh_suidregister
#	dh_makeshlibs
	#Toma: create oops.conffiles automagically:
	find $(WAY)/etc -type f|sed s:$(WAY):: >`pwd`/debian/oops.conffiles
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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