From 7e6249bc3c494f2f762f039c31f10f1098bfece8 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sat, 10 Apr 2021 03:02:08 +0000 Subject: [PATCH] Improve Debian packaging by creating a source package --- Makefile | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 6f73ebe..000291a 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,13 @@ Q = $(if $(filter 1, $V),, @) BINDIR=$(CURDIR)/bin PREFIX=/usr DESTDIR=bin +BUILDDIR=$(CURDIR)/build + +DEBBUILDDIR=$(BUILDDIR)/deb +DEBTMPLDIR=$(CURDIR)/packaging/debian +DEBDATE=$(shell date -R) +DEBORIGSRC=lume_$(DEBVERSION).orig.tar.xz +DEBORIGSRCDIR=lume-$(DEBVERSION) ifeq ($(OS), Windows_NT) EXE=$(BINDIR)/lume.exe @@ -16,11 +23,18 @@ endif LUME_VERSION ?= $(shell git describe --tags --always) GIT_COMMIT := $(shell git rev-parse --short HEAD) +GIT_TAG=$(shell git describe --tags --abbrev=0) LDFLAGS = \ -X git.kill0.net/chill9/lume/cmd.Version=$(LUME_VERSION) \ -X git.kill0.net/chill9/lume/cmd.BuildDate=$(BUILD_DATE) \ -X git.kill0.net/chill9/lume/cmd.GitCommit=$(GIT_COMMIT) +ifneq (,$(findstring -,$(LUME_VERSION))) + DEBVERSION=$(GIT_TAG)+git$(shell date +%Y%m%d)+$(GIT_COMMIT) +else + DEBVERSION=$(LUME_VERSION) +endif + .PHONY: build build: $(Q) go build -o $(EXE) -ldflags="$(LDFLAGS)" ./cmd/lume @@ -34,18 +48,18 @@ install: $(Q) install -p -D -m 0755 $(EXE) $(DESTDIR)${PREFIX}/bin/lume $(Q) install -p -D -m 0644 .lumerc.sample $(DESTDIR)${PREFIX}/share/lume/lumerc -DEBDIR=$(CURDIR)/debian -TMPLDIR=$(CURDIR)/packaging/debian -DEBDATE=$(shell date -R) - .PHONY: deb deb: - $(Q) mkdir -p $(DEBDIR) - $(Q) sed -e 's/__VERSION__/$(LUME_VERSION)/g' $(TMPLDIR)/rules > $(DEBDIR)/rules - $(Q) sed -e 's/__VERSION__/$(LUME_VERSION)/g' -e 's/__DATE__/$(DEBDATE)/g' $(TMPLDIR)/changelog > $(DEBDIR)/changelog - $(Q) echo 9 > $(DEBDIR)/compat - $(Q) cp $(TMPLDIR)/control $(DEBDIR)/control - $(Q) dpkg-buildpackage -us -uc -b + $(Q) mkdir -p $(DEBBUILDDIR) + $(Q) git archive --format tar --prefix lume-$(DEBVERSION)/ $(LUME_VERSION) | xz > $(DEBBUILDDIR)/$(DEBORIGSRC) + $(Q) tar xf $(DEBBUILDDIR)/$(DEBORIGSRC) -C $(DEBBUILDDIR) + $(Q) mkdir $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian + $(Q) sed -e 's/__VERSION__/$(DEBVERSION)/g' $(DEBTMPLDIR)/rules > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/rules + $(Q) sed -e 's/__VERSION__/$(DEBVERSION)/g' -e 's/__DATE__/$(DEBDATE)/g' $(DEBTMPLDIR)/changelog > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/changelog + $(Q) echo 9 > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/compat + $(Q) cp $(DEBTMPLDIR)/control $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/control + $(Q) dpkg-source -b $(DEBBUILDDIR)/$(DEBORIGSRCDIR) + $(Q) cd $(DEBBUILDDIR)/$(DEBORIGSRCDIR) && dpkg-buildpackage -us -uc deb-clean: - $(Q) rm -rf $(CURDIR)/debian + $(Q) rm -rf $(CURDIR)/build/deb