-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
142 lines (131 loc) · 4.46 KB
/
Makefile
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# vim: shiftwidth=2 tabstop=2 noexpandtab :
# -----------------------------------------------------------------------------
# Setup
# -----------------------------------------------------------------------------
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -o errexit -o nounset -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
# -----------------------------------------------------------------------------
# Globals
# -----------------------------------------------------------------------------
DIVIDER := $$(printf "%0.1s" -{1..80})
OS_REL := /etc/os-release
OS_FAMILY := $(shell sed -n '/^ID=/{s/"//g;s/.*=//;p}' $(OS_REL))
OS_RELEASE := $(shell sed -n '/^VERSION_ID=/{s/"//g;s/.*=//;p}' $(OS_REL))
OS_NAME := $(OS_FAMILY)_$(OS_RELEASE)
USER_BIN := $(HOME)/bin
REPO_NAME := $(shell basename $(CURDIR))
BASH_VERSIONS := 4.0 4.1 4.2 4.3 4.4 5.0 5.1 5.2-rc
# -----------------------------------------------------------------------------
# Contidionally assigned globals
# -----------------------------------------------------------------------------
ifeq ($(OS_NAME), ubuntu_18.04)
ASCIIDOCTOR_PREFIX := bundler exec
ASCIIDOCTOR_DEPENDENCIES := deb:ruby-bundler gem:asciidoctor-pdf:1.6.2
else
ASCIIDOCTOR_PREFIX :=
ASCIIDOCTOR_DEPENDENCIES := deb:asciidoctor deb:ruby-asciidoctor-pdf
endif
.PHONY: test
# -----------------------------------------------------------------------------
# Document creation
# -----------------------------------------------------------------------------
asciidoctor_dependencies:
@echo "Install asciidoctor dependencies $(ASCIIDOCTOR_DEPENDENCIES)"
for pkg in $(ASCIIDOCTOR_DEPENDENCIES); do
IFS=: read method name version <<< $${pkg}
case $${method} in
deb)
if dpkg -l $${name} &>/dev/null; then
echo "Package $${name} already installed"
else
sudo apt -y install $${name}
fi
;;
gem)
[[ -f Gemfile ]] || bundler init && :
bundler add "$${name}" --version "$${version}"
;;
esac
done
@echo $(DIVIDER)
docs/README.html: README.adoc
@echo "Build HTML doc $<"
$(ASCIIDOCTOR_PREFIX) asciidoctor -D docs $<
@echo $(DIVIDER)
docs/README.pdf: README.adoc
@echo "Build PDF doc $<"
$(ASCIIDOCTOR_PREFIX) asciidoctor-pdf --trace -D docs $<
@echo $(DIVIDER)
docs: asciidoctor_dependencies docs/README.html docs/README.pdf
# -----------------------------------------------------------------------------
# User install
# -----------------------------------------------------------------------------
user_install:
@echo "Install $(REPO_NAME) under $(USER_BIN)"
mkdir -p $(USER_BIN) || :
for script in bin/*; do
basename=$${script##*/}
install $${script} $(USER_BIN)/$${basename} &&
echo "-> Installing $${script} to $(USER_BIN)/$${basename}"
done
user_uninstall:
@echo "Uninstall $(REPO_NAME) from $(USER_BIN)"
for script in bin/*; do
basename=$${script##*/}
if [[ -f $(USER_BIN)/$${basename} ]]; then
rm $(USER_BIN)/$${basename} &&
echo "-> Unstalling $(USER_BIN)/$${basename}"
fi
done
# -----------------------------------------------------------------------------
# Janitor tasks
# -----------------------------------------------------------------------------
clean:
test -d docs && \
find docs \( -name "*.pdf" -or -name "*.html" \) -print -delete
test -f Gemfile && rm Gemfile
test -f Gemfile.lock && rm Gemfile.lock
# -----------------------------------------------------------------------------
# Run tests
# -----------------------------------------------------------------------------
test:
bats tests/*bats
test-bash:
@echo "Bash tests"
declare -a VERSIONS=( $(BASH_VERSIONS) );
function setup() {
apk add \
bats \
curl \
file \
grep \
imagemagick \
make \
openjdk11-jre-headless \
poppler-utils \
sane-utils \
tesseract-ocr \
tesseract-ocr-data-deu \
tesseract-ocr-data-eng \
tesseract-ocr-data-fra \
tesseract-ocr-data-ita; \
curl -sJLO 'https://gitlab.com/pdftk-java/pdftk/-/jobs/812582458/artifacts/raw/build/libs/pdftk-all.jar?inline=false' && \
mv pdftk-all.jar /usr/lib/ && \
echo -e "#!/usr/bin/env bash\njava -jar /usr/lib/pdftk-all.jar \"\$$@\"" > /usr/bin/pdftk && \
chmod 755 /usr/bin/pdftk
};
for version in $${VERSIONS[@]}; do
@echo "Test bash version $${version}"
docker pull bash:$${version}; \
docker run \
--rm \
--tty \
--volume $$(pwd):/pdftools \
--workdir /pdftools \
bash:$${version} \
bash -c "$$(declare -f setup); setup &>/dev/null && make test";
done