#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export CFLAGS := $(shell dpkg-buildflags --get CFLAGS) $(shell dpkg-buildflags --get CPPFLAGS)
export CXXFLAGS := $(shell dpkg-buildflags --get CXXFLAGS) $(shell dpkg-buildflags --get CPPFLAGS)
export LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS) -Wl,--as-needed

# Filter -g from environment on troublesome arches. Replace it with -gstabs
# See also: stabs_format_debug_info.diff
DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
ifneq (,$(filter $(DEB_HOST_ARCH),s390 s390x armel armhf mips mipsel))
    export DEB_CFLAGS_MAINT_STRIP := -g
    export DEB_CFLAGS_MAINT_APPEND := -gstabs
    export DEB_CXXFLAGS_MAINT_STRIP := -g
    export DEB_CXXFLAGS_MAINT_APPEND := -gstabs
endif
ifneq (,$(filter $(DEB_HOST_ARCH),alpha))
    export DEB_LDFLAGS_MAINT_APPEND := -Wl,--no-relax
endif

%:
	dh $@ --parallel --list-missing --dbg-package=libqt5webkit5-dbg --with pkgkde_symbolshelper

override_dh_auto_configure:
	qmake

override_dh_auto_install:
	make install INSTALL_ROOT=$(CURDIR)/debian/tmp
	
	# Remove rpath from the offending binaries
	chrpath -d $(CURDIR)/debian/tmp/usr/lib/*/qt5/libexec/QtWebProcess
	chrpath -d $(CURDIR)/debian/tmp/usr/lib/*/qt5/libexec/QtWebPluginProcess
	
	# Remove la files (http://wiki.debian.org/ReleaseGoals/LAFileRemoval)
	rm -f debian/tmp/usr/lib/*/*.la

override_dh_builddeb:
	dh_builddeb -- -Zxz
