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:
+12
@@ -19,3 +19,15 @@ coverage.*
|
|||||||
*.swp
|
*.swp
|
||||||
*~
|
*~
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
# Debian packaging build output
|
||||||
|
/debian/files
|
||||||
|
/debian/lazyntfy/
|
||||||
|
/debian/*.substvars
|
||||||
|
/debian/.debhelper/
|
||||||
|
|
||||||
|
# Arch Linux packaging build output
|
||||||
|
/packaging/archlinux/src/
|
||||||
|
/packaging/archlinux/pkg/
|
||||||
|
/packaging/archlinux/*.pkg.tar.*
|
||||||
|
/packaging/archlinux/*.tar.gz
|
||||||
|
|||||||
@@ -2,33 +2,42 @@ BINARY := lazyntfy
|
|||||||
PREFIX ?= $(HOME)/.local
|
PREFIX ?= $(HOME)/.local
|
||||||
BINDIR ?= $(PREFIX)/bin
|
BINDIR ?= $(PREFIX)/bin
|
||||||
MANDIR ?= $(PREFIX)/share/man/man1
|
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)
|
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null | sed 's/^v//' | grep . || echo 0.1.0)
|
||||||
TOPIC ?= alerts
|
TOPIC ?= alerts
|
||||||
|
GO ?= go
|
||||||
|
GOFLAGS ?= -trimpath
|
||||||
|
|
||||||
LDFLAGS := -X main.version=$(VERSION)
|
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:
|
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
|
install: build
|
||||||
mkdir -p "$(BINDIR)" "$(MANDIR)"
|
install -Dm755 $(BINARY) "$(DESTDIR)$(BINDIR)/$(BINARY)"
|
||||||
install -m 755 $(BINARY) "$(BINDIR)/$(BINARY)"
|
install -Dm644 man/lazyntfy.1 "$(DESTDIR)$(MANDIR)/lazyntfy.1"
|
||||||
install -m 644 man/lazyntfy.1 "$(MANDIR)/lazyntfy.1"
|
install -Dm644 LICENSE "$(DESTDIR)$(DOCDIR)/copyright"
|
||||||
|
install -Dm644 README.md "$(DESTDIR)$(DOCDIR)/README.md"
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f "$(BINDIR)/$(BINARY)" "$(MANDIR)/lazyntfy.1"
|
rm -f "$(DESTDIR)$(BINDIR)/$(BINARY)" "$(DESTDIR)$(MANDIR)/lazyntfy.1"
|
||||||
|
rm -rf "$(DESTDIR)$(DOCDIR)"
|
||||||
|
|
||||||
man:
|
man:
|
||||||
mkdir -p "$(MANDIR)"
|
install -Dm644 man/lazyntfy.1 "$(DESTDIR)$(MANDIR)/lazyntfy.1"
|
||||||
install -m 644 man/lazyntfy.1 "$(MANDIR)/lazyntfy.1"
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test ./...
|
$(GO) test ./...
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
go vet ./...
|
$(GO) vet ./...
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
gofmt -w .
|
gofmt -w .
|
||||||
@@ -36,5 +45,19 @@ fmt:
|
|||||||
run: build
|
run: build
|
||||||
./$(BINARY) $(TOPIC)
|
./$(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:
|
clean:
|
||||||
rm -f $(BINARY)
|
rm -f $(BINARY)
|
||||||
|
rm -rf dist
|
||||||
|
-$(MAKE) -f debian/rules clean
|
||||||
|
|||||||
Reference in New Issue
Block a user