3 ### Build script for TeX packages
5 ### (c) 2020 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
11 ###--------------------------------------------------------------------------
26 clean::; rm -f $(CLEANFILES)
29 realclean:: clean; rm -f $(REALCLEANFILES)
32 distdir:: recreate-distdir
35 ###--------------------------------------------------------------------------
36 ### Project identification.
38 VERSION := $(shell ./auto-version)
39 DISTFILES += auto-version
41 distdir:: recreate-distdir
42 $(v_at)echo "$(VERSION)" >$(distdir)/RELEASE
44 ###--------------------------------------------------------------------------
52 ###--------------------------------------------------------------------------
53 ### Installation directories.
55 ## Determine a sensible TeX base directory.
58 for d in $(prefix)/share/texmf $(prefix)/lib/texmf $(prefix)/texmf; do \
59 if [ -d $$d ]; then echo $$d; exit 0; fi; \
63 ifeq ($(texmfdir),/invalid/)
64 $(error "Failed to choose a TeX installation directory.")
67 INSTALLDIRS += pkglatex
68 pkglatexdir = $(texmfdir)/tex/latex/$(PACKAGE)
71 pkgdocdir = $(texmfdir)/doc/latex/$(PACKAGE)
73 ###--------------------------------------------------------------------------
74 ### Preliminary definitions.
76 .SECONDEXPANSION: # sorry
84 v_tag = $(call v_tag_$V,$1,$2)
85 v_tag_0 = @printf " %-8s %s\n" "$1" "$2";
90 v_quiet = $(v_quiet_$V)
93 ## Runes for building rules.
95 $$(firstword $$($3_OUT)): $3 $4
96 $$(call v_tag,$2,$$<)$1 $$< $$(v_null)
97 $$(wordlist 2,$$(words $$($3_OUT)),$$($3_OUT)): \
98 $$(firstword $$($3_OUT))
101 ###--------------------------------------------------------------------------
102 ### Project specific definitions.
105 DISTFILES += Project.mk
107 ###--------------------------------------------------------------------------
108 ### Parse the `docstrip' installation files.
110 parse-names = $(shell \
111 sed -n '/^\\mdwgen/,$$ s:^.*\\$1 *{\([^}]*\)}.*$$:\1:p' $2 | sort -u)
114 $1_DTX := $$(call parse-names,from,$1)
115 $1_OUT := $$(call parse-names,mdwf,$1)
117 $(foreach i,$(INS), $(eval $(call parse-insfile,$i)))
119 DTX += $(sort $(foreach i,$(INS), $($i_DTX)))
120 OUT += $(sort $(foreach i,$(INS), $($i_OUT)))
122 ###--------------------------------------------------------------------------
123 ### Extract output files from the `doc' files.
126 $(foreach i,$(INS), $(eval $(call output-targets,$$(TEX),TEX,$i,$($i_DTX))))
129 DISTFILES += $(sort $(DTX) $(EXTRA))
130 CLEANFILES += $(addsuffix .log,$(basename $(INS)))
132 REALCLEANFILES += $(OUT)
134 ###--------------------------------------------------------------------------
135 ### Build the documentation.
137 ## The main rune for running LaTeX.
139 ## We run LaTeX in a subdirectory to prevent the temporary files (e.g., the
140 ## `.aux' files) from interfering with each other. The `\jobname' isn't
141 ## enough, because we might be building DVI and PDF versions of the same
142 ## document at the same time.
144 rm -rf t.$@/ && mkdir t.$@/ && cd t.$@/ && \
145 TEXINPUTS=..:$$TEXINPUTS && export TEXINPUTS && \
146 $1 "\def\indexing{n} \nonstopmode \input $<" $(v_null) && \
147 $1 "\def\indexing{y} \nonstopmode \input $<" $(v_null) && \
148 makeindex $(v_quiet) -s gind.ist $*.idx $(v_null) && \
149 $1 "\def\indexing{n} \nonstopmode \input $<" $(v_null) && \
150 mv $@ $*.log ../ && cd ../ && rm -rf t.$@/
153 ## Good old-fashioned DVI.
154 DVI = $(addsuffix .dvi,$(basename $(DTX)))
155 pkgdoc_FILES += $(DVI)
157 %.dvi: %.dtx $(OUT) $(EXTRA)
158 $(call v_tag,DVILATEX,$@)$(call run-latex,$(DVILATEX))
159 %.dvi: %.tex $(OUT) $(EXTRA)
160 $(call v_tag,DVILATEX,$@)$(call run-latex,$(DVILATEX))
162 REALCLEANFILES += $(DVI)
164 ## Build PostScript from the DVI.
165 PS = $(addsuffix .ps,$(basename $(DTX)))
166 pkgdoc_FILES += $(PS)
169 $(call v_tag,DVIPS,$@)$(DVIPS) $(v_quiet) -o $@ $<
171 REALCLEANFILES += $(PS)
173 ## Build PDF using PDFTeX.
174 PDF = $(addsuffix .pdf,$(basename $(DTX)))
175 pkgdoc_FILES += $(PDF)
177 %.pdf: %.dtx $(OUT) $(EXTRA)
178 $(call v_tag,PDFLATEX,$@)$(call run-latex,$(PDFLATEX))
179 %.pdf: %.tex $(OUT) $(EXTRA)
180 $(call v_tag,PDFLATEX,$@)$(call run-latex,$(PDFLATEX))
182 REALCLEANFILES += $(PDF)
184 ###--------------------------------------------------------------------------
187 install-targets = $(foreach d,$(INSTALLDIRS), install/$d)
188 install:: $(install-targets)
189 $(install-targets): install/%: $$($$*_FILES)
190 $(v_at)mkdir -p $(DESTDIR)$($*dir)
191 $(call v_tag,INSTALL,$($*dir))install -m$(or $($*_FILEMODE),644) \
192 $($*_FILES) $(DESTDIR)$($*dir)
194 uninstall-targets = $(foreach d,$(INSTALLDIRS), uninstall/$d)
195 uninstall:: $(uninstall-targets)
196 $(uninstall-targets): uninstall/%: $$($$*_FILES)
197 $(call v_tag,UNINSTALL,$($*dir))rm -f \
198 $(addprefix $(DESTDIR)$($*dir)/,$($*_FILES))
200 ###--------------------------------------------------------------------------
203 DISTFILES += COPYING $(wildcard README)
204 DISTFILES += Makefile
206 DISTFILES += debian/control debian/rules
207 DISTFILES += debian/copyright debian/changelog
208 DISTFILES += debian/compat
210 distdir = $(PACKAGE)-$(VERSION)
211 tarball = $(distdir).tar.gz
213 distdir:: recreate-distdir $(DISTFILES)
215 for i in $(DISTFILES); do \
216 case $$i in */*) mkdir -p $(distdir)/$${i%/*} ;; esac; \
217 ln $$i $(distdir)/$$i; \
221 $(call v_tag,TAR,$(tarball))tar chzf $(tarball) $(distdir)
222 $(v_at)rm -rf $(distdir)/
224 CLEANFILES += $(tarball)
225 clean::; rm -rf $(distdir)/
228 $(v_at)rm -rf $(distdir)/
229 $(v_at)mkdir $(distdir)
230 .PHONY: recreate-distdir
234 mkdir _distcheck/ && cd _distcheck/ && \
235 tar xzf ../$(tarball) && cd $(distdir)/ && \
237 $(MAKE) install texmfdir=../_install && \
238 $(MAKE) realclean && \
239 $(MAKE) install texmfdir=../_install && \
240 $(MAKE) uninstall texmfdir=../_install && \
241 $(MAKE) install DESTDIR=../_root && \
242 $(MAKE) uninstall DESTDIR=../_root && \
244 find _distcheck/_install/ _distcheck/_root ! -type d | \
245 diff -u - /dev/null && \
248 clean::; rm -rf _distcheck/
250 ###----- That's all, folks --------------------------------------------------