#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# Suppress some warnings as a temporary measure.  See the description
# of debian/patches/22-gnome-common-deprecated.patch for details.
export DEB_CFLAGS_MAINT_APPEND = -Wno-redundant-decls -Wno-clobbered \
				 -Wno-strict-prototypes -Wno-shadow \
				 -Wno-suggest-attribute=noreturn \
				 -Wno-suggest-attribute=format -Wno-undef \
				 -Wno-implicit-fallthrough -Wno-switch-enum \
				 -Wno-switch-default
BDIR := BUILD

ifeq ($(DEB_BUILD_ARCH_OS),linux)
	CONFIGFLAG += --enable-v4l
else ifeq ($(DEB_BUILD_ARCH_OS),hurd)
	CONFIGFLAG += --disable-v4l --disable-bktr
else
	CONFIGFLAG += --enable-bktr
endif

%:
	dh $@ --builddirectory=$(BDIR)

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGFLAG)                      \
	  ac_cv_path_CONSOLEHELPER_LOCATION=/usr/bin/consolehelper \
			   --enable-pam                         \
			   --enable-compile-warnings=yes

	mv $(BDIR)/libtool $(BDIR)/libtool.old
	sed -e '/^archive_cmds/{ s/="\\$$CC -shared /&$${wl}--as-needed /;s/ [^ ]*soname[^ ]*/ /g; }' < \
		 $(BDIR)/libtool.old >  $(BDIR)/libtool
	chmod 755  $(BDIR)/libtool

	@echo "Config variables:"
	sed -ne "s/^#define \(.*\) 1 *$$/ \1/p" $(BDIR)/config.h

# The testsuite has to be fixed in order to remove the override.
override_dh_auto_test: ;

override_dh_auto_install:
	dh_auto_install -- MKINSTALLDIRS="install -d"
	$(RM) debian/zapping/usr/lib/zapping/plugins/*.la
# Upstream's build system assumes that consolehelper is used but that
# is no longer necessary.  Note that zapping_setup_fb is built only on
# GNU/Linux architectures.
ifeq ($(DEB_BUILD_ARCH_OS),linux)
	mv debian/zapping/usr/sbin/zapping_setup_fb debian/zapping/usr/bin
	rmdir debian/zapping/usr/sbin
endif

override_dh_strip:
	dh_strip --dbgsym-migration='zapping-dbg (<< 0.10~cvs6-12~)'
