#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# generate documentation unless nodoc requested
DOCS_stem = README
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
DOCS = $(addsuffix .html,$(DOCS_stem)) $(addsuffix .txt,$(DOCS_stem))
MANPAGES = jbig2.1
endif

%:
	dh $@

%.html: %.md
	cmark-gfm $< > $@

%.txt: %.md
	cmark-gfm --to plaintext $< > $@

override_dh_autoreconf:
	dh_autoreconf --as-needed

override_dh_auto_configure:
	dh_auto_configure -- --disable-static --disable-rpath

execute_after_dh_auto_build: $(DOCS) $(MANPAGES)

execute_after_dh_auto_install:
	find debian/ -name "*.la" -delete
	d-shlibmove --commit \
		--t64 \
		--devunversioned \
		--exclude-la \
		--exclude-a \
		--multiarch \
		--movedev "debian/tmp/usr/include/*" usr/include/ \
		debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/*.so

override_dh_install:
	dh_install -Xpdf.py

override_dh_installdocs:
	dh_installdocs --all -- $(DOCS)

override_dh_installchangelogs:
	dh_installchangelogs -- ChangeLog

# build manpages
jbig2.1: LD_LIBRARY_PATH = src/.libs
jbig2.1: %.1: src/%
	help2man --section 1 --no-info --no-discard-stderr \
		--name "encoder for JBIG2" \
		--output $@ $< \
		|| { $1 --help; false; }
