summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/phfthm/pkg.mk
blob: 328b5fc36d373e53eed679f51a8d1ea6cb0308b7 (plain)
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
182
183
184
185
186
187
188

#
# Common useful definitions
#
LATEX = latex

PDFLATEXNAME = pdflatex

PDFLATEX = TEXINPUTS="$$TEXINPUTS:../phfnote" $(PDFLATEXNAME)
PDFLATEXOPTS = -interaction=batchmode
PDFLATEXOPTSLAST = -interaction=batchmode --synctex=1

MAKEINDEX = makeindex


#
# Set default PREFIX. This can be overridden with 'make install PREFIX=/installation/directory'
#
DEFAULT_PREFIX := $(shell kpsewhich -var-value TEXMFHOME)
PREFIX ?= $(DEFAULT_PREFIX)


#
# package should be set in variable PKG
#
PKGREADME = README.md

#
# packages may specify additional files in the distribution with this variable
# (by default empty)
#
DIST_ADDITIONAL_FILES ?= 

#
# Additional files automatically generated by the .ins file, such as .def files
# (by default empty)
#
ADDITIONAL_GENERATED_FILES ?= 


# By default, the generated style file is a '.sty' latex package.  If it's a
# '.cls' class file instead, the local Makefile will redefine this to 'cls'.
PKGSTYEXT ?= sty

PKGDTX = $(PKG).dtx
PKGSTY = $(PKG).$(PKGSTYEXT)
PKGINS = $(PKG).ins
PKGPDF = $(PKG).pdf
PKGTDSZIP = $(PKG).tds.zip
PKGZIP = $(PKG).zip


.PHONY: help sty cls pdf install install_sty install_cls install_doc tdszip dist clean cleanall cleansty cleancls cleanaux cleanpdf cleantdszip cleandist


help:
	@echo "Targets for $(PKG):"
	@echo "make $(PKGSTYEXT)             -- generate LaTeX package file $(PKG).$(PKGSTYEXT)"
	@echo "make pdf             -- generate pdf documentation"
	@echo "make install         -- install style and documentation files to $(DEFAULT_PREFIX)"
	@echo "make install PREFIX=[specify texmf directory destination]"
	@echo "make $(PKG).tds.zip  -- create TDS.ZIP package for distribution"
	@echo "make dist            -- create distribution ZIP, ready for upload to CTAN"
	@echo "make clean           -- remove LaTeX auxiliary files"
	@echo "make clean$(PKGSTYEXT)        -- remove generated style file"
	@echo "make cleanpdf        -- remove generated pdf documentation"
	@echo "make cleanall        -- remove all generated files, incl. distribution zip"


clean: cleanaux

cleanall: cleansty cleanaux cleanpdf cleantdszip cleandist

# ------------------------------------------------
# make sty
# ------------------------------------------------

sty: $(PKGSTY)

# synonym of `sty` in case of LaTeX classes, we use same commands etc.
cls: $(PKGSTY)

$(PKGSTY): $(PKGINS) $(PKGDTX)
	$(LATEX) $<

cleansty:
	@rm -f $(PKGSTY) $(ADDITIONAL_GENERATED_FILES)

cleancls: cleansty


# ------------------------------------------------
# make pdf
# ------------------------------------------------

pdf: $(PKG).pdf

#
# fake index & glossary so they get a TOC entry from the beginning, and so the page
# numbers in the index are correct.
#
$(PKG).aux $(PKG).idx $(PKG).glo: $(PKGDTX) $(PKGSTY)
	DTX=$< ; echo '\\begin{theindex}\\item index here \\end{theindex}' >$${DTX%.dtx}.ind
	DTX=$< ; echo '\\begin{theglossary}\\item changes here\\end{theglossary}' >$${DTX%.dtx}.gls
	$(PDFLATEX) $(PDFLATEXOPTS) $<
	$(PDFLATEX) $(PDFLATEXOPTS) $<
	$(PDFLATEX) $(PDFLATEXOPTS) $<

$(PKG).ind: $(PKG).idx
	$(MAKEINDEX) -s gind.ist -o $@ $<

$(PKG).gls: $(PKG).glo
	$(MAKEINDEX) -s gglo.ist -o $@ $<

# final steps of making the PKG.pdf doc file.  At the end, touch the ind and gls files so
# that they don't look out-of-date (because the idx and glo files were overwritten again)
$(PKGPDF): $(PKGDTX) $(PKG).aux $(PKG).ind $(PKG).gls
	$(PDFLATEX) $(PDFLATEXOPTS) $<
	$(PDFLATEX) $(PDFLATEXOPTS) $<
	$(PDFLATEX) $(PDFLATEXOPTSLAST) $<
	touch $(PKG).ind $(PKG).gls $(PKG).pdf


cleanaux:
	@rm -f *.aux *.log *.toc *.glo *.gls *.ind *.idx *.ilg *.out *.bbl *.blg *.synctex.gz *.hd

cleanpdf:
	@rm -f $(PKGPDF)

# ------------------------------------------------
# 'make install' partial installation targets
# ------------------------------------------------

#
# The install target itself is defined per-package, in case packages want to install more
# files (such as bibtex styles)
#

install_sty: $(PKGSTY)
	mkdir -p $(DESTDIR)$(PREFIX)/tex/latex/$(PKG)
	cp $(PKGSTY) $(ADDITIONAL_GENERATED_FILES)  $(DESTDIR)$(PREFIX)/tex/latex/$(PKG)

install_cls: install_sty

install_doc: $(PKGPDF)
	mkdir -p $(DESTDIR)$(PREFIX)/doc/latex/$(PKG)
	cp $(PKGPDF) $(PKGREADME)  $(DESTDIR)$(PREFIX)/doc/latex/$(PKG)



# ------------------------------------------------
# make tdszip
# ------------------------------------------------

TDSTMPDIR = $(CURDIR)/_install_tds_zip.make.tmp

tdszip: $(PKGTDSZIP)

$(PKGTDSZIP): $(PKGSTY) $(PKGPDF)
	mkdir $(TDSTMPDIR)
	$(MAKE) install PREFIX=$(TDSTMPDIR)
	cd $(TDSTMPDIR) && zip -r $(CURDIR)/$(PKGTDSZIP) *
	rm -rf $(TDSTMPDIR)

cleantdszip:
	@rm -f $(PKGTDSZIP)


# ------------------------------------------------
# make dist
# ------------------------------------------------

DISTTMPDIR = $(CURDIR)/_install_dist_zip.make.tmp

dist: $(PKGZIP)

# feedback from CTAN upload manager: prefer not to provide tds.zip in CTAN upload
$(PKGZIP):  #$(PKGTDSZIP)
	rm -rf $(DISTTMPDIR)
	mkdir -p $(DISTTMPDIR)/$(PKG)
#	 cp $(PKGTDSZIP) $(DISTTMPDIR)
	cp $(PKGDTX) $(PKGINS) $(PKGPDF) $(PKGREADME) Makefile pkg.mk $(DIST_ADDITIONAL_FILES) $(DISTTMPDIR)/$(PKG)
#	cd $(DISTTMPDIR) && zip -r $(CURDIR)/$(PKGZIP) $(PKG) $(PKGTDSZIP)
	cd $(DISTTMPDIR) && zip -r $(CURDIR)/$(PKGZIP) $(PKG)
	rm -rf $(DISTTMPDIR)

cleandist:
	@rm -f $(PKGZIP)