#!/usr/bin/make -f

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

DESTDIR=$(CURDIR)/debian/spectrwm

build: build-indep build-arch
build-indep: build-stamp
build-arch: build-stamp
build-stamp:
	dh_testdir
	$(MAKE) -C linux/ PREFIX=/usr \
	                  LIBDIR=/usr/lib/spectrwm
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	$(MAKE) -C linux/ clean
	dh_clean

binary: binary-indep binary-arch
binary-indep: build
binary-arch: build
	dh_testdir
	dh_testroot
	dh_prep
	$(MAKE) -C linux/ install PREFIX=/usr \
	                          LIBDIR=/usr/lib/spectrwm \
	                          DESTDIR=$(DESTDIR)
	dh_install
	dh_installexamples
	dh_installchangelogs 
	dh_installdocs
	dh_installwm /usr/bin/spectrwm
	dh_strip
	dh_compress
	dh_link
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# 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: build clean binary binary-indep binary-arch rebuild-patches-series
