Improve Debian packaging by creating a source package

This commit is contained in:
Ryan Cavicchioni 2021-04-10 03:02:08 +00:00
parent adbda33078
commit 7e6249bc3c
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D

View File

@ -3,6 +3,13 @@ Q = $(if $(filter 1, $V),, @)
BINDIR=$(CURDIR)/bin BINDIR=$(CURDIR)/bin
PREFIX=/usr PREFIX=/usr
DESTDIR=bin 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) ifeq ($(OS), Windows_NT)
EXE=$(BINDIR)/lume.exe EXE=$(BINDIR)/lume.exe
@ -16,11 +23,18 @@ endif
LUME_VERSION ?= $(shell git describe --tags --always) LUME_VERSION ?= $(shell git describe --tags --always)
GIT_COMMIT := $(shell git rev-parse --short HEAD) GIT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_TAG=$(shell git describe --tags --abbrev=0)
LDFLAGS = \ LDFLAGS = \
-X git.kill0.net/chill9/lume/cmd.Version=$(LUME_VERSION) \ -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.BuildDate=$(BUILD_DATE) \
-X git.kill0.net/chill9/lume/cmd.GitCommit=$(GIT_COMMIT) -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 .PHONY: build
build: build:
$(Q) go build -o $(EXE) -ldflags="$(LDFLAGS)" ./cmd/lume $(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 0755 $(EXE) $(DESTDIR)${PREFIX}/bin/lume
$(Q) install -p -D -m 0644 .lumerc.sample $(DESTDIR)${PREFIX}/share/lume/lumerc $(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 .PHONY: deb
deb: deb:
$(Q) mkdir -p $(DEBDIR) $(Q) mkdir -p $(DEBBUILDDIR)
$(Q) sed -e 's/__VERSION__/$(LUME_VERSION)/g' $(TMPLDIR)/rules > $(DEBDIR)/rules $(Q) git archive --format tar --prefix lume-$(DEBVERSION)/ $(LUME_VERSION) | xz > $(DEBBUILDDIR)/$(DEBORIGSRC)
$(Q) sed -e 's/__VERSION__/$(LUME_VERSION)/g' -e 's/__DATE__/$(DEBDATE)/g' $(TMPLDIR)/changelog > $(DEBDIR)/changelog $(Q) tar xf $(DEBBUILDDIR)/$(DEBORIGSRC) -C $(DEBBUILDDIR)
$(Q) echo 9 > $(DEBDIR)/compat $(Q) mkdir $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian
$(Q) cp $(TMPLDIR)/control $(DEBDIR)/control $(Q) sed -e 's/__VERSION__/$(DEBVERSION)/g' $(DEBTMPLDIR)/rules > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/rules
$(Q) dpkg-buildpackage -us -uc -b $(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: deb-clean:
$(Q) rm -rf $(CURDIR)/debian $(Q) rm -rf $(CURDIR)/build/deb