#!/usr/bin/make -f

# add if we don't want optimisations
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
	DEB_BUILD_CONFIG_OPTIONS += --disable-optimizations
endif

ifneq (,$(findstring parallel=,$(DEB_BUILD_OPTIONS)))
	NCPUS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
else
	NCPUS := $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
	ifeq ($(NCPUS),-1)
		NCPUS:=1
	endif
	ifeq ($(NCPUS),0)
		NCPUS:=1
	endif
endif

# set configure flags here
CONFIGURE_FLAGS := \

%:
	dh $@ --with quilt

override_dh_autoreconf:
	dh_autoreconf --as-needed

override_dh_auto_configure:
	dh_auto_configure -- \
	--disable-dxr3 \
	--disable-gnomevfs \
	--disable-nosefart \
	--disable-rpath \
	--disable-vidix \
	--enable-directfb \
	--enable-ipv6 \
	--enable-v4l2 \
	--enable-vdpau \
	--with-external-dvdnav \
	--with-freetype \
	--with-jack \
	--with-libflac \
	--with-pulseaudio \
	--with-wavpack \
	--with-xcb \
	$(DEB_BUILD_CONFIG_OPTIONS) \
	LIBMODPLUG_LIBS="$(filter-out -lstdc++ -lm,$(shell pkg-config --libs libmodplug))" \
	CFLAGS="$(shell dpkg-buildflags --get CFLAGS)" \
	CPPFLAGS="$(shell dpkg-buildflags --get CPPFLAGS)" \
	CXXFLAGS="$(shell dpkg-buildflags --get CXXFLAGS)" \
	LDFLAGS="$(shell dpkg-buildflags --get LDFLAGS)" \
	XCB_LIBS="$(shell pkg-config --libs xcb xcb-shape xcb-shm)"

#	exit 1

override_dh_auto_build:
	$(MAKE) -j $(NCPUS)

override_dh_clean:
	dh_clean build-stamp configure-stamp install-stamp po/*.gmo \
	po/stamp-po config.h config.log po/Makevars.extra a.out

override_dh_installdocs:
	dh_installdocs -A TODO

override_dh_install:
	find debian/tmp -name *.la -delete

	-rm debian/tmp/usr/share/doc/xine-lib/ChangeLog
	-rm debian/tmp/usr/share/doc/xine-lib/README.solaris
	-rm debian/tmp/usr/share/doc/xine-lib/README.irix
	-rm debian/tmp/usr/share/doc/xine-lib/COPYING
	-rm debian/tmp/usr/share/doc/xine-lib/TODO
	-rm debian/tmp/usr/share/doc/xine-lib/faq.txt
	-rm debian/tmp/usr/share/doc/xine-lib/CREDITS
	-rm debian/tmp/usr/share/doc/xine-lib/README.WIN32
	-rm debian/tmp/usr/share/doc/xine-lib/README.network_dvd
	-rm debian/tmp/usr/share/doc/xine-lib/faq.html
	-rm debian/tmp/usr/share/doc/xine-lib/README.dxr3
	-rm debian/tmp/usr/share/doc/xine-lib/README.macosx
	-rm debian/tmp/usr/share/doc/xine-lib/NEWS
	-rm debian/tmp/usr/share/doc/xine-lib/README.cetus
	-rm debian/tmp/usr/share/doc/xine-lib/README.MINGWCROSS
	-rm debian/tmp/usr/share/doc/xine-lib/README.freebsd
	-rm debian/tmp/usr/lib/*/xine/plugins/2.7/mime.types

	dh_install

override_dh_missing:
	dh_missing --fail-missing

# No tests
override_dh_auto_test:
