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
|
2020-06-29 18:11:36 +03:00
|
|
|
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.
|
2020-06-29 18:11:36 +03:00
|
|
|
.PHONY: build
|
2020-01-18 19:29:01 +03:00
|
|
|
build: $(PATAT_BINARY)
|
2016-12-02 13:22:25 +03:00
|
|
|
|
2020-06-29 18:11:36 +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)
|
2020-06-29 18:11:36 +03:00
|
|
|
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):
|
2024-10-22 22:03:48 +03:00
|
|
|
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)
|
2024-10-22 22:03:48 +03:00
|
|
|
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.
|
2024-10-22 22:03:48 +03:00
|
|
|
extra/patat.bash-completion: $(PATAT_BINARY)
|
|
|
|
cabal exec -- patat --bash-completion-script patat >$@
|
2017-03-01 18:45:20 +03:00
|
|
|
|
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
|
2024-10-22 22:03:48 +03:00
|
|
|
cabal test
|
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
|