build(make): add deb and arch targets and a staged install
install now honors DESTDIR and also installs the license and README under DOCDIR, so packagers can stage a filesystem tree. Add deb (runs dpkg-buildpackage, collects the artifacts in dist/) and arch (runs makepkg) targets, plus uninstall. Ignore the Debian and Arch build output.
This commit is contained in:
@@ -2,33 +2,42 @@ BINARY := lazyntfy
|
||||
PREFIX ?= $(HOME)/.local
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
MANDIR ?= $(PREFIX)/share/man/man1
|
||||
DOCDIR ?= $(PREFIX)/share/doc/$(BINARY)
|
||||
DESTDIR ?=
|
||||
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null | sed 's/^v//' | grep . || echo 0.1.0)
|
||||
TOPIC ?= alerts
|
||||
GO ?= go
|
||||
GOFLAGS ?= -trimpath
|
||||
|
||||
LDFLAGS := -X main.version=$(VERSION)
|
||||
|
||||
.PHONY: build install uninstall test vet fmt run man clean
|
||||
.PHONY: all build install uninstall man test vet fmt run deb arch clean
|
||||
|
||||
all: build
|
||||
|
||||
build:
|
||||
go build -ldflags "$(LDFLAGS)" -o $(BINARY) ./cmd/lazyntfy
|
||||
$(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BINARY) ./cmd/lazyntfy
|
||||
|
||||
# System-wide install: sudo make install PREFIX=/usr/local
|
||||
# Staged install: make install DESTDIR=/tmp/pkg PREFIX=/usr
|
||||
install: build
|
||||
mkdir -p "$(BINDIR)" "$(MANDIR)"
|
||||
install -m 755 $(BINARY) "$(BINDIR)/$(BINARY)"
|
||||
install -m 644 man/lazyntfy.1 "$(MANDIR)/lazyntfy.1"
|
||||
install -Dm755 $(BINARY) "$(DESTDIR)$(BINDIR)/$(BINARY)"
|
||||
install -Dm644 man/lazyntfy.1 "$(DESTDIR)$(MANDIR)/lazyntfy.1"
|
||||
install -Dm644 LICENSE "$(DESTDIR)$(DOCDIR)/copyright"
|
||||
install -Dm644 README.md "$(DESTDIR)$(DOCDIR)/README.md"
|
||||
|
||||
uninstall:
|
||||
rm -f "$(BINDIR)/$(BINARY)" "$(MANDIR)/lazyntfy.1"
|
||||
rm -f "$(DESTDIR)$(BINDIR)/$(BINARY)" "$(DESTDIR)$(MANDIR)/lazyntfy.1"
|
||||
rm -rf "$(DESTDIR)$(DOCDIR)"
|
||||
|
||||
man:
|
||||
mkdir -p "$(MANDIR)"
|
||||
install -m 644 man/lazyntfy.1 "$(MANDIR)/lazyntfy.1"
|
||||
install -Dm644 man/lazyntfy.1 "$(DESTDIR)$(MANDIR)/lazyntfy.1"
|
||||
|
||||
test:
|
||||
go test ./...
|
||||
$(GO) test ./...
|
||||
|
||||
vet:
|
||||
go vet ./...
|
||||
$(GO) vet ./...
|
||||
|
||||
fmt:
|
||||
gofmt -w .
|
||||
@@ -36,5 +45,19 @@ fmt:
|
||||
run: build
|
||||
./$(BINARY) $(TOPIC)
|
||||
|
||||
# Build a Debian/Ubuntu package. -d skips build-dependency checks so the
|
||||
# package can also be built on a machine without golang-go installed as a
|
||||
# distro package.
|
||||
deb:
|
||||
dpkg-buildpackage -us -uc -b -d
|
||||
mkdir -p dist
|
||||
mv -f ../$(BINARY)_*_*.deb ../$(BINARY)_*_*.changes ../$(BINARY)_*_*.buildinfo dist/ 2>/dev/null || true
|
||||
@echo " packages written to dist/"
|
||||
|
||||
arch:
|
||||
cd packaging/archlinux && makepkg -f
|
||||
|
||||
clean:
|
||||
rm -f $(BINARY)
|
||||
rm -rf dist
|
||||
-$(MAKE) -f debian/rules clean
|
||||
|
||||
Reference in New Issue
Block a user