/
Makefile
181 lines (165 loc) · 7.75 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# the default goal is build
.DEFAULT_GOAL := build
# Set the shell to bash
SHELL := /bin/bash
# Get the current working directory
CWD := $(shell pwd)
# Get the latexgit version.
VERSION := $(shell (less '$(CWD)/latexgit.dtx' | sed -n 's/.*\\ProvidesPackage{latexgit}\[[0-9\/]* *\([.0-9]*\) .*\].*/\1/p'))
# Get the current date and time
NOW = $(shell date +'%0Y-%0m-%0d %0R:%0S')
# Print the status information.
status:
echo "$(NOW): working directory: '$(CWD)'." &&\
echo "$(NOW): latexgit version to build: '$(VERSION)'." &&\
echo "$(NOW): shell: '$(SHELL)'"
pre_clean: status
echo "$(NOW): Deleting all temporary, intermediate, and generated files before the build." && \
rm -rf website &&\
rm latexgit.aux || true &&\
rm latexgit.glo || true &&\
rm latexgit.gls || true &&\
rm latexgit.idx || true &&\
rm latexgit.ilg || true &&\
rm latexgit.ind || true &&\
rm latexgit.latexgit.dummy || true &&\
rm latexgit.log || true &&\
rm latexgit.out || true &&\
rm latexgit.pdf || true &&\
rm latexgit.sty || true &&\
rm latexgit.toc || true &&\
rm -rf examples/*.log &&\
rm -rf examples/*.aux &&\
rm -rf examples/*.pdf &&\
echo "$(NOW): Done deleting all temporary, intermediate, and generated files before the build."
# Initialization: Install all Python requirements, both for executing and building the library.
python_dependencies: pre_clean
echo "$(NOW): Initialization: first install required packages from requirements.txt." && \
pip install --no-input --timeout 360 --retries 100 -r requirements.txt && ## nosem \
echo "$(NOW): Finished installing required packages from requirements.txt, now installing packages required for development from requirements-dev.txt." && \
pip install --no-input --timeout 360 --retries 100 -r requirements-dev.txt && ## nosem \
echo "$(NOW): Finished installing requirements from requirements-dev.txt, now printing all installed packages." &&\
pip freeze &&\
echo "$(NOW): Finished printing all installed packages."
post_clean: extract build_documentation build_examples build_tds build_website pre_clean python_dependencies status
echo "$(NOW): Deleting all temporary and intermediate files after the build." && \
rm latexgit.aux &&\
rm latexgit.glo &&\
rm latexgit.gls &&\
rm latexgit.idx &&\
rm latexgit.ilg &&\
rm latexgit.ind &&\
rm latexgit.latexgit.dummy || true &&\
rm latexgit.log &&\
rm latexgit.out &&\
rm latexgit.toc &&\
rm -rf examples/*.log &&\
rm -rf examples/*.aux &&\
echo "$(NOW): Done deleting all temporary and intermediate files after the build."
extract: pre_clean
echo "$(NOW): Now extracting the package." &&\
pdflatex latexgit.ins &&\
rm latexgit.log &&\
echo "$(NOW): Finished extracting the package."
build_examples: extract python_dependencies
echo "$(NOW): Now building the examples." &&\
cp latexgit.sty examples &&\
cd examples &&\
pdflatex example_1.tex &&\
python3 -m latexgit.aux example_1 &&\
pdflatex example_1.tex &&\
rm example_1.log &&\
rm example_1.aux &&\
rm example_1.latexgit.dummy &&\
pdflatex example_2.tex &&\
python3 -m latexgit.aux example_2 &&\
pdflatex example_2.tex &&\
rm example_2.log &&\
rm example_2.aux &&\
rm example_2.latexgit.dummy &&\
rm example_2.out &&\
pdflatex example_3.tex &&\
python3 -m latexgit.aux example_3 &&\
pdflatex example_3.tex &&\
rm example_3.log &&\
rm example_3.aux &&\
rm example_3.latexgit.dummy &&\
rm example_3.out &&\
pdflatex example_4.tex &&\
python3 -m latexgit.aux example_4 &&\
pdflatex example_4.tex &&\
rm example_4.log &&\
rm example_4.aux &&\
rm example_4.latexgit.dummy &&\
rm example_4.out &&\
rm latexgit.sty &&\
cd .. &&\
echo "$(NOW): Finished building the examples."
build_documentation: extract build_examples
echo "$(NOW): Now building the documentation." &&\
pdflatex latexgit.dtx &&\
pdflatex latexgit.dtx &&\
makeindex -s gglo.ist -o latexgit.gls latexgit.glo &&\
makeindex -s gind.ist -o latexgit.ind latexgit.idx &&\
pdflatex latexgit.dtx &&\
echo "$(NOW): Done building the documentation."
build_website: build_documentation
echo "$(NOW): Now building the website." &&\
mkdir -p website &&\
echo "$(NOW): Now copying LICENSE and other files." &&\
pygmentize -f html -l latex -O full -O style=default -o website/latexgit_sty.html latexgit.sty &&\
pygmentize -f html -l latex -O full -O style=default -o website/latexgit_dtx.html latexgit.dtx &&\
pygmentize -f html -l latex -O full -O style=default -o website/latexgit_ins.html latexgit.ins &&\
pygmentize -f html -l text -O full -O style=default -o website/LICENSE.html LICENSE &&\
pygmentize -f html -l text -O full -O style=default -o website/requirements.html requirements.txt &&\
pygmentize -f html -l text -O full -O style=default -o website/requirements-dev.html requirements-dev.txt &&\
pygmentize -f html -l make -O full -O style=default -o website/Makefile.html Makefile &&\
echo "$(NOW): Finished creating additional files, now building index.html from README.md." &&\
export PART_A='<!DOCTYPE html><html><title>' &&\
export PART_B='</title><style>code {background-color:rgb(204 210 95 / 0.3);white-space:nowrap;border-radius:3px}</style><body style="margin-left:5%;margin-right:5%">' &&\
export PART_C='</body></html>' &&\
export BASE_URL='https\:\/\/thomasweise\.github\.io\/latexgit_tex\/' &&\
echo "$${PART_A}latexgit $(VERSION)$${PART_B}$(shell (python3 -m markdown -o html ./README.md))$$PART_C" > ./website/index.html &&\
sed -i "s/\"$$BASE_URL/\".\//g" ./website/index.html &&\
sed -i "s/=$$BASE_URL/=.\//g" ./website/index.html &&\
sed -i "s/<\/h1>/<\/h1><h2>version\ $(VERSION) build on\ $(NOW)<\/h2>/g" ./website/index.html &&\
echo "$(NOW): Finished copying README.md to index.html, now minifying all files." &&\
cd "website/" &&\
find -type f -name "*.html" -exec python3 -c "print('{}');import minify_html;f=open('{}','r');s=f.read();f.close();s=minify_html.minify(s,do_not_minify_doctype=True,ensure_spec_compliant_unquoted_attribute_values=True,keep_html_and_head_opening_tags=False,minify_css=True,minify_js=True,remove_bangs=True,remove_processing_instructions=True);f=open('{}','w');f.write(s);f.close()" \; &&\
cd "../" &&\
echo "$(NOW): Finished minifying all files, now copying or moving remaining files." &&\
mv latexgit.sty website &&\
mv latexgit.pdf website &&\
cp latexgit.dtx website &&\
cp latexgit.ins website &&\
cp Makefile website &&\
cp requirements.txt website &&\
cp requirements-dev.txt website &&\
touch website/.nojekyll &&\
echo "$(NOW): Done building the website."
build_tds: build_documentation build_website
echo "$(NOW): Now creating latexgit.tds.zip."
export tempDir=`mktemp -d` &&\
export oldDir="$(CWD)" &&\
echo "$(NOW): Created temp directory '$$tempDir'. Now building tds." &&\
mkdir -p "$$tempDir/tex/latex/latexgit/" &&\
cp website/latexgit.sty "$$tempDir/tex/latex/latexgit/" &&\
mkdir -p "$$tempDir/doc/latex/latexgit/" &&\
cp README.md "$$tempDir/doc/latex/latexgit/" &&\
cp website/index.html "$$tempDir/doc/latex/latexgit/README.html" &&\
cp website/latexgit.pdf "$$tempDir/doc/latex/latexgit/" &&\
mkdir -p "$$tempDir/source/latex/latexgit/" &&\
cp latexgit.ins "$$tempDir/source/latex/latexgit/" &&\
cp latexgit.dtx "$$tempDir/source/latex/latexgit/" &&\
cd "$$tempDir" &&\
zip -9 -r "latexgit.tds.zip" tex doc source &&\
mv "latexgit.tds.zip" "$$oldDir/website" &&\
rm -rf "$$tempDir" &&\
cd "$$oldDir" &&\
echo "$(NOW): Done building latexgit.tds.zip."
# The meta-goal for a full build
build: build_documentation build_examples build_tds build_website extract status pre_clean post_clean python_dependencies
echo "$(NOW): The build has completed."
# .PHONY means that the targets init and test are not associated with files.
# see https://stackoverflow.com/questions/2145590
.PHONY: build build_documentation build_examples build_tds build_website extract status pre_clean post_clean python_dependencies