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_VERSION=$(shell sed -n 's/^Version: *//p' *.cabal)
|
|
|
|
PATAT_PACKAGE=patat-v$(PATAT_VERSION)-$(UNAME)-$(ARCH)
|
|
|
|
|
|
|
|
GHR_VERSION=0.13.0
|
|
|
|
GHR_NAME=ghr_v$(GHR_VERSION)_$(UNAME)_amd64
|
|
|
|
GHR_BINARY=$(HOME)/.local/bin/ghr
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
ifeq ($(UNAME), darwin)
|
2016-12-02 13:22:25 +03:00
|
|
|
# We use `?=` to set SOURCE_DATE_EPOCH only if it is not present. Unfortunately
|
|
|
|
# we can't use `git --date=unix` since only very recent git versions support
|
|
|
|
# that, so we need to make a round trip through `date`.
|
2020-01-18 19:29:01 +03:00
|
|
|
SOURCE_DATE_EPOCH?=$(shell git log -1 --format=%cd --date=unix)
|
|
|
|
else
|
2016-12-02 13:22:25 +03:00
|
|
|
SOURCE_DATE_EPOCH?=$(shell date '+%s' \
|
2020-01-18 19:29:01 +03:00
|
|
|
--date="$(shell git log -1 --format=%cd --date=rfc)")
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(UNAME), darwin)
|
|
|
|
COMPRESS_BIN_DEPS=
|
|
|
|
COMPRESS_BIN=ls
|
|
|
|
else
|
|
|
|
COMPRESS_BIN_DEPS=$(UPX_BINARY)
|
|
|
|
COMPRESS_BIN=upx
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Default target.
|
|
|
|
build: $(PATAT_BINARY)
|
2016-12-02 13:22:25 +03:00
|
|
|
|
2020-01-18 19:29:01 +03:00
|
|
|
# Upload a release.
|
|
|
|
release: $(PATAT_PACKAGE).$(ARCHIVE) $(GHR_BINARY)
|
|
|
|
ghr -u jaspervdj -r patat v$(PATAT_VERSION) $(PATAT_PACKAGE).$(ARCHIVE)
|
|
|
|
|
|
|
|
$(PATAT_PACKAGE).$(ARCHIVE): $(PATAT_BINARY) extra/patat.1 $(COMPRESS_BIN_DEPS)
|
|
|
|
mkdir $(PATAT_PACKAGE)
|
|
|
|
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):
|
|
|
|
stack build -j1 --copy-bins --pedantic
|
|
|
|
|
|
|
|
# GHR is used to upload releases to GitHub.
|
|
|
|
$(GHR_BINARY):
|
|
|
|
curl -Lo /tmp/$(GHR_NAME).$(ARCHIVE) \
|
|
|
|
https://github.com/tcnksm/ghr/releases/download/v$(GHR_VERSION)/$(GHR_NAME).$(ARCHIVE)
|
|
|
|
cd /tmp && $(ARCHIVE_EXTRACT) $(GHR_NAME).$(ARCHIVE)
|
|
|
|
mv /tmp/$(GHR_NAME)/ghr $(GHR_BINARY)
|
|
|
|
ghr --version
|
|
|
|
|
|
|
|
# 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)
|
2017-12-19 17:56:53 +03:00
|
|
|
SOURCE_DATE_EPOCH="$(SOURCE_DATE_EPOCH)" patat-make-man >$@
|
2016-11-18 14:38:04 +03:00
|
|
|
|
2020-01-18 19:29:01 +03:00
|
|
|
# Bash completion.
|
2017-03-01 18:45:20 +03:00
|
|
|
extra/patat.bash-completion:
|
|
|
|
patat --bash-completion-script patat >$@
|
|
|
|
|
2020-01-18 19:29:01 +03:00
|
|
|
.PHONY: completion
|
2017-03-01 18:45:20 +03:00
|
|
|
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
|
|
|
|
|
2016-12-01 16:21:08 +03:00
|
|
|
# Also check if we can generate the manual.
|
2020-01-18 19:29:01 +03:00
|
|
|
.PHONY: test
|
2016-12-01 16:21:08 +03:00
|
|
|
test: man
|
2019-10-07 15:14:30 +03:00
|
|
|
bash tests/golden.sh
|
2016-11-18 14:38:04 +03:00
|
|
|
|
2020-01-18 19:29:01 +03:00
|
|
|
.PHONY: clean
|
2016-12-01 16:55:10 +03:00
|
|
|
clean:
|
|
|
|
rm -f extra/patat.1
|
|
|
|
rm -f extra/make-man
|
2017-03-01 18:45:20 +03:00
|
|
|
rm -f extra/patat.bash-completion
|