#!/usr/bin/make -f

DEB_BUILD_MAINT_OPTIONS=hardening=+bindnow
DPKG_EXPORT_BUILDFLAGS=1
include /usr/share/dpkg/buildflags.mk

%:
	dh $@

# Build, install and clean.
#
# The Makefile we need to use is in the linux/ directory, so we need
# to override the usual dh_auto_* commands to prevent them from using
# the top-level Makefile, which only works on OpenBSD. We also pass a
# few extra variables to customize the installation paths.
override_dh_auto_build:
	$(MAKE) -C linux/ PREFIX=/usr \
	                  LIBDIR=/usr/lib/spectrwm

override_dh_auto_install:
	$(MAKE) -C linux/ install PREFIX=/usr \
	                          LIBDIR=/usr/lib/spectrwm \
	                          DESTDIR=$(CURDIR)/debian/spectrwm

override_dh_auto_clean:
	$(MAKE) -C linux/ clean

# Don't try to run tests.
#
# spectrwm doesn't have a test suite, but the OpenBSD Makefile in the
# top-level directory confuses dh_auto_test's detection and tricks it
# into thinking one exists.
override_dh_auto_test:

# Don't create shlibs files.
#
# libswmhack.so is not a proper shared library, and it should not be
# treated as such.
override_dh_makeshlibs:

# Rebuild the patches series by looking at the contents of the
# debian/patches directory.
#
# Patches with names starting with D (Debian-specific) should be applied
# after those with names starting with U (to be forwarded upstream).
rebuild-patches-series:
	@( \
		SERIES=debian/patches/series; \
		{ \
			echo "# To rebuild this file, use \`debian/rules $@'"; \
			for patch in debian/patches/U*.diff debian/patches/D*.diff; \
			do \
				test -f "$${patch}" || continue; \
				patch=$$(basename "$${patch}"); \
				echo "$${patch}"; \
			done; \
		} >"$${SERIES}"; \
	)

.PHONY: rebuild-patches-series
