#!/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:
	#./autogen.sh
	#wget -O ADL_SDK/adl.zip http://download2-developer.amd.com/amd/GPU/zip/ADL_SDK_4.0.zip;
	#unzip ADL_SDK/adl.zip include/* -d ADL_SDK/;
	#mv ADL_SDK/include/* ADL_SDK/;
	#rm -rf ADL_SDK/adl.zip ADL_SDK/include/;
	## Can't enable "--enable-ztex" as ztex licensed under GPL-2 while most files are GPL-3+
	dh_auto_configure -- --bindir=/usr/lib/cgminer \
                             --enable-avalon \
                             --enable-bitforce \
                             --enable-icarus \
                             --enable-scrypt \
                             --enable-modminer \
                             --enable-bflsc \
                             --disable-silent-rules

override_dh_auto_install:
	dh_auto_install
	chmod a-x $(CURDIR)/debian/cgminer/*/*/*/*.cl

#generates manpage, we used to do it at build time but now that CPU mining is
#disabled we can generate this prior to upload
MAN_NAME=multi-threaded multi-pool GPU, FPGA and CPU bitcoin miner.
cgminer.1:
	help2man --no-discard-stderr --no-info --name="$(MAN_NAME)" cgminer > cgminer.1
	perl \
             -E 's{\s+(It was generated by help2man)}{ $$1};   # correcting help2man comment'               \
             -E 's{^cgminer\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)
