patat/Makefile

88 lines
2.1 KiB
Makefile
Raw Permalink Normal View History

2020-01-18 19:29:01 +03:00
ARCH=$(shell uname -m)
UNAME=$(shell uname | tr 'A-Z' 'a-z')
PATAT_BINARY=$(HOME)/.local/bin/patat
PATAT_TAG?=v$(shell sed -n 's/^Version: *//p' *.cabal)
PATAT_PACKAGE=patat-$(PATAT_TAG)-$(UNAME)-$(ARCH)
2020-01-18 19:29:01 +03:00
UPX_VERSION=3.94
UPX_NAME=upx-$(UPX_VERSION)-amd64_$(UNAME)
UPX_BINARY=$(HOME)/.local/bin/upx
ifeq ($(UNAME), darwin)
ARCHIVE=zip
ARCHIVE_CREATE=zip -r
ARCHIVE_EXTRACT=unzip
else
ARCHIVE=tar.gz
ARCHIVE_CREATE=tar czf
ARCHIVE_EXTRACT=tar xvzf
endif
SOURCE_DATE_EPOCH?=$(shell git log -1 --format=%cd --date=unix)
ifeq ($(UNAME), darwin)
COMPRESS_BIN_DEPS=
COMPRESS_BIN=ls
else
COMPRESS_BIN_DEPS=$(UPX_BINARY)
COMPRESS_BIN=upx
endif
# Default target.
.PHONY: build
2020-01-18 19:29:01 +03:00
build: $(PATAT_BINARY)
2016-12-02 13:22:25 +03:00
# When we want to do a release.
.PHONY: artifact
artifact: $(PATAT_PACKAGE).$(ARCHIVE)
mkdir -p artifacts
cp $(PATAT_PACKAGE).$(ARCHIVE) artifacts/
2020-01-18 19:29:01 +03:00
$(PATAT_PACKAGE).$(ARCHIVE): $(PATAT_BINARY) extra/patat.1 $(COMPRESS_BIN_DEPS)
mkdir -p $(PATAT_PACKAGE)
2020-01-18 19:29:01 +03:00
cp $(PATAT_BINARY) $(PATAT_PACKAGE)/
$(COMPRESS_BIN) $(PATAT_PACKAGE)/patat
cp README.md $(PATAT_PACKAGE)/
cp CHANGELOG.md $(PATAT_PACKAGE)/
cp LICENSE $(PATAT_PACKAGE)/
cp extra/patat.1 $(PATAT_PACKAGE)/
$(ARCHIVE_CREATE) $(PATAT_PACKAGE).$(ARCHIVE) $(PATAT_PACKAGE)
$(PATAT_BINARY):
cabal install --installdir="$(dir $(PATAT_BINARY))"
2020-01-18 19:29:01 +03:00
# UPX is used to compress the resulting binary. We currently don't use this on
# Mac OS.
$(UPX_BINARY):
curl -Lo /tmp/$(UPX_NAME).tar.xz \
https://github.com/upx/upx/releases/download/v$(UPX_VERSION)/$(UPX_NAME).tar.xz
cd /tmp && tar xf $(UPX_NAME).tar.xz
mv /tmp/$(UPX_NAME)/upx $(UPX_BINARY)
upx --version
# Man page.
extra/patat.1: README.md $(PATAT_BINARY)
SOURCE_DATE_EPOCH="$(SOURCE_DATE_EPOCH)" cabal exec -- patat-make-man >$@
2016-11-18 14:38:04 +03:00
2020-01-18 19:29:01 +03:00
# Bash completion.
extra/patat.bash-completion: $(PATAT_BINARY)
cabal exec -- patat --bash-completion-script patat >$@
2020-01-18 19:29:01 +03:00
.PHONY: completion
completion: extra/patat.bash-completion
2020-01-18 19:29:01 +03:00
.PHONY: man
2016-11-18 14:38:04 +03:00
man: extra/patat.1
# Also check if we can generate the manual.
2020-01-18 19:29:01 +03:00
.PHONY: test
test: man
cabal test
2016-11-18 14:38:04 +03:00
2020-01-18 19:29:01 +03:00
.PHONY: clean
clean:
rm -f extra/patat.1
rm -f extra/make-man
rm -f extra/patat.bash-completion