-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.mk
More file actions
118 lines (105 loc) · 4.26 KB
/
Makefile.mk
File metadata and controls
118 lines (105 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Licensed under the GNU GPL-3.0+: https://www.gnu.org/licenses/gpl-3.0.html
all: # default target
SHELL := /bin/bash -o pipefail
version_full != src/version.sh
VERSION := $(word 1, $(version_full))
version_bits := $(subst _, , $(subst -, , $(subst ., , $(VERSION))))
PKGVERSION := $(word 1, $(version_bits)).$(word 2, $(version_bits))
ALL_TARGETS :=
Q := $(if $(findstring 1, $(V)),, @)
QGEN = @echo ' GEN ' $@
QSKIP := $(if $(findstring s,$(MAKEFLAGS)),: )
QECHO = @QECHO() { Q1="$$1"; shift; QR="$$*"; QOUT=$$(printf ' %-8s ' "$$Q1" ; echo "$$QR") && $(QSKIP) echo "$$QOUT"; }; QECHO
QCHECK = $(QECHO) CHECK $@
QOK = $(QECHO) OK $@
PANDOC := pandoc
CLEANFILES = $(ALL_TARGETS) .version
# == Paths ==
# Installation locations
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
LIBEXEC ?= libexec/imagewmark-$(PKGVERSION)
PRJDIR ?= $(PREFIX)/$(LIBEXEC)
# == Versioning ==
# Force .version to be kept up to date
.version: ; $(QGEN) && src/version.sh > $@
ALL_TARGETS += .version
ifneq ($(version_full),$(shell test ! -r .version || cat .version))
.PHONY: .version
endif
# == Subdir Makefiles ==
include src/Makefile.mk
include cxx/Makefile.mk
include doc/Makefile.mk
# Rules
imagewmark: cxx/imagewmark
$(QGEN)
$Q ln -sf cxx/imagewmark $@
ALL_TARGETS += imagewmark
# == install ==
install:
$(QGEN)
mkdir -p $(BINDIR) $(PRJDIR) $(PRJDIR)/src $(PRJDIR)/cxx $(PRJDIR)/doc $(PREFIX)/share/man/man1
cp -Pp imagewmark .version $(PRJDIR)
cp -Pp src/*.py $(PRJDIR)/src
cp -Pp cxx/cornersync cxx/peaks2grid cxx/imagewmark cxx/wmops $(PRJDIR)/cxx
cp -Pp doc/imagewmark.1 doc/imagewmark-arch.html $(PRJDIR)/doc
ln -sf ../../../$(LIBEXEC)/doc/imagewmark.1 $(PREFIX)/share/man/man1/imagewmark-$(PKGVERSION).1
ln -sf imagewmark-$(PKGVERSION).1 $(PREFIX)/share/man/man1/imagewmark.1
ln -sf ../$(LIBEXEC)/imagewmark $(BINDIR)/imagewmark-$(PKGVERSION)
ln -sf imagewmark-$(PKGVERSION) $(BINDIR)/imagewmark
uninstall:
$(QGEN)
test "$$(readlink $(BINDIR)/imagewmark)" != "imagewmark-$(PKGVERSION)" \
|| rm -f $(BINDIR)/imagewmark $(PREFIX)/share/man/man1/imagewmark.1
test "$$(readlink -f $(BINDIR)/imagewmark-$(PKGVERSION))" != "$$(readlink -f $(PRJDIR)/imagewmark)" \
|| rm -f $(BINDIR)/imagewmark-$(PKGVERSION) $(PREFIX)/share/man/man1/imagewmark-$(PKGVERSION).1
rm -rf $(PRJDIR)
# == installcheck ==
# verify that the installed imagewmark can process WMs
INSTALLED_IMAGEWMARK := $(PRJDIR)/imagewmark
installcheck:
@$(eval TDIR != mktemp --tmpdir -d iwm.XXXXXX)
$(QGEN)
$Q convert tests/example01.svg $(TDIR)/iwmtest01.png
$Q cd $(TDIR) && $(INSTALLED_IMAGEWMARK) add iwmtest01.png iwmtest01wm.png 1234abcd00
$Q cd $(TDIR) && $(INSTALLED_IMAGEWMARK) get --cornersync=on iwmtest01wm.png >wm-cs.out && fgrep -q 1234abcd00 wm-cs.out
$Q cd $(TDIR) && $(INSTALLED_IMAGEWMARK) get --cornersync=off iwmtest01wm.png >wm-nc.out && fgrep -q 1234abcd00 wm-nc.out
$Q rm -r $(TDIR)
# == distcheck ==
distcheck:
@$(eval distversion != git describe --match='v[0-9]*.[0-9]*.[0-9]*' | sed 's/^v//')
@$(eval distname := imagewmark-$(distversion))
$(QECHO) MAKE $(distname).tar.zst
$Q test -n "$(distversion)" || (echo -e "#\n# $@: ERROR: no dist version, is git working?\n#" ; false )
$Q git describe --dirty | grep -qve -dirty || echo -e "#\n# $@: WARNING: working tree is dirty\n#"
$Q git archive -o $(distname).tar --prefix=$(distname)/ HEAD
$Q rm -f $(distname).tar.zst && zstd --ultra -22 --rm $(distname).tar && ls -lh $(distname).tar.zst
$Q T=`mktemp -d --tmpdir iwmtest-XXXXXX` && cd $$T && tar xvf $(abspath $(distname).tar.zst) \
&& cd imagewmark-$(distversion) \
&& nice make all -j`nproc` \
&& make PREFIX=$$T/inst install \
&& make PREFIX=$$T/inst installcheck -j`nproc` \
&& (set -x && $$T/inst/bin/imagewmark --version) \
&& make PREFIX=$$T/inst uninstall \
&& (set -x && $$PWD/imagewmark --version) \
&& cd / && rm -r "$$T"
$Q echo "Archive ready: $(distname).tar.zst" | sed '1h; 1s/./=/g; 1p; 1x; $$p; $$x'
# == clean ==
clean:
rm -f $(CLEANFILES)
test:
$(MAKE) -C tests/ $@
.PHONY: test
# == check-syntax ==
check-syntax:
$(QECHO) CHECK 'Detect invalid print() statements'
$Q { TCOLOR=--color=always ; tty -s <&1 || TCOLOR=; } \
&& ( grep $$TCOLOR -nE '\bprint *\(' -r src/*.py || : )
.PHONY: check-syntax
# == check ==
check: check-syntax
.PHONY: check
# == all ==
all: $(ALL_TARGETS)
# Must be last rule