#!/usr/bin/make -f

export DH_VERBOSE=1

DEB_CFLAGS_MAINT_APPEND  := -Werror -Wno-error=unused-result \
	-Wno-error=sign-compare

# Disable optimisations if noopt found in $DEB_BUILD_OPTIONS
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	DEB_LDFLAGS_MAINT_APPEND += -Wl,-O0
else
	DEB_LDFLAGS_MAINT_APPEND += -Wl,-O1
endif

export DEB_LDFLAGS_MAINT_APPEND DEB_CFLAGS_MAINT_APPEND

# This renderer is only available on architectures that are sufficiently
# PC-like
ifneq (,$(filter $(DEB_HOST_ARCH),amd64 armel i386 ia64))
	VGA_RENDERER=lib/$(DEB_HOST_MULTIARCH)/plymouth/renderers/vga16fb.so
endif	

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
	dh ${@} --parallel --with autoreconf,systemd

override_dh_auto_clean:
	dh_auto_clean

	rm -f build-tools/config.guess build-tools/config.sub

override_dh_auto_configure:
	cp -f /usr/share/misc/config.guess build-tools
	cp -f /usr/share/misc/config.sub build-tools

	dh_auto_configure -- \
		--prefix=/usr \
		--libdir=/lib/$(DEB_HOST_MULTIARCH) \
		--datadir=/lib \
		--localstatedir=/var \
		--enable-pango \
		--enable-upstart-monitoring \
		--enable-systemd-integration \
		--enable-static \
		--enable-tracing \
		--disable-gdm-transition \
		--with-background-color=0x005a8a \
		--without-gdm-autostart-file \
		--with-log-viewer \
		--with-logo=/lib/plymouth/ubuntu_logo.png \
		--with-release-file=/etc/os-release \
		--with-system-root-install \
		--without-rhgb-compat-link \
		--with-background-color=0x2c001e \
		--with-background-start-color-stop=0x2c001e \
		--with-background-end-color-stop=0x2c001e \
		--with-boot-tty=/dev/tty7 \
		--with-shutdown-tty=/dev/tty7

override_dh_auto_install:
	dh_auto_install
	mkdir -p debian/tmp/usr/share/apport/package-hooks
	install -m 644 debian/libplymouth4.apport debian/tmp/usr/share/apport/package-hooks/source_plymouth.py

override_dh_install:
	sed -e'/frame-buffer\.so$$/a\
$(VGA_RENDERER)' < debian/plymouth.install.in > debian/plymouth.install
	dh_install
	sed -i -e's/#DEB_HOST_MULTIARCH#/$(DEB_HOST_MULTIARCH)/g' \
		debian/plymouth/usr/share/initramfs-tools/hooks/plymouth

override_dh_auto_clean:
	dh_auto_clean
	rm -f debian/plymouth.install

override_dh_systemd_start:
	dh_systemd_start --no-start

# Don't start plymouth when installing!
override_dh_installinit:
	dh_installinit --noscripts
	dh_installinit --name=plymouth-log --noscripts
	dh_installinit --name=plymouth-splash --noscripts
	dh_installinit --name=plymouth-stop --noscripts
	dh_installinit --name=plymouth-upstart-bridge --noscripts
	dh_installinit --name=plymouth-ready --noscripts
	dh_installinit --name=plymouth-shutdown --noscripts

# Make the initramfs scripts executable
override_dh_fixperms:
	dh_fixperms
	chmod 755 debian/plymouth/usr/share/initramfs-tools/hooks/plymouth
	chmod 755 debian/plymouth/usr/share/initramfs-tools/scripts/init-top/plymouth
	chmod 755 debian/plymouth/usr/share/initramfs-tools/scripts/init-bottom/plymouth
	chmod 755 debian/plymouth/usr/share/initramfs-tools/scripts/panic/plymouth

# Don't generate shlibs for plugins (ideally these wouldn't have a SONAME)
override_dh_makeshlibs:
	dh_makeshlibs -X/lib/$(DEB_HOST_MULTIARCH)/plymouth/
