From 9a2c0f0e1f0ada78a1659a6657834b4e902dd642 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Tue, 9 May 2023 22:09:55 -0500 Subject: [PATCH] Produce both A4 and US-Letter pdfs --- .gitignore | 5 ++-- Makefile | 71 ++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 96bf4b4..66b9fd2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ doc/sphinx-venv/ # A generated requirements.txt file doc/requirements.txt.new -# The generated pdf -sokwedbtechnical.pdf +# The generated pdfs +doc/sokwedbtechnical_a4.pdf +doc/sokwedbtechnical_letter.pdf diff --git a/Makefile b/Makefile index bf26079..572fa73 100644 --- a/Makefile +++ b/Makefile @@ -71,18 +71,25 @@ endif # Variables # PREFIX := doc -PDF_NAME := sokwedbtechnical.pdf EMACS_BK_CHR := ~ +# The pdf file built by sphinx +PDF_NAME := sokwedbtechnical.pdf +# The pdf file names we copy out of the sphinx build dirs +PDF_A4_NAME := sokwedbtechnical_a4.pdf +PDF_LETTER_NAME := sokwedbtechnical_letter.pdf + # Website location in file system DOC_ROOT := /var/www/html -PDF_PATH := $(DOC_ROOT)/$(PDF_NAME) +PDF_A4_PATH := $(DOC_ROOT)/$(PDF_A4_NAME) +PDF_LETTER_PATH := $(DOC_ROOT)/$(PDF_LETTER_NAME) HTML_PATH := $(DOC_ROOT)/doc # Locations where docs are built by sphinx SPHINX_PREFIX := $(PREFIX)/sphinx-doc SPHINX_BUILDDIR := $(SPHINX_PREFIX)/build -SPHINX_BUILT_LATEX := $(SPHINX_BUILDDIR)/latex +SPHINX_BUILT_LATEX_A4 := $(SPHINX_BUILDDIR)/latex_a4 +SPHINX_BUILT_LATEX_LETTER := $(SPHINX_BUILDDIR)/latex_letter SPHINX_BUILT_HTML := $(SPHINX_BUILDDIR)/$(HTML_TARGETDIR) # Locations of source files, original m4 and generated @@ -96,8 +103,9 @@ M4_INCLUDE_PATH := include M4_DOC_INCLUDE_PATH := doc/include M4_DB_INCLUDE_PATH := db/include -# The target sphinx builds for a pdf -PDF_TARGET := $(PDF_NAME) +# The locations the targets are copied into +PDF_A4_TARGET := $(PREFIX)/$(PDF_A4_NAME) +PDF_LETTER_TARGET := $(PREFIX)/$(PDF_LETTER_NAME) # Rebuild when any of these change DB_DEPENDS := Makefile $(wildcard $(M4_INCLUDE_PATH)/*.m4) \ @@ -143,7 +151,8 @@ HTML_EPILOG := $(SPHINX_PREFIX)/html_epilog.inc LATEX_EPILOG := $(SPHINX_PREFIX)/latex_epilog.inc # Where sphinx puts the pdf it builds -SPHINX_PDF_TARGET := $(SPHINX_BUILT_LATEX)/$(PDF_TARGET) +SPHINX_PDF_A4_TARGET := $(SPHINX_BUILT_LATEX_A4)/$(PDF_NAME) +SPHINX_PDF_LETTER_TARGET := $(SPHINX_BUILT_LATEX_LETTER)/$(PDF_NAME) # Image targets DIA_BASEDIR := diagrams/dia/ @@ -164,7 +173,7 @@ CLEAN_TARGETS := $(PREFIX)/requirements.txt.new \ $(SPHINX_PREFIX) \ $(HTML_RST_FILES) $(LATEX_RST_FILES) \ $(SVG_FILES) $(PNG_FILES) \ - $(PDF_TARGET) + $(PDF_A4_TARGET) $(PDF_LETTER_TARGET) ## ## The available targets for make (make TARGET) are: @@ -183,7 +192,7 @@ html: install-sphinx html_rst $(HTML_IMAGE_FILES) $(HTML_EPILOG) \ ## pdf Make pdf docs with sphinx .PHONY: pdf -pdf: install-sphinx $(PDF_TARGET) +pdf: install-sphinx $(PDF_A4_TARGET) $(PDF_LETTER_TARGET) ## mostlyclean Delete all the generated files but the virtualenv .PHONY: mostlyclean @@ -216,7 +225,7 @@ $(PREFIX)/requirements.txt.new: install-sphinx ## install-pdf Install the pdf docs on the website .PHONY: install-pdf -install-pdf: $(PDF_PATH) +install-pdf: $(PDF_A4_PATH) $(PDF_LETTER_PATH) ## install-html Install the html docs on the website .PHONY: install-html @@ -245,6 +254,17 @@ $(SPHINX_VENV): destroy-sphinx-venv: rm -rf $(SPHINX_VENV) +# The files we want for a pdf +## doc/sokwedbtechnical_a4.pdf +## Produce the A4 PDF technical docs +$(PDF_A4_TARGET): $(SPHINX_PDF_A4_TARGET) + cp $(SPHINX_PDF_A4_TARGET) $(PDF_A4_TARGET) + +## doc/sokwedbtechnical_letter.pdf +## Produce the US-Letter PDF technical docs +$(PDF_LETTER_TARGET): $(SPHINX_PDF_LETTER_TARGET) + cp $(SPHINX_PDF_LETTER_TARGET) $(PDF_LETTER_TARGET) + ## html_rst Build RST files from m4 source for HTML generation .PHONY: html_rst html_rst: $(HTML_DIRS) $(HTML_RST_FILES) $(HTML_SRCDIR) @@ -296,29 +316,38 @@ $(SPHINX_VENV)/bin/sphinx-build: install_new_sphinx: $(SPHINX_VENV) $(SPHINX_VENV)/bin/pip install sphinx -# Install the pdf on the website -$(PDF_PATH): $(PDF_TARGET) - rsync -a $(PDF_TARGET) $(PDF_PATH) +# Install the pdfs on the website +$(PDF_A4_PATH): $(PDF_A4_TARGET) + rsync -a $(PDF_A4_TARGET) $(PDF_A4_PATH) +$(PDF_LETTER_PATH): $(PDF_LETTER_TARGET) + rsync -a $(PDF_LETTER_TARGET) $(PDF_LETTER_PATH) # Construct all the source dirs used to build output $(LATEX_DIRS) $(HTML_DIRS) $(HTML_SRCDIR) $(LATEX_SRCDIR) \ $(HTML_STATIC_DIR): mkdir -p $@ -# The file we want for a pdf -$(PDF_TARGET): $(SPHINX_PDF_TARGET) - cp $(SPHINX_PREFIX)/build/latex/$(PDF_TARGET) $(PDF_TARGET) - -# The file sphinx builds for a pdf +# +# The files sphinx builds for a pdf # It is unclear whether it's a good idea to run latexmk ourselves # or whether we should try to use the sphinx auto-generated Makefile # to do it, and try to keep the auto-generated Makefile under revision control. # Running it ourselves seems simplest. -$(SPHINX_PDF_TARGET): latex_rst $(PNG_FILES) $(LATEX_EPILOG) +# + +# A4 pdf +$(SPHINX_PDF_A4_TARGET): latex_rst $(PNG_FILES) $(LATEX_EPILOG) + $(SPHINXBUILD) -t a4paper -t latex_epilog -b latex \ + $(LATEX_SRCDIR) $(SPHINX_BUILT_LATEX_A4) + cd $(SPHINX_BUILT_LATEX_A4) \ + && latexmk -pdf -dvi- -ps- $(patsubst %.pdf,%.tex,$(PDF_NAME)) + +# Letter pdf +$(SPHINX_PDF_LETTER_TARGET): latex_rst $(PNG_FILES) $(LATEX_EPILOG) $(SPHINXBUILD) -t a4paper -t latex_epilog -b latex \ - $(LATEX_SRCDIR) $(SPHINX_BUILT_LATEX) - cd $(SPHINX_BUILT_LATEX) \ - && latexmk -pdf -dvi- -ps- $(patsubst %.pdf,%.tex,$(PDF_TARGET)) + $(LATEX_SRCDIR) $(SPHINX_BUILT_LATEX_LETTER) + cd $(SPHINX_BUILT_LATEX_LETTER) \ + && latexmk -pdf -dvi- -ps- $(patsubst %.pdf,%.tex,$(PDF_NAME)) # The rst_epilogs of conf.py. -- 2.34.1