# $Id: Makefile 1258 2026-06-09 14:53:27Z karl $
# Public domain.  Originally written 2006, Karl Berry.
# Makefile for latexrefman.

en_tex_output = latex2e.dvi latex2e.pdf
es_tex_output = latex2e-es.dvi latex2e-es.pdf
fr_tex_output = latex2e-fr.dvi latex2e-fr.pdf
#
xref_suffixes := ky cp vr fn cp pg tp
xref_suffixes := $(xref_suffixes) $(addsuffix s,$(xref_suffixes))
xref_suffixes := aux log toc $(xref_suffixes)
mi_suffixes = dbk html info txt epub
en_mi_output = $(addprefix latex2e., $(mi_suffixes))
es_mi_output = $(addprefix latex2e-es., $(mi_suffixes))
fr_mi_output = $(addprefix latex2e-fr., $(mi_suffixes))
#
all_suffixes = dvi pdf $(mi_suffixes)

#  how to build.
#
texi2dvi = texfot texi2dvi --batch --tidy --build-dir=$*.t2dvi
texi2pdf = texfot texi2pdf --batch --tidy --build-dir=$*.t2pdf
#
makeinfo = makeinfo
texi2docbook = $(makeinfo) --docbook
texi2epub3 = $(makeinfo) --epub3
texi2html = $(makeinfo) --no-split $(htmlopts)
texi2info = $(makeinfo) --no-split
texi2latex = $(makeinfo) --latex
texi2txt = $(makeinfo) --plaintext --no-split
#
htmlopts = --html $(html_css) $(t2html_config)
#
html_css = --css-include=latex2e.css
#
t2html_config = $(t2html_top) $(t2html_pagewords) $(t2html_menu) $(t2html_home)
#
# Go somewhere useful from Top:
t2html_top = -c TOP_NODE_UP_URL=https://tug.org/texinfohtml/
#
# Nodes must be larger than this to get navigation panel at bottom of
# page; default is 300.
t2html_pagewords = -c WORDS_IN_PAGE=10000
#
# For makeinfo 7.0, needed this to get warnings about tree structure:
#t2html_menu = -c CHECK_NORMAL_MENU_STRUCTURE=1
# https://lists.gnu.org/archive/html/bug-texinfo/2024-01/msg00021.html
# But as of 7.1, it is the default again (whew).
t2html_menu =
#
# Incidentally, a tree transformation can generate missing menu entries:
#   -c TREE_TRANSFORMATIONS=complete_tree_nodes_menus file.texi
#
# Put a link in the footer:
t2html_home = -c PRE_BODY_CLOSE="<hr/><div class='referenceinfo'>\
<a href='https://latexref.xyz/'>\
<i>Unofficial LaTeX2e reference manual</i></a></div>"

%.pdf: %.texi
	$(texi2pdf) $<
%.dvi: %.texi
	$(texi2dvi) $<
#
%.dbk: %.texi
	$(texi2docbook) -o $@ $<
%.epub: %.texi
	$(texi2epub3) $<
%.html: %.texi latex2e.css
	$(texi2html) $<
%.info: %.texi
	$(texi2info) $<
%.ltx: %.texi
	$(texi2latex) -o $@ $<
%.txt: %.texi
	$(texi2txt) -o $@ $<

#  targets follow.
#
default: check-en

# convenience.
enp: latex2e.pdf

# to test changes, build a subset: html and info (since these formats
# exercise significantly different code paths), and pdf for tex.
check_suffixes = html info pdf
#
check-en: spell-en $(addprefix latex2e., $(check_suffixes))
check-es: $(addprefix latex2e-es., $(check_suffixes))
check-fr: $(addprefix latex2e-fr., $(check_suffixes))
check: check-en check-es check-fr

dw:
	sed 's/^@.*index.*$$//' latex2e.texi | dw

# Build per language.
en: $(en_mi_output) $(en_tex_output)
es: $(es_mi_output) $(es_tex_output)
fr: $(fr_mi_output) $(fr_tex_output)

# To build everything in all languages.
all: en es fr

# Sort of following the GNU sequence of clean targets.
distclean clean mostlyclean:
	rm -rf latex2e*.t2* $(distname) $(distname)*zip
	rm -rf src/latex2e src/testdist

realclean maintainer-clean: distclean
	rm -f $(addprefix latex2e*., pdf dvi $(mi_suffixes) $(xref_suffixes))

#  Basic dist target for CTAN, but please see ./CTAN
# for all the necessary steps.
#
txt_files = ChangeLog Makefile NEWS README \
            aspell.en.pws latex2e.css ltx-help.el
# html_files = index.html mirroring.html writing.html
figure_files = list.eps list.pdf list.png list.txt
figure_source_files = asy/list.asy
distname = latex2e-help-texinfo
distzip = $(distname).zip
#
webtree = $(distname)-tree
#
# Make the distribution for CTAN; but use the "commitready" target
# below instead of this directly, to get the split output for the web site.
# 
# The *.html files here at the top level of the repository, including
# index.html, end up at https://latexref.xyz/dev/.  

dist: en #es
	@printf "\n\f Making $@ (for CTAN) ...\n"
	rm -rf $(distname)
	mkdir $(distname) && cd $(distname) && ln -s ../* .
	mkdir $(distname)/spanish && cd $(distname)/spanish && ln -s ../../* .
	rm -f $(distzip)
	zip -q $(distzip) \
$(addprefix $(distname)/, $(txt_files) \
latex2e.texi common.texi $(en_mi_output) latex2e.pdf) \
$(addprefix $(distname)/spanish/,  $(es_mi_output) latex2e-es.pdf) \
$(addprefix $(distname)/latex2e-figures/,  $(figure_files)) \
$(addprefix $(distname)/graphics/,  README $(figure_source_files))
	zip -q $(distzip) $(distname)
	@ls -l $(distzip); unzip -l $(distzip) # CTAN

# To update web site, after basic build is ok (check-dw, spelling, etc.),
# first undo temporary build results:
#   make svr       # revert generated single files
#   make svrsplit  # revert generated split html
# then update ChangeLog, etc.,
# then svn commit the modified source files,
# then make commitready, which runs:
#	$(MAKE)
#	$(MAKE) htmlsplit
#	$(MAKE) dist
#	$(MAKE) easyurls     # depends on htmlsplit and dist
# and then:
#   $(MAKE) distdiff  # diff from last release, if you have TL
#   svn commit        # when ok, to commit regenerated files
# then:
#   svn -q update     # restore easy url stubs
#   make svrsplit     # restore generated split html
#   make distclean    # remove
#
# If uploading to CTAN:
#   see file ./CTAN (update NEWS, write announcement, etc.)
#   when ready, upload latex2e-help-texinfo.zip
#
# Clean up:
postwebclean:
	rm -rf $(distname) $(distname).zip # the ctan dist
	rm -rf src/testdist src/latex2e # from easyurls
	rm -f $(webtree).zip $(webtree)-easyurls.zip
	rm -rf $(webtree) # remove the web site split html
	svn revert -R $(webtree) >/tmp/svri # restore it
	svn -q update # postwebclean
	svn status # postwebclean

# In Texinfo 7.0, the default output directory changed to foo_html.
# Change it back.
html_split_opts = $(htmlopts) -o latex2e

# Get many small .html files.
htmlsplit: en
	@printf "\n\f Making $@ ...\n"
	rm -rf $(webtree)
	mkdir $(webtree) && cd $(webtree) && ln -s ../* .
	cd $(webtree) && $(makeinfo) $(html_split_opts) latex2e.texi
	cd $(webtree)/latex2e && ln -s ../../latex2e-figures .

# easyurls are not distributed on CTAN (nothing split is).
easyurls_python = python # depends on bs4 (beautifulsoup4)
easyurls_debug = # --debug
easyurls_dir = --directory latex2e # where we'll write
easyurls_opt = --action softlink --lower_case --rewrite_index $(easyurls_debug)
easyurls_zip = ../$(webtree)-easyurls.zip
#
# cd into src,
# create and read src/testdist/latex2e, write src/latex2e;
# then pack that into *easyurls.zip, and
# then unpack that into $(webtree) to revivify the easyurl files.
easyurls: htmlsplit dist
	@printf "\n\f Making $@ ...\n"
# easyurls operates on the split tree, make a copy for a base
	cd $(webtree) && zip -qr ../$(webtree).zip latex2e
	cd src \
        && rm -rf testdist && mkdir -p testdist \
        && rm -rf latex2e && unzip -q ../$(webtree).zip \
        && $(easyurls_python) ./easyurls.py $(easyurls_dir) $(easyurls_opt) \
        && zip -qry $(easyurls_zip) latex2e \
	&& unzip -qn $(easyurls_zip) -d ../$(webtree)
# zip -y: store symlinks as symlinks
# unzip -n: do not overwrite anything (we only want the new easyurls links)

# Before a commit, delete html files that are gone and add new ones.
splitstatus = cd $(webtree)/latex2e && svn status
commitready: easyurls
	@printf "\n\f Making $@ ...\n"
	svn revert -q -R $(webtree)/latex2e-fr # don't touch French, and
	cd $(webtree)/latex2e && svn revert fr # keep fr symlink for French
	$(splitstatus) | sed -n 's/^\!//p' | xargs -r svn rm
	$(splitstatus) | sed -n 's/^\?//p' | xargs -r svn add
# remove the unused top-level links.
	cd $(webtree) && svn status | sed -n 's/^\?//p' | xargs rm -f
	rm -rf latex2e.t2dvi
	svn status # commitready

# spanish/ will not in the released version, that's a separate directory.
distdiff:
	diff -u0r --ignore-all-space /usr/local/texlive/dev/texmf-dist/doc/latex/$(distname) $(distname) | tee /tmp/lrdiff

#  A hacky spell check target.
# Remove \commandnames to reduce exception list, but not {args} or
# [args], since they are often words.
spell spell-en:
	sed -e 's/\\[a-zA-Z]*//g' -e 's/U+[0-9A-F]\{4\}//' latex2e.texi \
	| aspell list --mode=texinfo --add-extra-dicts=`pwd`/aspell.en.pws \
        | sort -f -u
# No capital letters in @PkgIndex argument, since it's output in typewriter.
	! grep '@PkgIndex{.*[A-Z]' 

# Check for doubled words.
# https://www.math.utah.edu/~beebe/software/file-tools.html#dw
# The first sed expression elides a few @-command lines which cause
# duplicates; the second expr some text in the middle of lines.
check-dw:
	sed -e 's/^@\(c\|node\|item\|anchor\|.index\|.*section\) .*//' \
	    -e 's/ da da\|xxx\|overwrite\|{test test}\|[iI][jJ]//g' \
	  latex2e.texi | dw

# Convenience targets for svn operations.
svat sat:
	svn status
svup sup:
	svn -q update
svr:
	svn revert $(addprefix latex2e*., $(all_suffixes))
	svn status
svri svrsplit:
	svn revert -R $(webtree)
	svn status
svd:
	svn diff -x -p $(txt_files) *.texi
