--- /dev/null
+### -*-makefile-*-
+###
+### Build script for TeX packages
+###
+### (c) 2020 Mark Wooding
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+
+###--------------------------------------------------------------------------
+### Extension points.
+
+all::
+.PHONY: all
+
+install::
+.PHONY: install
+
+uninstall::
+.PHONY: uninstall
+
+check::
+.PHONY: check
+
+clean::; rm -f $(CLEANFILES)
+.PHONY: clean
+
+realclean:: clean; rm -f $(REALCLEANFILES)
+.PHONY: clean
+
+distdir:: recreate-distdir
+.PHONY: distdir
+
+###--------------------------------------------------------------------------
+### Project identification.
+
+VERSION := $(shell ./auto-version)
+DISTFILES += auto-version
+
+distdir:: recreate-distdir
+ $(v_at)echo "$(VERSION)" >$(distdir)/RELEASE
+
+###--------------------------------------------------------------------------
+### Tools.
+
+TEX = tex
+DVILATEX = latex
+PDFLATEX = pdflatex
+DVIPS = dvips
+
+###--------------------------------------------------------------------------
+### Installation directories.
+
+## Determine a sensible TeX base directory.
+prefix = /usr/local
+texmfdir := $(shell \
+ for d in $(prefix)/share/texmf $(prefix)/lib/texmf $(prefix)/texmf; do \
+ if [ -d $$d ]; then echo $$d; exit 0; fi; \
+ done; \
+ echo /invalid/)
+
+ifeq ($(texmfdir),/invalid/)
+ $(error "Failed to choose a TeX installation directory.")
+endif
+
+INSTALLDIRS += pkglatex
+pkglatexdir = $(texmfdir)/tex/latex/$(PACKAGE)
+
+INSTALLDIRS += pkgdoc
+pkgdocdir = $(texmfdir)/doc/latex/$(PACKAGE)
+
+###--------------------------------------------------------------------------
+### Preliminary definitions.
+
+.SECONDEXPANSION: # sorry
+
+## Silent-rules.
+V = 0
+
+v_at = $(v_at_$V)
+v_at_0 = @
+
+v_tag = $(call v_tag_$V,$1,$2)
+v_tag_0 = @printf " %-8s %s\n" "$1" "$2";
+
+v_null = $(v_null_$V)
+v_null_0 = >/dev/null
+
+v_quiet = $(v_quiet_$V)
+v_quiet_0 = -q
+
+## Runes for building rules.
+define output-targets
+$$(firstword $$($3_OUT)): $3 $4
+ $$(call v_tag,$2,$$<)$1 $$< $$(v_null)
+$$(wordlist 2,$$(words $$($3_OUT)),$$($3_OUT)): \
+ $$(firstword $$($3_OUT))
+endef
+
+###--------------------------------------------------------------------------
+### Project specific definitions.
+
+include Project.mk
+DISTFILES += Project.mk
+
+###--------------------------------------------------------------------------
+### Parse the `docstrip' installation files.
+
+parse-names = $(shell \
+ sed -n '/^\\mdwgen/,$$ s:^.*\\$1 *{\([^}]*\)}.*$$:\1:p' $2 | sort -u)
+
+define parse-insfile
+$1_DTX := $$(call parse-names,from,$1)
+$1_OUT := $$(call parse-names,mdwf,$1)
+endef
+$(foreach i,$(INS), $(eval $(call parse-insfile,$i)))
+
+DTX += $(sort $(foreach i,$(INS), $($i_DTX)))
+OUT += $(sort $(foreach i,$(INS), $($i_OUT)))
+
+###--------------------------------------------------------------------------
+### Extract output files from the `doc' files.
+
+all:: $(OUT)
+$(foreach i,$(INS), $(eval $(call output-targets,$$(TEX),TEX,$i,$($i_DTX))))
+
+DISTFILES += $(INS)
+DISTFILES += $(sort $(DTX) $(EXTRA))
+CLEANFILES += $(addsuffix .log,$(basename $(INS)))
+DISTFILES += $(OUT)
+REALCLEANFILES += $(OUT)
+
+###--------------------------------------------------------------------------
+### Build the documentation.
+
+## The main rune for running LaTeX.
+##
+## We run LaTeX in a subdirectory to prevent the temporary files (e.g., the
+## `.aux' files) from interfering with each other. The `\jobname' isn't
+## enough, because we might be building DVI and PDF versions of the same
+## document at the same time.
+run-latex = \
+ rm -rf t.$@/ && mkdir t.$@/ && cd t.$@/ && \
+ TEXINPUTS=..:$$TEXINPUTS && export TEXINPUTS && \
+ $1 "\def\indexing{n} \nonstopmode \input $<" $(v_null) && \
+ $1 "\def\indexing{y} \nonstopmode \input $<" $(v_null) && \
+ makeindex $(v_quiet) -s gind.ist $*.idx $(v_null) && \
+ $1 "\def\indexing{n} \nonstopmode \input $<" $(v_null) && \
+ mv $@ ../ && cd ../ && rm -rf t.$@/
+clean::; rm -rf t.*/
+
+## Good old-fashioned DVI.
+DVI = $(addsuffix .dvi,$(basename $(DTX)))
+pkgdoc_FILES += $(DVI)
+all:: $(DVI)
+%.dvi: %.dtx $(OUT) $(EXTRA)
+ $(call v_tag,DVILATEX,$@)$(call run-latex,$(DVILATEX))
+%.dvi: %.tex $(OUT) $(EXTRA)
+ $(call v_tag,DVILATEX,$@)$(call run-latex,$(DVILATEX))
+DISTFILES += $(DVI)
+REALCLEANFILES += $(DVI)
+
+## Build PostScript from the DVI.
+PS = $(addsuffix .ps,$(basename $(DTX)))
+pkgdoc_FILES += $(PS)
+all:: $(PS)
+%.ps: %.dvi
+ $(call v_tag,DVIPS,$@)$(DVIPS) $(v_quiet) -o $@ $<
+DISTFILES += $(PS)
+REALCLEANFILES += $(PS)
+
+## Build PDF using PDFTeX.
+PDF = $(addsuffix .pdf,$(basename $(DTX)))
+pkgdoc_FILES += $(PDF)
+all:: $(PDF)
+%.pdf: %.dtx $(OUT) $(EXTRA)
+ $(call v_tag,PDFLATEX,$@)$(call run-latex,$(PDFLATEX))
+%.pdf: %.tex $(OUT) $(EXTRA)
+ $(call v_tag,PDFLATEX,$@)$(call run-latex,$(PDFLATEX))
+DISTFILES += $(PDF)
+REALCLEANFILES += $(PDF)
+
+###--------------------------------------------------------------------------
+### Installation.
+
+install-targets = $(foreach d,$(INSTALLDIRS), install/$d)
+install:: $(install-targets)
+$(install-targets): install/%: $$($$*_FILES)
+ $(v_at)mkdir -p $(DESTDIR)$($*dir)
+ $(call v_tag,INSTALL,$($*dir))install -m$(or $($*_FILEMODE),644) \
+ $($*_FILES) $(DESTDIR)$($*dir)
+
+uninstall-targets = $(foreach d,$(INSTALLDIRS), uninstall/$d)
+uninstall:: $(uninstall-targets)
+$(uninstall-targets): uninstall/%: $$($$*_FILES)
+ $(call v_tag,UNINSTALL,$($*dir))rm -f \
+ $(addprefix $(DESTDIR)$($*dir)/,$($*_FILES))
+
+###--------------------------------------------------------------------------
+### Distribution.
+
+DISTFILES += COPYING $(wildcard README)
+DISTFILES += Makefile
+
+DISTFILES += debian/control debian/rules
+DISTFILES += debian/copyright debian/changelog
+DISTFILES += debian/compat
+
+distdir = $(PACKAGE)-$(VERSION)
+tarball = $(distdir).tar.gz
+
+distdir:: recreate-distdir $(DISTFILES)
+ $(v_at)set -e; \
+ for i in $(DISTFILES); do \
+ case $$i in */*) mkdir -p $(distdir)/$${i%/*} ;; esac; \
+ ln $$i $(distdir)/$$i; \
+ done
+
+dist: distdir
+ $(call v_tag,TAR,$(tarball))tar chzf $(tarball) $(distdir)
+ $(v_at)rm -rf $(distdir)/
+.PHONY: dist
+CLEANFILES += $(tarball)
+clean::; rm -rf $(distdir)/
+
+recreate-distdir:
+ $(v_at)rm -rf $(distdir)/
+ $(v_at)mkdir $(distdir)
+.PHONY: recreate-distdir
+
+distcheck: dist
+ rm -rf _distcheck/
+ mkdir _distcheck/ && cd _distcheck/ && \
+ tar xzf ../$(tarball) && cd $(distdir)/ && \
+ $(MAKE) check && \
+ $(MAKE) install texmfdir=../_install && \
+ $(MAKE) realclean && \
+ $(MAKE) install texmfdir=../_install && \
+ $(MAKE) uninstall texmfdir=../_install && \
+ $(MAKE) install DESTDIR=../_root && \
+ $(MAKE) uninstall DESTDIR=../_root && \
+ cd ../../ && \
+ find _distcheck/_install/ _distcheck/_root ! -type d | \
+ diff -u - /dev/null && \
+ rm -rf _distcheck
+.PHONY: distcheck
+clean::; rm -rf _distcheck/
+
+###----- That's all, folks --------------------------------------------------
+++ /dev/null
-## -*-makefile-*-
-##
-## Build system for mdwtools
-##
-## (c) 2002 Mark Wooding
-##
-
-##----- Licensing notice ----------------------------------------------------
-##
-## This file is part of the mdwtools LaTeX package collection.
-##
-## mdwtools is free software; you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 2 of the License, or
-## (at your option) any later version.
-##
-## mdwtools is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-## GNU General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with mdwtools; if not, write to the Free Software Foundation,
-## Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-AUTOMAKE_OPTIONS = foreign
-
-pkglatexdir = ${texmfdir}/tex/latex/${PACKAGE}
-pkgdocdir = ${texmfdir}/doc/latex/${PACKAGE}
-
-define(`addsuffix', `patsubst(`$1', `\>', `$2')')
-define(`BASE', `\
- at centre cmtt colour crypto doafter exercise footnote mdwkey \
- mdwlist mdwmath mdwref mdwtab mdwthm poetry slowbox sverb syntax')
-
-AUX = mdwtools.tex gpl.tex
-SRC = addsuffix(BASE, `.dtx')
-DVI = addsuffix(BASE, `.dvi') mdwtools.dvi
-PS = addsuffix(BASE, `.ps') mdwtools.ps
-PDF = addsuffix(BASE, `.pdf') mdwtools.pdf
-OBJ = \
- at.sty \
- cmtt.sty mttcmtt.fd mttenc.def \
- centre.sty \
- colour.sty \
- crypto.sty \
- doafter.sty \
- doafter.tex \
- exercise.sty \
- footnote.sty \
- mdwkey.sty \
- mdwlist.sty \
- mdwmath.sty \
- mdwref.sty \
- mdwtab.sty mathenv.sty mtcolour.sty mtcolor.sty \
- mdwthm.sty mdwmargin.thm \
- poetry.sty \
- slowbox.sty \
- sverb.sty svcolor.sty svcolour.sty svsplit.sty \
- syntax.sty
-
-pkglatex_DATA = $(OBJ) mdwtools.tex
-pkgdoc_DATA = $(DVI) $(PS) $(PDF)
-
-SUFFIXES = .dtx .tex .dvi .ps
-define(`run_latex', `rm -rf t.$`'@/ && mkdir t.$`'@/ && \
- cd t.$`'@/ && \
- TEXINPUTS=..:$$TEXINPUTS && export TEXINPUTS && \
- $1 "\def\indexing{n} \nonstopmode \input $<" && \
- $1 "\def\indexing{y} \nonstopmode \input $<" && \
- makeindex -s gind.ist $`'*.idx && \
- $1 "\def\indexing{n} \nonstopmode \input $<" && \
- mv $`'@ ../ && cd ../ && rm -rf t.$`'@/')
-
-.dtx.dvi:; run_latex(`latex')
-.tex.dvi:; run_latex(`latex')
-.dtx.pdf:; run_latex(`pdflatex')
-.tex.pdf:; run_latex(`pdflatex')
-.dvi.ps:; dvips -e0 -o $@ $<
-clean-local::; rm -rf t.*/
-
-$(DVI) $(PDF): gpl.tex $(OBJ) mdwtools.tex
-
-$(wordlist 2,$(words $(OBJ)),$(OBJ)): $(firstword $(OBJ))
-$(firstword $(OBJ)): $(SRC) mdwtools.ins
- tex mdwtools.ins
-
-EXTRA_DIST = $(SRC) $(AUX) $(DVI) $(OBJ) $(PS) $(PDF) \
- mdwtools.ins Makefile.m4
-
-MAINTAINERCLEANFILES = $(OBJ) $(DVI) $(PS) $(PDF)
-CLEANFILES = *.tmp *.aux *.idx *.ilg *.log *.toc *.ind *.lot *.ans
-
-Makefile.am: Makefile.m4
- m4 $(srcdir)/Makefile.m4 >Makefile.am.new
- mv Makefile.am.new $(srcdir)/Makefile.am
-
-dist-hook::
- echo $(VERSION) >$(distdir)/RELEASE
-EXTRA_DIST += auto-version
-
-EXTRA_DIST += debian/changelog debian/control debian/copyright debian/compat
-EXTRA_DIST += debian/rules
-
-.PHONY: dvi
-
-##----- That's all, folks ---------------------------------------------------
--- /dev/null
+### -*-makefile-gmake-*-
+###
+### Package-specfic definitions for the build script
+###
+### (c) 2020 Mark Wooding
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+### This file is part of the `mdwtools' LaTeX package collection.
+###
+### `mdwtools' is free software: you can redistribute it and/or modify it
+### under the terms of the GNU General Public License as published by the
+### Free Software Foundation; either version 2 of the License, or (at your
+### option) any later version.
+###
+### `mdwtools' is distributed in the hope that it will be useful, but
+### WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+### General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with `mdwtools'. If not, write to the Free Software Foundation,
+### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+## Package identification.
+PACKAGE = mdwtools
+
+## Installation files.
+INS = mdwtools.ins
+
+## Install all of our output files in the LaTeX directory.
+pkglatex_FILES += $(OUT)
+
+## Also format the main `mdwtools.tex' file. Things will depend on this.
+DTX += mdwtools.tex
+EXTRA += mdwtools.tex
+pkglatex_FILES += mdwtools.tex
+
+## Format the licence text.
+EXTRA += gpl.tex
+
+###----- That's all, folks --------------------------------------------------