F
F
faragly2018-09-12 10:29:36
GNU Make
faragly, 2018-09-12 10:29:36

How to move a compiled pdf file from a directory with renaming (add a suffix) in Makefile?

Hello! I use Sphinx-doc to generate project documentation, for simplicity there is a basic Makefile that allows you to build html or pdf with a simple command `make html` or `make latexpdf`. Since the project documentation is written in English and Russian, I start the generation for the Russian language by adding an additional argument `LANG=ru` (en is generated by default). Depending on the language, the source corresponding to the language is picked up, the pdf file is generated with the same name for any language in the folder with latex files. It is necessary to move the assembled pdf file to another directory and add the _ru or _en suffix.

# Makefile for Sphinx documentation
#

# You can set these variables from the command line.
LANG          = en
SPHINXOPTS    = -c sphinx/source -a -D language=$(LANG)
SPHINXBUILD   = sphinx-build
PAPER         =
BUILDDIR      = .

# Internal variables.
ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source/$(LANG)

.PHONY: help
help:
  @echo "Please use \`make <target>' where <target> is one of"
  @echo "  html       to make standalone HTML files, you can set LANG=ru (en default)"
  @echo "  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
  @echo "  latexpdf   to make LaTeX files and run them through pdflatex"

.PHONY: html
html:
  $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html/$(LANG)
  @echo
  @echo "Build finished. The HTML pages are in $(BUILDDIR)/html/$(LANG)."

.PHONY: latex
latex:
  $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex/$(LANG)
  @echo
  @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex/$(LANG)."
  @echo "Run \`make' in that directory to run these through (pdf)latex" \
        "(use \`make latexpdf' here to do that automatically)."

.PHONY: latexpdf
latexpdf:
  rm -rf $(BUILDDIR)/latex/$(LANG)
  $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex/$(LANG)
  @echo "Running LaTeX files through pdflatex..."
  $(MAKE) -C $(BUILDDIR)/latex/$(LANG) all-pdf
  @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex/$(LANG)."

There is an option to specify the file name immediately and add a command, it is known:
mv -f $(BUILDDIR)/latex/$(LANG)/documentation.pdf $(BUILDDIR)/pdf/documentation_$(LANG).pdf

but since the filename is set in the Sphinx-doc configuration file, you don't want to change this value in multiple places, you need a solution where you don't need to know the filename.
One more question, I want the documentation in all available languages ​​to be generated immediately, that is, the script looks for folders in `source`, forms an array of languages ​​and then bypasses this array, placing the current language in the LANG variable.
Sorry for the noob questions, but I have not come across GNU Make before, looking through the documentation did not give the right answers. Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question