#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DH_OPTIONS

DB2MAN=/usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl
XP=xsltproc --nonet

CFLAGS = -Wall -g -std=gnu17

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

%: 
	dh $@

override_dh_auto_configure:
	perl makever.pl

override_dh_auto_build:
	dh_auto_build
ifneq ($(filter sketch-doc,$(shell dh_listpackages)),)
	cd Doc && perl make.pl linux examples
endif
	$(XP) -o sketch.1 $(DB2MAN)  debian/sketch-man.xml

override_dh_auto_clean:
	$(MAKE) clean

PATCH_EXPORT_SCRIPT=/usr/share/gitpkg/hooks/quilt-patches-deb-export-hook

.PHONY: export-patches

export-patches: 
	[ ! -r debian/patches ] || \
	grep "^\#.*$(notdir $(PATCH_EXPORT_SCRIPT))" debian/patches/series
	rm -rf debian/patches
	sh $(PATCH_EXPORT_SCRIPT)
