#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
export DH_VERBOSE = 1

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# Introduce standard debhelper variables
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

PERL ?= /usr/bin/perl

LDFLAGS_LIB_SEARCHPATH = $(strip $(shell find $(CURDIR)/zbar -name '*.so' -printf "-L%h "))
LDFLAGS_BINDINGS = $(strip $(LDFLAGS) $(LDFLAGS_LIB_SEARCHPATH))


# Explicitly set supported Qt version
export QT_SELECT := 5


# Properly set configure flags
CONFIGURE_FLAGS = --without-java --libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)

# We enable libv4l support only on Linux platforms.
ifeq (,$(findstring linux,$(DEB_HOST_ARCH_OS)))
    CONFIGURE_FLAGS += --disable-video
endif



%:
	dh $@ --with python2

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_FLAGS)

override_dh_missing:
	dh_missing --list-missing

override_dh_strip:
	dh_strip --dbgsym-migration='zbar-dbg (<< 0.21~)'

override_dh_clean:
	dh_clean
	# Also clean up perl-related files
	[ ! -f $(CURDIR)/perl/Makefile ] || $(MAKE) -C perl realclean

override_dh_auto_install: build-perl
	dh_auto_install

build-perl:
	dh_auto_configure --sourcedirectory=perl -- INC="-I$(CURDIR)/include" LIBS="$(LDFLAGS_LIB_SEARCHPATH) -lzbar"
	dh_auto_build --sourcedirectory=perl -- OTHERLDFLAGS="$(LDFLAGS_LIB_SEARCHPATH)" LD_RUN_PATH=''
	dh_auto_install --sourcedirectory=perl

.PHONY: build-perl