#!/usr/bin/make -f

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

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
  NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
  MAKEFLAGS += -j$(NUMJOBS)
endif

TMP=$(CURDIR)/debian/tmp/

%:
	dh $@ --with sphinxdoc --with autoreconf

override_dh_auto_clean:
	dh_testdir
	dh_auto_clean
	dh_clean
	debconf-updatepo
	-${RM} -rf docs/drizzled docs/html docs/pyext/*.pyc tests/kewpie

override_dh_autoreconf:
	python config/pandora-plugin write
	python config/pandora-plugin plugin-list
	dh_autoreconf config/autorun.sh


override_dh_auto_configure:
	CC=gcc-4.7 CXX=g++-4.7 dh_auto_configure -- \
	  --disable-rpath \
	  --localstatedir=/var/lib/drizzle \
	  --with-comment="Debian" $(shell dpkg-buildflags --export=configure) \
	  --disable-silent-rules \
	  F_LOOP_PARALLELIZE_ALL=""

override_dh_auto_build:
	${MAKE}
	${MAKE} doxygen
	${MAKE} html


override_dh_strip:
	dh_strip -Xdrizzled -Xplugin -Xbin --dbg-package=libdrizzle-dbg
	dh_strip -Xlibdrizzle.so --dbg-package=drizzle-dbg

override_dh_auto_test:
	echo "skipping tests"

override_dh_installdocs:
	dh_installdocs -A
	${RM} -f $(CURDIR)/debian/drizzle-doc/usr/share/doc/drizzle-doc/html/_sources/license.txt

override_dh_sphinxdoc:
	(test -d $(CURDIR)/debian/drizzle-doc && dh_sphinxdoc -Xlicense.txt) || /bin/true

grepdiff:
	bzr diff | grepdiff Copyright

scan-copyright:
	for f in `bzr status  --short | grep '^.[NM]' | awk '{print $$2}'` ; do [ -f $$f ] && bzr diff $$f | grep 'Copyright' && echo $$f; done

get-orig-source:
	# Uscan will read debian/watch, grab the correct version, repack, and
	# leave it in the current directory
	uscan --noconf --force-download --rename --repack \
	  --download-current-version --destdir=.
