lume/Makefile

100 lines
3.5 KiB
Makefile
Raw Normal View History

2021-03-03 02:41:58 +00:00
V ?= 0
Q = $(if $(filter 1, $V),, @)
2021-04-07 01:37:19 +00:00
BINDIR=$(CURDIR)/bin
2021-04-09 00:05:59 +00:00
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)
2021-03-31 04:57:52 +00:00
2021-04-10 03:49:29 +00:00
RPMVERSION=$(subst -,_,$(LUME_VERSION))
RPMBUILDDIR=$(BUILDDIR)/rpm
RPMTMPLDIR=$(CURDIR)/packaging/rpm
RPMDATE=$(shell date "+%a %b %d %Y")
RPMORIGSRC=lume-$(RPMVERSION).tar.xz
RPMORIGSRCDIR=lume-$(RPMVERSION)
2021-03-02 04:59:11 +00:00
ifeq ($(OS), Windows_NT)
2021-04-07 01:37:19 +00:00
EXE=$(BINDIR)/lume.exe
2021-03-02 06:40:22 +00:00
RM=del /f /q
2021-03-03 02:41:18 +00:00
BUILD_DATE=$(shell powershell Get-Date -Format "yyyy-MM-ddThh:mm:sszzz")
2021-03-02 04:59:11 +00:00
else
2021-04-07 01:37:19 +00:00
EXE=$(BINDIR)/lume
2021-03-30 18:27:58 +00:00
RM=rm -f
2021-03-03 02:41:18 +00:00
BUILD_DATE=$(shell date --iso-8601=seconds)
2021-03-02 04:59:11 +00:00
endif
2021-03-03 02:41:18 +00:00
LUME_VERSION ?= $(shell git describe --tags --always)
2021-03-11 03:39:47 +00:00
GIT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_TAG=$(shell git describe --tags --abbrev=0)
LDFLAGS = \
2021-03-03 06:29:40 +00:00
-X git.kill0.net/chill9/lume/cmd.Version=$(LUME_VERSION) \
2021-03-11 03:39:47 +00:00
-X git.kill0.net/chill9/lume/cmd.BuildDate=$(BUILD_DATE) \
-X git.kill0.net/chill9/lume/cmd.GitCommit=$(GIT_COMMIT)
2021-03-03 02:41:18 +00:00
ifneq (,$(findstring -,$(LUME_VERSION)))
DEBVERSION=$(GIT_TAG)+git$(shell date +%Y%m%d)+$(GIT_COMMIT)
else
DEBVERSION=$(LUME_VERSION)
endif
2020-02-29 18:55:28 +00:00
.PHONY: build
build:
2021-03-03 06:29:40 +00:00
$(Q) go build -o $(EXE) -ldflags="$(LDFLAGS)" ./cmd/lume
2020-02-29 18:55:28 +00:00
.PHONY: clean
2021-04-10 03:49:29 +00:00
clean: deb-clean rpm-clean
2021-03-30 18:27:58 +00:00
$(Q) $(RM) $(EXE)
2021-04-07 01:38:00 +00:00
.PHONY: install
install:
2021-04-09 00:05:59 +00:00
$(Q) install -p -D -m 0755 $(EXE) $(DESTDIR)${PREFIX}/bin/lume
$(Q) install -p -D -m 0644 .lumerc.sample $(DESTDIR)${PREFIX}/share/lume/lumerc
2021-04-08 05:36:07 +00:00
.PHONY: deb
deb:
$(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
2021-04-10 07:23:25 +00:00
$(Q) mkdir $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/source
$(Q) sed -e 's/__VERSION__/$(DEBVERSION)/g' $(DEBTMPLDIR)/rules > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/rules
2021-04-10 07:23:25 +00:00
$(Q) chmod 0755 $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/rules
$(Q) sed -e 's/__VERSION__/$(DEBVERSION)/g' -e 's/__DATE__/$(DEBDATE)/g' $(DEBTMPLDIR)/changelog > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/changelog
2021-04-10 07:23:25 +00:00
$(Q) echo 10 > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/compat
$(Q) echo "3.0 (quilt)" > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/source/format
$(Q) cp $(DEBTMPLDIR)/control $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/control
2021-04-10 07:23:57 +00:00
$(Q) cp $(DEBTMPLDIR)/copyright $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/copyright
$(Q) cd $(DEBBUILDDIR)/$(DEBORIGSRCDIR) && dpkg-buildpackage -us -uc
$(Q) mv $(DEBBUILDDIR)/*.dsc $(BUILDDIR)
$(Q) mv $(DEBBUILDDIR)/*.changes $(BUILDDIR)
$(Q) mv $(DEBBUILDDIR)/*.buildinfo $(BUILDDIR)
$(Q) mv $(DEBBUILDDIR)/*.deb $(BUILDDIR)
$(Q) mv $(DEBBUILDDIR)/*.tar.* $(BUILDDIR)
2021-04-10 03:49:29 +00:00
.PHONY: rpm
rpm:
$(Q) mkdir -p $(RPMBUILDDIR)/SPECS
$(Q) mkdir -p $(RPMBUILDDIR)/SOURCES
$(Q) sed -e 's/__VERSION__/$(RPMVERSION)/g' -e 's/__DATE__/$(RPMDATE)/g' $(RPMTMPLDIR)/lume.spec > $(RPMBUILDDIR)/SPECS/lume.spec
$(Q) git archive --format tar --prefix $(RPMORIGSRCDIR)/ $(LUME_VERSION) | xz > $(RPMBUILDDIR)/SOURCES/$(RPMORIGSRC)
$(Q) rpmbuild --define "_topdir $(RPMBUILDDIR)" -ba $(RPMBUILDDIR)/SPECS/lume.spec
$(Q) mv $(RPMBUILDDIR)/RPMS/*/*.rpm $(BUILDDIR)
$(Q) mv $(RPMBUILDDIR)/SRPMS/*.rpm $(BUILDDIR)
deb-clean:
2021-04-10 03:48:09 +00:00
$(Q) rm -rf $(DEBBUILDDIR)
$(Q) rm -f $(BUILDDIR)/*.dsc
$(Q) rm -f $(BUILDDIR)/*.changes
$(Q) rm -f $(BUILDDIR)/*.buildinfo
$(Q) rm -f $(BUILDDIR)/*.deb
$(Q) rm -f $(BUILDDIR)/*.tar.*
2021-04-10 03:49:29 +00:00
rpm-clean:
$(Q) rm -rf $(RPMBUILDDIR)
$(Q) rm -f $(BUILDDIR)/*.rpm