#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk

DEB_DH_MAKESHLIBS_ARGS := -Xavg
PYTHON_VERSIONS        := $(shell pyversions -vr)
CONFIGURE_ARGS         := --prefix=/usr --mandir=/usr/share/man \
  --with-boost-thread=boost_thread-mt

CHECK_DIRS := base graphics lmfit player conradrelais imaging parport python video
CXXFLAGS               := -D__STDC_CONSTANT_MACROS

makebuilddir/python-libavg::
	./bootstrap

configure/python-libavg:: $(addprefix debian/stamp-configure, $(PYTHON_VERSIONS))
debian/stamp-configure%:
	mkdir build$*
	cd build$* && ../configure $(CONFIGURE_ARGS) PYTHON=python$* \
	  BOOST_PYTHON_LIBS=-lboost_python-py$(subst .,,$*)
	touch $@

build/python-libavg:: $(addprefix debian/stamp-build, $(PYTHON_VERSIONS))
debian/stamp-build%:
	make -C build$*
	touch $@

install/python-libavg:: $(addprefix debian/stamp-install, $(PYTHON_VERSIONS))
	dh_pycentral -p$(cdbs_curpkg)
debian/stamp-install%:
	-make -C build$*/src check SUBDIRS="$(CHECK_DIRS)"
	make -C build$* install DESTDIR=$(DEB_DESTDIR)
	rmdir -p --ignore-fail-on-non-empty $(DEB_DESTDIR)/usr/share/avg
	mv $(DEB_DESTDIR)/usr/bin/avg_showfont.py \
	  $(DEB_DESTDIR)/usr/bin/avg_showfont
	mv $(DEB_DESTDIR)/usr/bin/avg_videoplayer.py \
	  $(DEB_DESTDIR)/usr/bin/avg_videoplayer
	mv $(DEB_DESTDIR)/usr/bin/avg_showcamera.py \
	  $(DEB_DESTDIR)/usr/bin/avg_showcamera
	mv $(DEB_DESTDIR)/usr/bin/avg_videoinfo.py \
	  $(DEB_DESTDIR)/usr/bin/avg_videoinfo
	touch $@

clean::
	$(RM) -r build* debian/stamp-*

get-orig-source:
	uscan --force-download --download-version $(DEB_UPSTREAM_VERSION) --rename
