#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 2004 by Joey Hess.
# This version is GPL.

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

%:
	dh $@

override_dh_auto_clean:
	# Clean up after the build process.
	dh_auto_clean

override_dh_auto_build:
	# Build the package.
	cp /usr/src/packages/SOURCES/dotoold.service .
	cp /usr/src/packages/SOURCES/vendor.tar.gz .
	tar -xzf vendor.tar.gz
	go build -mod=vendor -ldflags "-X main.Version=$(DEB_VERSION_UPSTREAM)"

override_dh_auto_install:
	# Install the package into debian/dotool.
	dh_auto_install
	mkdir -p debian/dotool/usr/bin
	mkdir -p debian/dotool/etc/udev/rules.d
	mkdir -p debian/dotool/lib/systemd/user
	mkdir -p debian/dotool/usr/share/man/man1
	install -Dm755 dotool dotoolc dotoold debian/dotool/usr/bin/
	install -Dm644 80-dotool.rules debian/dotool/etc/udev/rules.d/80-dotool.rules
	install -Dm644 dotoold.service debian/dotool/lib/systemd/user/dotoold.service

override_dh_installudev:
	# Install udev rules
	dh_installudev

override_dh_installinit:
	# Install init scripts
	dh_installinit

override_dh_installman:
	scdoc < doc/dotool.1.scd > debian/dotool/usr/share/man/man1/dotool.1
	dh_installman