#!/usr/bin/make -f

PKG_VERSION  := $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ')
DESTDIR = $(CURDIR)/debian/cpuminer-opt/

%:
	dh $@ --with systemd

override_dh_auto_configure:
override_dh_auto_build:
override_dh_auto_install:
	mkdir -p "$(DESTDIR)/var/lib/cpuminer-opt/src/"
	mkdir -p "$(DESTDIR)/var/lib/cpuminer-opt/binaries/"
	echo "$(PKG_VERSION)" > $(DESTDIR)/var/lib/cpuminer-opt/PKG_VERSION
	# Because any user should be able to produce a new binary
	chmod 0777 "$(DESTDIR)/var/lib/cpuminer-opt/binaries/"
	# Most of excludes are just to reduce amount of lintian warnings
	rsync -av "$(CURDIR)/" "$(DESTDIR)/var/lib/cpuminer-opt/src/" \
	  --exclude='debian/' \
	  --exclude '.gitignore' \
          --exclude '.gitattributes' \
          --exclude 'm4/.gitignore' \
          --exclude 'COPYING' \
          --exclude 'LICENSE' \
          --exclude 'compat/jansson/LICENSE' \
	  --exclude 'cpuminer.sln' 
	mkdir -p "$(DESTDIR)/usr/bin/"
	install -m 0755 "$(CURDIR)/debian/wrapper/cpuminer-opt" "$(DESTDIR)/usr/bin/cpuminer-opt"
override_dh_fixperms:
	dh_fixperms -X/var/lib/cpuminer-opt/binaries

override_dh_systemd_enable:
	dh_systemd_enable --no-enable
override_dh_systemd_start:
	dh_systemd_start --no-start

override_dh_installman:
	dh_installman
	mv "$(DESTDIR)/usr/share/man/man1/cpuminer.1" "$(DESTDIR)/usr/share/man/man1/cpuminer-opt.1"
	sed -i -e 's!CPUMINER!CPUMINER-OPT!g' -e 's!cpuminer!cpuminer-opt!g' "$(DESTDIR)/usr/share/man/man1/cpuminer-opt.1"

override_dh_installchangelogs:
	dh_installchangelogs RELEASE_NOTES
