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

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

export DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie

%:
	dh $@ --with autoreconf

override_dh_auto_configure:
	dh_auto_configure -- --bindir=/usr/lib/bfgminer \
                             --disable-silent-rules \
                             --enable-opencl \
                             --enable-scrypt \
                             --with-system-libblkmaker
#                             --enable-cpumining \

override_dh_auto_install:
	dh_auto_install
	## remove duplicates
	cd $(CURDIR)/debian/bfgminer/usr/share/doc/bfgminer && $(RM) -v COPYING* NEWS*

MAN_NAME=multi-threaded multi-pool ASIC, FPGA, GPU and CPU bitcoin miner.
bfgminer.1:
	help2man --no-info --name="$(MAN_NAME)" ./bfgminer > bfgminer.1
	perl \
             -E 's{\s+(It was generated by help2man)}{ $$1};   # correcting help2man comment'               \
             -E 's{^bfgminer\s+[\d.]+$$}{$(MAN_NAME)};         # correcting DESCRIPTION section'            \
             -E 's{\.PP\K}{\n.SH OPTIONS\n};                   # create OPTIONS section'                    \
             -E 's{^(Options\s+for)}{.SS\n$$1};                # separate Options paragraphs'               \
             -E 's{^(\\fB\\-\\-)}{.TP\n$$1};                   # prepend each option with .TP'              \
             -E 's{(?:<arg>\s+|\s\s+|\\fR\s+(?!<arg>))\K}{\n}; # separate arguments and their descriptions' \
          -pi $@

override_dh_installchangelogs:
	dh_installchangelogs NEWS

override_dh_builddeb:
	dh_builddeb -- -Zxz

DPATH := $(abspath $(dir $(MAKEFILE_LIST)))
VER ?= $(shell dpkg-parsechangelog -l$(DPATH)/changelog | perl -ne 'print $$1 if m{Version:\s*([\d\.]+)}')
.PHONY: get-orig-source
get-orig-source:
	@echo "# Downloading..."
	uscan --noconf --verbose --rename --destdir=$(CURDIR) --check-dirname-level=0 --force-download --download-version $(VER) $(DPATH)

