TEX=$(shell command -v lualatex xelatex | head -n 1) SOURCE=. SRC =$(wildcard *.rst) SVG =$(wildcard content/*.svg) PDFS = $(SRC:.rst=.pdf) INCLUDED_PDF = $(SVG:.svg=.pdf) all: $(PDFS) BIBS =$(wildcard *.bib) DIR = $(sort $(shell find $(SOURCE) -name '*.rst' -print)) SOURCES = $(sort $(wildcard resources/*.tex) ) null := space := $(null) # comma := , TEX_STYLE := $(subst $(space),$(comma),$(strip $(SOURCES))) TEX_BIBS := $(subst $(space),$(comma),$(strip $(BIBS))) # Add a variable for specific options to add in the rst2latex command # RST_OPTIONS ?= PACK = $(shell sed -e 's/\#.*$$//' -e '/^$$/d' resources/modules) PACKAGES := $(subst $(space),$(comma),$(strip $(PACK))) tmp: mkdir tmp # Generate the latex file from rst tmp/%.tex: %.rst $(INCLUDED_PDF) $(SOURCES)| tmp $$(command -v rst2latex rst2latex.py | head -n 1) \ --no-section-subtitles \ --table-style=borderless \ --use-latex-citations \ --use-latex-docinfo \ --documentclass=extarticle \ --documentoption=12pt,A4,table \ --syntax-highlight=short \ $(RST_OPTIONS) \ --stylesheet=$(PACKAGES),$(TEX_STYLE) $< $@ sed -i -e 's/continued on next page/suite sur la page suivante/;s|^%$$||' $@ sed -i -e 's/admonition-/admonition/g' $@ # Generate each pdf with latex tmp/%.pdf: tmp/%.tex $(BIBS) | tmp $(TEX) -output-directory tmp $< #bibtex tmp/$*.aux && $(TEX) -output-directory tmp $< || echo "no bib" while grep 'Rerun to get ' tmp/$*.log ; do $(TEX) -output-directory tmp $< ; done # Put the pdf in the right place %.pdf: tmp/%.pdf | tmp cp $< $@ # Update mupdf if the process exist, or do nothing. pkill -HUP mupdf || true clean: rm -r tmp # Generate the final PDF document # Send a notification to mupdf in order to refresh the document %.png: %.pdf gs -dTextAlphaBits=4 -dFirstPage=1 -dLastPage=1 -dBATCH -dNOPAUSE -sDEVICE=png16m -r150 -dUseCropBox -sOutputFile=$@ $< # Watch mode, which regenerate the documents as soon there is a change in a # file., # requires inotifywait (package inotify-tools) watch: while true; do \ $(MAKE) all; \ inotifywait -qre close_write . ; \ done # Format the pages in order to make them printable in a book book: $(PDFS) pdfbook2 --no-crop $<