#!/usr/bin/make -f

#export DH_VERBOSE=1

DEB_HOST_ARCH       ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)

# Used to enable documentation if dependencies are available
define cond_enable
	$(shell if test -x /usr/bin/doxygen && test -x /usr/bin/dot \
		&& test -x /usr/bin/pdftex; then echo --enable-documentation; \
		else echo --disable-documentation; fi )
endef

CONFIGURE_OPTIONS ?= $(call cond_enable) \
		     --enable-dri2

32-ARCHS=amd64
ifneq (,$(findstring $(DEB_HOST_ARCH), $(32-ARCHS)))
EXTRA_CONFIGURE	+= configure32
EXTRA_BUILD	+= build32
EXTRA_INSTALL	+= install32
endif

%:
	dh $@

binary: binary-indep binary-arch ;

override_dh_auto_configure: $(EXTRA_CONFIGURE)
	dh_testdir
	./configure --prefix=/usr $(CONFIGURE_OPTIONS)

configure32:
	dh_testdir
	mkdir debian/32
	cd debian/32 && CC="$(CC) -m32" CXX="$(CXX) -m32" \
		../../configure --prefix=/usr --libdir=/usr/lib32 \
		$(CONFIGURE_OPTIONS)

override_dh_auto_build: $(EXTRA_BUILD)
	dh_auto_build

build32:
	dh_auto_build --sourcedirectory=debian/32

override_dh_auto_install: $(EXTRA_INSTALL)
	dh_auto_install

install32:
	dh_auto_install --sourcedirectory=debian/32

clean:
	dh clean
	rm -rf debian/32

get-orig-source:
	$(dir $_)libvdpau-get-orig-source
