#!/usr/bin/make -f
# Debian packaging without debhelper: the Go toolchain builds the binary and
# the rules stage it by hand. This keeps the build dependencies to just Go.

export CGO_ENABLED = 0

PACKAGE := lazyntfy
VERSION := $(shell dpkg-parsechangelog -SVersion)
PKGDIR  := debian/$(PACKAGE)

.PHONY: clean build build-arch build-indep binary binary-arch binary-indep

clean:
	rm -rf $(PKGDIR) $(PACKAGE)
	rm -f debian/files

build: build-arch build-indep

build-arch: $(PACKAGE)

build-indep:

$(PACKAGE):
	go build -trimpath -ldflags "-s -w -X main.version=$(VERSION)" -o $(PACKAGE) ./cmd/$(PACKAGE)

binary: binary-arch binary-indep

binary-arch: build-arch
	install -d $(PKGDIR)/DEBIAN
	install -Dm755 $(PACKAGE) $(PKGDIR)/usr/bin/$(PACKAGE)
	install -Dm644 man/lazyntfy.1 $(PKGDIR)/usr/share/man/man1/lazyntfy.1
	install -Dm644 LICENSE $(PKGDIR)/usr/share/doc/$(PACKAGE)/copyright
	install -Dm644 README.md $(PKGDIR)/usr/share/doc/$(PACKAGE)/README.md
	dpkg-gencontrol -p$(PACKAGE) -P$(PKGDIR)
	dpkg-deb --build --root-owner-group $(PKGDIR) ..

binary-indep:
