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

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

CFLAGS = -Wall -g

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

#Architecture 
build: build-indep

build-indep: build-indep-stamp
build-indep-stamp: patch

	# Add here commands to compile the indep part of the package.
	python setup.py build

	touch $@

clean: clean1 unpatch
clean1:
	dh_testdir
	dh_testroot
	rm -f build-indep-stamp
#	-mv $(CURDIR)/setup.cfg.orig $(CURDIR)/setup.cfg

	python setup.py clean

	#find $(CURDIR)/freddist/ -name \*.pyc -exec rm {} \;

	dh_clean

install: install-indep
install-indep:
	dh_testdir
	dh_testroot
	dh_clean -k -i
	dh_installdirs -i

	python setup.py install \
		--no-check-deps \
		--root=$(CURDIR)/debian/tmp \
		--preservepath \
		--sysconfdir=/etc/ \
		--prefix=/usr \
	        --localstatedir=/var \
		--drill=/bin/true \
		--sendmail=/bin/true \
		--include-scripts

	install -m 640 $(CURDIR)/debian/genzone.conf $(CURDIR)/debian/pyfred-genzone/etc/fred/
	install -m 640 $(CURDIR)/debian/pyfred.conf  $(CURDIR)/debian/fred-pyfred/etc/fred/
	install -m 640 $(CURDIR)/debian/fred-pyfred.event.d $(CURDIR)/debian/fred-pyfred/etc/event.d/fred-pyfred

	dh_install -i --sourcedir=debian/tmp

binary-common:
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
	dh_installinit -- defaults 40
	dh_installcron
	dh_pysupport
	dh_link
	dh_strip
	dh_compress 
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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

binary-arch:
	$(MAKE) -f debian/rules DH_OPTIONS=-s binary-common

# And now the simple things for dpatch. Here we only apply/unapply the patches.
# You can do more things with dpatch, like having patches only applied on
# a special architecture - see the non-dh version of the sample for this!
patch: patch-stamp
patch-stamp:
	dpatch apply-all
	dpatch cat-all >patch-stamp
	touch patch-stamp

unpatch:
	dpatch deapply-all
	rm -rf patch-stamp debian/patched


binary: binary-indep
.PHONY: build clean binary-indep binary install install-indep configure patch unpatch clean1
