#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/autoreconf.mk
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/gnome.mk
include /usr/share/cdbs/1/rules/utils.mk
include /usr/share/gnome-pkg-tools/1/rules/uploaders.mk
include /usr/share/gnome-pkg-tools/1/rules/gnome-version.mk
include /usr/share/gnome-pkg-tools/1/rules/gnome-get-source.mk

GNOME_MODULE := epiphany

LDFLAGS += -Wl,-O1 -Wl,--as-needed

DEB_CONFIGURE_EXTRA_FLAGS += \
		--disable-scrollkeeper \
		--enable-zeroconf \
		--libexecdir=\$${prefix}/lib/epiphany-browser \
		--enable-gtk-doc \
		--enable-introspection \
		--with-ca-file=/etc/ssl/certs/ca-certificates.crt

ifeq (,$(filter $(DEB_HOST_ARCH),ia64 mips))
DEB_CONFIGURE_EXTRA_FLAGS += \
		--enable-seed
endif

DEB_DH_INSTALLCHANGELOGS_ARGS_ALL := --no-act
DEB_INSTALL_DOCS_ALL := --no-act
DEB_DH_GIREPOSITORY_ARGS_ALL += -lsrc

binary-post-install/%::
	dh_installchangelogs -p$(cdbs_curpkg)
	dh_installdocs -p$(cdbs_curpkg)

binary-post-install/epiphany-browser::
	cd debian/epiphany-browser/usr/bin \
		&& mv epiphany epiphany-browser \
		&& mv epiphany.sh epiphany

binary-post-install/epiphany-browser-data::
	dh_installchangelogs -p$(cdbs_curpkg) ./ChangeLog
	cd debian/epiphany-browser-data/usr/share/man/man1 \
		&& mv epiphany.1 epiphany-browser.1
	cd debian/epiphany-browser-data/usr/share/applications \
		&& sed -r 's/^(Exec=epiphany-browser)/\1 -n/' epiphany.desktop | grep -v ^MimeType > epiphany-newtab.desktop \
		&& echo 'MimeType=x-scheme-handler/http;x-scheme-handler/https;' >> epiphany-newtab.desktop \
		&& echo 'NoDisplay=true' >> epiphany-newtab.desktop \
		&& sed -ri 's,x-scheme-handler/[^;]+;,,g' epiphany.desktop \
		&& mv epiphany.desktop epiphany-browser.desktop
	sed -i s/@PACKAGEVERSION@/$(DEB_VERSION)/ debian/branding.conf.in
	sed -i s/@DISTROID@/`lsb_release -is`/ debian/branding.conf.in
	sed -i s/@DISTROVERSION@/`lsb_release -rs`/ debian/branding.conf.in \
		&& mv debian/branding.conf.in debian/epiphany-browser-data/usr/share/epiphany-browser/branding.conf
