#!/usr/bin/make -f
#export DH_VERBOSE=1

# Use this variable to set all required PackageKit configure flags
# We set aptcc as default backend and disable gobject-introspection
# (pass --enable-introspection to enable it again)
PK_CONFIGURE_FLAGS = --disable-static \
		--disable-tests \
		--enable-gtk-doc \
		--disable-cron \
		--enable-apt --enable-aptcc --enable-smart \
		--disable-local \
		--with-default-backend=aptcc \
		--enable-browser-plugin \
		--enable-gtk-module \
		--enable-gstreamer-plugin \
		--enable-command-not-found

LDFLAGS += -Wl,--as-needed

ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes), yes)
	SUBSTVARS = -Vdist:Browser="firefox (>> 3.0) | www-browser"
else
	SUBSTVARS = -Vdist:Browser="iceweasel (>> 3.0) | www-browser"
endif

# Define install and build directory
INSTALLDIR = $(CURDIR)/debian/tmp

%:
	dh $@ --parallel --with autotools_dev --with python2

override_dh_auto_configure:
	cp -dpr $(CURDIR)/docs/api $(CURDIR)/docs/api.orig
	dh_auto_configure -- $(PK_CONFIGURE_FLAGS)
	
override_dh_auto_install:
	dh_auto_install --destdir=$(INSTALLDIR)

	# Those files do not need to be installed
	rm -f $(INSTALLDIR)/usr/lib/packagekit-backend/*.la
	rm -f $(INSTALLDIR)/usr/lib/mozilla/plugins/packagekit-plugin.la
	rm -f $(INSTALLDIR)/usr/lib/gtk-?.0/modules/*.la
	rm -f $(INSTALLDIR)/usr/lib/polkit-1/extensions/libpackagekit-action-lookup.la
	rm -f $(INSTALLDIR)/usr/bin/packagekit-bugreport.sh
	# And these files should be cleaned to remove dependency_libs.
	for file in $(INSTALLDIR)/usr/lib/*.la; do \
		sed -i "/dependency_libs/ s/'.*'/''/" $$file ; \
	done

override_dh_install:
	dh_install --list-missing

override_dh_makeshlibs:
	dh_makeshlibs -Xlibpk-gtk-module -Xlibpackagekit-action-lookup -Xlibpk_ -Xpackagekit-plugin

override_dh_auto_clean:
	dh_auto_clean
	# Restore documentation
	if test -d $(CURDIR)/docs/api.orig; then \
		rm -rf $(CURDIR)/docs/api; \
		mv $(CURDIR)/docs/api.orig $(CURDIR)/docs/api; \
	fi

override_dh_gencontrol:
	dh_gencontrol -- $(SUBSTVARS)
