X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mjotex.git;a=blobdiff_plain;f=GNUmakefile;h=61c9eca394ae7ea3767a2c554128dc1447358d9d;hp=3456c4d9c2f396d439345805b109ff52d3f6db75;hb=HEAD;hpb=a6c1d186ec5bbd8d02dfd2f057cd147afdfe900f diff --git a/GNUmakefile b/GNUmakefile index 3456c4d..3669ac2 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -2,8 +2,12 @@ # Example makefile using mjotex and a BibTeX references database. # -# The latex compiler. -LATEX = pdflatex -file-line-error -halt-on-error +# The latex compiler. The SOURCE_DATE_EPOCH=0 prevents the creation +# and modification dates from being embedded as metadata into the +# output file; that in turn is important because it allows us to tell +# when the output stops changing (that is, when we are done). The +# variable is supported in pdftex v1.40.17 and later. +LATEX = SOURCE_DATE_EPOCH=0 pdflatex -file-line-error -halt-on-error # The name of this document. # @@ -27,8 +31,8 @@ BIBS = local-references.bib # MJOTEX = mjo-algebra.tex mjo-algorithm.tex mjo-arrow.tex mjo-calculus.tex MJOTEX += mjo-common.tex mjo-complex.tex mjo-cone.tex mjo-convex.tex -MJOTEX += mjo-eja.tex mjo-font.tex mjo-linear_algebra.tex mjo-listing.tex -MJOTEX += mjo-misc.tex mjo-proof_by_cases.tex mjo-theorem.tex +MJOTEX += mjo-eja.tex mjo-font.tex mjo-hurwitz.tex mjo-linear_algebra.tex +MJOTEX += mjo-listing.tex mjo-proof_by_cases.tex mjo-set.tex mjo-theorem.tex MJOTEX += mjo-theorem-star.tex mjo-topology.tex mjo.bst # Compile a list of raw source code listings (*.listing) and their @@ -44,6 +48,16 @@ SAGE_LISTING_DSTS = $(patsubst %.listing,%.py,$(SAGE_LISTING_SRCS)) # INDICES = $(PN) +# We have to rebuild the index whenever the contents of the document +# change, because page numbers get moved around. But when no INDICES +# are defined, rebuilding them should be a no-op. This next definition +# ensures that. +ifdef INDICES +REMAKE_INDICES = makeindex $(INDEX_SRCS) +else +REMAKE_INDICES = true +endif + # Use kpsewhich (from the kpathsea suite) to find the absolute paths # of the bibtex/mjotex files listed in in $(BIBS)/$(MJOTEX). The SRCS # variable should contain all (Bib)TeX source files for the document. @@ -74,49 +88,25 @@ endif # in a makefile? # # At the start of this target, we call $(LATEX) to compile $(PN).tex. -# If you ignore the "sed" for now, then the next step is to check for -# the existence of a "previous" file. If there isn't one, this is the -# first time that we've tried to build the PDF. In that case, take the -# PDF that we've just built and make *that* the previous file. Then -# start all over. If there is a previous file, then this is the second -# (or more) time that we've tried to build the PDF. We diff the PDF -# file that we've just built against the previous file; if they're the -# same, then we've succeeded and stop. Otherwise, we make the new PDF -# the previous file, and start all over. The end result is that we -# will loop until the newly-created PDF and the previous file are -# identical. -# -# But what about the "sed" call? By default, pdflatex will compile the -# creation date, modification date, and a unique ID into the output -# PDF. That means that two otherwise-identical documents, created -# seconds apart, will look different. We only need to know when the -# *contents* of the document are the same -- we don't care about the -# metadata -- so sed is used to remove those three nondeterministic -# pieces of information. -# -# The creation and modification dates should become optional in pdftex -# v1.40.17 thanks to Debian's SOURCE_DATE_EPOCH initiative. When that -# version of pdflatex makes it into TeX Live 2016, we can replace -# those two sed scripts with something smarter. +# Afterwards, we check for the existence of a "previous" file. If +# there isn't one, then this is the first time that we've built the +# PDF. In that case, we take the PDF that we've just built and make it +# the "previous" file before starting all over. If, on the other hand, +# there already *was* a "previous" file, then this is the second (or +# third...) time that we've built the PDF. We diff the newly-built PDF +# against the "previous" file; if they're the same, then we've +# succeeded and stop. Otherwise, we make the new PDF the "previous" +# one, and start all over. The end result is that we will loop until +# the newly-created PDF and the "previous" one are identical. # $(PN).pdf: $(SRCS) $(PN).bbl $(INDEX_DSTS) $(LATEX) $(PN).tex - sed --in-place \ - -e '/^\/ID \[<.*>\]/d' \ - -e "s/^\/\(ModDate\) (.*)/\/\1 (D:19700101000000Z00'00')/" \ - -e "s/^\/\(CreationDate\) (.*)/\/\\1 (D:19700101000000Z00'00')/" \ - $@ - - if [ ! -f $@.previous ]; then \ - mv $@ $@.previous; \ - $(MAKE) $@; \ - fi; - - if cmp -s $@ $@.previous; then \ + if [ -f $@.previous ] && cmp -s $@ $@.previous; then \ rm $@.previous; \ else \ mv $@ $@.previous; \ + $(REMAKE_INDICES); \ $(MAKE) $@; \ fi; @@ -164,7 +154,7 @@ $(PN).bbl: $(SRCS) | $(PN).aux ifdef BIBS bibtex $(PN).aux else - echo -n '' > $@ + printf '' > $@ endif # If the output PDF exists but the log file does not, then an attempt @@ -175,9 +165,10 @@ $(PN).log: $(SRCS) $(MAKE) # How do we convert a raw listing into something testable by sage? We -# append/prepend triple quotes to make the whole thing into a doctest. +# append/prepend triple quotes to make the whole thing into a doctest, +# and then we replace any blank lines by "". sage_listings/%.py: sage_listings/%.listing - echo '"""' > $@ && cat $< >> $@ && echo '"""' >> $@ + echo '"""' > $@ && cat $< >> $@ && echo '"""' >> $@ && sed -i 's/^[[:space:]]*$$//' $@ # Ensure that there are no overfull or underfull boxes in the output # document by parsing the log for said warnings. @@ -186,11 +177,12 @@ check-boxes: $(PN).log @! grep -i 'overfull\|underfull' $< # Run chktex to find silly mistakes. There is some exit code weirdness -# (Savannah bug 45979), so we just look for empty output. +# (Savannah bug 53129), so we just look for empty output. .PHONY: check-chktex CHKTEX = chktex --localrc .chktexrc --quiet --inputfiles=0 check-chktex: - @[ -z "$(shell $(CHKTEX) mjotex.sty)" ] + @chktexout=$$($(CHKTEX) $(PN).tex); \ + test -z "$${chktexout}" || { echo "$${chktexout}" 1>&2; exit 1; } # Ensure that there are no undefined references in the document by # parsing the log file for said warnings. @@ -205,9 +197,7 @@ check-undefined: $(PN).log .PHONY: check-sage check-sage: $(SAGE_LISTING_DSTS) ifdef SAGE_LISTING_DSTS - PYTHONPATH="$(HOME)/src/sage.d" \ - sage -t --timeout=0 --memlimit=0 \ - $^ + sage -t --timeout=0 $^ endif # Run a suite of checks. @@ -233,4 +223,4 @@ clean: .PHONY: dist dist: $(PN).bbl mkdir -p dist - cp $(SRCS) $(PN).bbl $(BIBPATHS) $(MJOTEXPATHS) dist/ + cp $(SRCS) $(PN).bbl dist/