#! /usr/bin/make -f

#export DH_VERBOSE = 1
#export DEB_BUILD_OPTIONS = nostrip

export LC_ALL = C.UTF-8

include /usr/share/dpkg/default.mk
include /usr/share/debhelper/dh_package_notes/package-notes.mk

# Make sure that DEB_BUILD_OPTIONS can be used by users to override any options
# we set here (By default DEB_BUILD_MAINT_OPTIONS overrides DEB_BUILD_OPTIONS).
export DEB_BUILD_MAINT_OPTIONS = optimize=+lto hardening=+pie $(DEB_BUILD_OPTIONS)

override_dh_auto_configure:
	dh_auto_configure -- \
		-Dversion-tag="$(VERSION_TAG)" \
		-Dmode=release \
		-Dkmod-path=/usr/bin/kmod \
		-Dmount-path=/usr/bin/mount \
		-Dumount-path=/usr/bin/umount \
		-Dsupport-url=https://www.debian.org/support \
		-Dsystem-uid-max=999 \
		-Dsystem-gid-max=999 \
		-Dnobody-user=nobody \
		-Dnobody-group=nogroup \
		-Ddev-kvm-mode=0660 \
		-Dgroup-render-mode=0660 \
		-Dselinux=enabled \
		-Dkmod=enabled \
		-Dacl=enabled \
		-Dblkid=enabled \
		-Dauto_features=disabled \
		-Drpmmacrosdir=no \
		-Dhwdb=false \
		-Dvconsole=false \
		-Dfirstboot=false \
		-Dwheel-group=false \
		-Dsysvinit-path='' \
		-Doomd=false \
		-Durlify=false \
		-Dlink-udev-shared=false \
		-Dsysext=false \
		-Dnscd=false \
		-Dsysusers=false \
		-Dinstall-tests=false \
		-Ddbus-interfaces-dir=no \
		-Dtranslations=false \
		-Dresolve=false \
		-Dutmp=false \
		-Dtests=false \
		-Dima=false \
		-Dipe=false \
		-Dsmack=false \
		-Dbacklight=false \
		-Dkernel-install=false \
		-Dmountfsd=false \
		-Dnetworkd=false \
		-Dnsresourced=false \
		-Dnss-myhostname=false \
		-Dnss-systemd=false \
		-Dhibernate=false \
		-Dldconfig=false \
		-Defi=false \
		-Dtpm=false \
		-Denvironment-d=false \
		-Dbinfmt=false \
		-Dpstore=false \
		-Dlogind=false \
		-Dhostnamed=false \
		-Dlocaled=false \
		-Dmachined=false \
		-Dportabled=false \
		-Dquotacheck=false \
		-Drandomseed=false \
		-Drfkill=false \
		-Danalyze=false \
		-Dstoragetm=false \
		-Dtimedated=false \
		-Dtimesyncd=false \
		-Dtmpfiles=false \
		-Dxdg-autostart=false \
		-Didn=false \
		-Dgshadow=false \
		-Durlify=false \
		-Dcoredump=false \
		-Dinstall-sysconfdir=false

override_dh_auto_build:
	dh_auto_build -- libudev udev

# TODO: in compat 14 we can use dh_auto_install -- --no-rebuild --tags libudev,udev
override_dh_auto_install:
	meson install -C obj-$(DEB_HOST_GNU_TYPE) --no-rebuild --tags libudev,udev --destdir ../debian/tmp/

PROJECT_VERSION ?= $(shell awk '/(PROJECT|PACKAGE)_VERSION / {print $$3}' obj-$(DEB_HOST_GNU_TYPE)/config.h | tr -d \")

override_dh_makeshlibs:
	sed 's/SHARED_LIB_VERSION/$(PROJECT_VERSION)/' debian/shlibs.local.in > debian/shlibs.local
	dh_makeshlibs -plibudev1-udeb --add-udeb=libudev1-udeb
	dh_makeshlibs --remaining-packages

override_dh_auto_test:

%:
	dh $@