# Load the configure script variables
-include ../configure.mk

##
## Options
##

# Pandoc flags
FLAGS      = --filter pandoc-crossref --citeproc --toc --number-sections
PDF_FLAGS  = --pdf-engine=xelatex
HTML_FLAGS = --standalone --katex$(KATEX_URL) --lua-filter filters/add-anchors.lua

# Rebuild everything if the makefile changed
.EXTRA_PREREQS += Makefile

# User manual
DOCDIR   = build/doc
SECTIONS = $(wildcard [0-9].*.md)
MANUALS  = $(addprefix $(DOCDIR)/,manual.html manual.pdf res)

##
## Targets
##

.PHONY: all clean

all: $(MANUALS) $(MANPAGES)

clean:
	rm -r build

$(DOCDIR)/manual.html: $(SECTIONS) res | $(DOCDIR)
	pandoc $(FLAGS) $(HTML_FLAGS) $(filter %.md, $^) -o '$@'

$(DOCDIR)/res: res | $(DOCDIR)
	cp -r $^ '$@'

$(DOCDIR)/manual.pdf: $(SECTIONS) | $(DOCDIR)
	pandoc $(FLAGS) $(PDF_FLAGS) $^ -o '$@'

# Create directories
$(DOCDIR):
	mkdir -p '$@'