################################################################################
##
## Basic parameters
## Can be overriden by ENV variables
##
###############################################################################

# Build directory
B?=_build

# Tests
T?=tests

# DEST is the folder where we install everything
DEST?=$(HOME)/.dalibo/themes

# if pandoc is not installed, let's use docker
ifeq (, $(shell which pandoc))
	DOCKER?=latest
endif

##
## Keep this for backward compatibility with projects based on the 17.12 toolchain
##
all: buildir book1_precompil

###############################################################################
##
## Bats
##
###############################################################################

# We use bats-core instead of the original bats
BATS?=tests/libs/bats-core/bin/bats

ifeq ($(DOCKER),)
	# use local bats
	BATS?=tests/libs/bats-core/bin/bats
else
	# use pandocker
	D=docker run --privileged --rm --env TEXMFHOME=beamer -u `id -u`:`id -g`
	VOLUMES=--volume /tmp:/tmp --volume `pwd`:/pandoc
	IMAGE=dalibo/pandocker:$(DOCKER)
	BATS=$D $(VOLUMES) --entrypoint /pandoc/tests/libs/bats-core/bin/bats $(IMAGE)
endif


# Bats filter
#
# usage : `TEST_ONLY=2 make test` will run all the tests starting with '2'.
#
TEST_ONLY?=
TEST_REGEXP?=
BATS_FILTER=

ifneq ($(TEST_ONLY),)
	BATS_FILTER:=--filter '^$(TEST_ONLY).*'
endif

# you can also pass a regexp directly
ifneq ($(TEST_REGEXP),)
	BATS_FILTER:=--filter '$(TEST_REGEXP)'
endif

.PHONY: bats
BATS_FILES= $(wildcard tests/*.bats)
BATS_LOGS= $(patsubst tests/%.bats, tests/%.bats.log, $(BATS_FILES))

bats: $(BATS_LOGS)

tests/%.bats.log: tests/%.bats
	$(BATS) $(BATS_FILTER) $^

###############################################################################
##
## $P is the Pandoc test command line
## $Y is the Python environment / Python3 is mandatory
## $(PDFTOPPM) is a poppler util to export PDF thumbnails
## $WEASY is the WeasyPrint converter
##
###############################################################################

# workaround for CI / backward compatibility with pandocker 17.12
PANDOC?=pandoc
PYTHON?=python3
PDFTOPPM?=pdf2ppm
WEASY?=weasyprint

ifeq ($(DOCKER),)
	# use local pandoc
	P=$(PANDOC) -o $@ -V dlb=`pwd`
    Y=/usr/bin/$(PYTHON)
	PDFTOPPM=pdf2ppm
	WEASY=weasyprint
else
	# use docker
	D=docker run --privileged --rm --env TEXMFHOME=beamer -u `id -u`:`id -g`
	VOLUMES=--volume /tmp:/tmp --volume `pwd`:/pandoc
	IMAGE=dalibo/pandocker:$(DOCKER)
	P=$D $(VOLUMES) $(IMAGE) -o $@ -V dlb=/pandoc/
	Y=$D $(VOLUMES) --entrypoint /usr/bin/$(PYTHON) $(IMAGE)
	PDFTOPPM=$D $(VOLUMES) --entrypoint pdftoppm $(IMAGE)
	WEASY=$D $(VOLUMES) --entrypoint weasyprint $(IMAGE)
endif

###############################################################################
##
## Debug
##
###############################################################################

#debug:
#	fc-list

###############################################################################
##
## Pre-Built elements
## Some parts of the themes are built and delivered with the sources
## The goal is to simplify the installation process and the CI jobs
##
###############################################################################

prebuild:  book1_prebuild

book1_prebuild: tex/book1/note.pdf tex/book1/publications.pdf tex/book1/backcover.pdf tex/common/CC-BY-NC-SA-2.0-FR.tex

tex/book1/backcover.pdf: tex/book1/backcover.md
	$P --pdf-engine=xelatex --template tex/book1/backcover.tex $^

tex/book1/publications.pdf: tex/book1/publications.md
	$P --pdf-engine=xelatex --template tex/book1/backcover.tex $^

tex/book1/note.pdf: tex/book1/note.md
	$P --pdf-engine=xelatex --template tex/book1/backcover.tex $^

tex/common/CC-BY-NC-SA-2.0-FR.tex: tex/common/CC-BY-NC-SA-2.0-FR.md
	$P --pdf-engine=xelatex $^

tex/common/PostgreSQL.tex: tex/common/PostgreSQL.md
	$P --pdf-engine=xelatex $^

book1_precompil: $B/tex/book1/note.pdf $B/tex/book1/publications.pdf $B/tex/book1/backcover.pdf $B/tex/common/CC-BY-NC-SA-2.0-FR.tex

$B/tex/book1/backcover.pdf: tex/book1/backcover.md
	$P --pdf-engine=xelatex --template tex/book1/backcover.tex $^

$B/tex/book1/publications.pdf: tex/book1/publications.md
	$P --pdf-engine=xelatex --template tex/book1/backcover.tex $^

$B/tex/book1/note.pdf: tex/book1/note.md
	$P --pdf-engine=xelatex --template tex/book1/backcover.tex $^

$B/tex/common/CC-BY-NC-SA-2.0-FR.tex: buildir tex/common/CC-BY-NC-SA-2.0-FR.md
	$P --pdf-engine=xelatex tex/common/CC-BY-NC-SA-2.0-FR.md

$B/tex/common/PostgreSQL.tex: buildir tex/common/PostgreSQL.md
	$P --pdf-engine=xelatex tex/common/PostgreSQL.md



###############################################################################
#
# Compilation optionnelle
#
###############################################################################

%.hs:
	ghc $@

###############################################################################
#
# Installation
#
###############################################################################

install: dest fonts odt_install doc_install revealjs_install beamer_install

dest:
	mkdir -p $(DEST)
	cp -pr * $(DEST)

fonts:
	mkdir -p $(HOME)
	cp -pr fonts $(HOME)/.fonts/dalibo
	fc-cache -f -v

odt_install:

doc_install:

revealjs_install:

beamer_install:
	#echo 'export TEXMFHOME=$(DEST)/beamer' >> ~/.bashrc


###############################################################################
#
# Nettoyage
#
###############################################################################

list:
	@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs



clean:
	rm -fr $B $(BATS_LOGS)

uninstall:
	rm -fr $(DEST)

###############################################################################
##
## Tests
##
###############################################################################

buildir:
	mkdir -p $B
	mkdir -p $B/tex/common
	mkdir -p $B/tex/book1


test: latex_test reveal_test filters_test html_test postprod_test epub_test beamer s5


###############################################################################
##
## 1000: LaTeX
##
###############################################################################

LATEX_OPT= --number-sections --toc --pdf-engine=xelatex --from=markdown-smart

latex_test: basic_tex_test book1_test code_test latex_listings_test citeproc_test

##
## 1000 : basic tex
##
basic_tex_test: buildir $B/1001.tex $B/1002.pdf $B/1003.tex $B/1004.pdf $B/1011.pdf

$B/1001.tex: tests/ligatures.md
	$P $^

$B/1002.pdf: tests/ligatures.md
	$P --pdf-engine=xelatex --template tex/book1/template.tex $^

$B/1003.tex: tests/ligatures.md
	$P --from=markdown-smart $^

$B/1004.pdf: tests/ligatures.md
	$P --pdf-engine=xelatex --from=markdown-smart --template tex/book1/template.tex $^

# Backslash with latex : https://github.com/jgm/pandoc/issues/2790
# Should work
$B/1011.pdf: tests/test_antislash.md
	$P -f markdown-raw_tex --pdf-engine=xelatex $^

# Should NOT work
$B/1012.pdf: tests/test_antislash.md
	$P --pdf-engine=xelatex $^

##
## 11xx: LaTeX template manuel
##
## Test Désactivé ! Le template n'est plus supporté
## Les manuels sont compilés avec le template book1

B1100= $B/1101.pdf $B/1102.pdf $B/1104.pdf

$B/1101.pdf: $T/image.md
$B/1102.pdf: $T/vide.md
$B/1104.pdf: $T/livret.md

manuel_test: buildir $(B1100)

$(B1100):
	$P $(LATEX_OPT) --template tex/manuel/template.tex $^


##
## 1200 : Latex template book1
##

B1200:=$B/1201.pdf $B/1202.pdf $B/1211.tex $B/1212.pdf $B/1213.pdf $B/1214.pdf $B/1231.pdf
B1200+=$B/1241.pdf $B/1251.pdf $B/1252.pdf $B/1253.pdf $B/1261.pdf
B1200+=$B/1271.tex $B/1272.pdf $B/1281.pdf

$B/1201.pdf: $T/latex.config.md  $T/image.md
$B/1202.pdf: $T/vide.md
$B/1211.tex: $T/latex.config.md $T/livret.md
$B/1212.pdf: $T/latex.config.md $T/livret.md
$B/1213.pdf: $T/dba4.md
$B/1214.pdf: $T/bug_151_book1_and_tables.md
$B/1231.pdf: $T/test_inline_code.md
$B/1241.pdf: $T/end_notes.md
$B/1251.pdf: $T/backtick_in_title.md # backtick in title ?
$B/1252.pdf: $T/i3.md
$B/1253.pdf: $T/input/common/weird_characters.md
$B/1261.pdf: $T/test_citation.md
$B/1271.tex: $T/definitions.md
$B/1272.pdf: $T/definitions.md
$B/1281.pdf: $T/book1_couverture_alternative.md

book1_test: buildir $(B1200)
$(B1200):
	$P $(LATEX_OPT) -s --template tex/book1/template.tex $^

#FIXME
$B/4008.pdf: $T/bug_97_texte_perdu_apres_codeblocks.md
	$P $(LATEX_OPT) --template=tex/book1/template.tex --filter pandoc-latex-environment --filter pandoc-latex-admonition  $^



##
## 1300 : Latex template audit
## OBSOLETE
##

B1300:=$B/1301.pdf $B/1302.pdf $B/1311.tex $B/1312.pdf $B/1313.pdf $B/1331.pdf
B1300+=$B/1341.pdf $B/1351.pdf $B/1352.pdf $B/1361.pdf
B1300+=$B/1371.tex $B/1372.pdf $B/1381.pdf

$B/1301.pdf: $T/latex.config.md  $T/image.md
$B/1302.pdf: $T/vide.md
$B/1311.tex: $T/latex.config.md $T/livret.md
$B/1312.pdf: $T/latex.config.md $T/livret.md
$B/1313.pdf: $T/dba4.md
$B/1331.pdf: $T/test_inline_code.md
$B/1341.pdf: $T/end_notes.md
$B/1351.pdf: $T/backtick_in_title.md # backtick in title ?
$B/1352.pdf: $T/i3.md
$B/1361.pdf: $T/test_citation.md
$B/1371.tex: $T/definitions.md
$B/1372.pdf: $T/definitions.md
$B/1381.pdf: $T/book1_couverture_alternative.md

latex_audit_test: buildir $(B1300)
$(B1300):
	$P $(LATEX_OPT) --pdf-engine-opt=-shell-escape -s --template tex/audit/template.tex $^


##
## 1400 : code highlight
##
B1400:=$B/1401.pdf $B/1402.pdf $B/1402.pdf $B/1403.pdf $B/1404.pdf $B/1405.pdf $B/1405.pdf $B/1406.pdf $B/1407.pdf
B1400+=$B/1411.pdf $B/1412.pdf
B1400+=$B/1421.pdf

code_test: buildir $(B1400)

$B/1401.pdf: $T/code.md
	$P $(LATEX_OPT) --highlight-style pygments $^

$B/1402.pdf: $T/code.md
	$P $(LATEX_OPT) --highlight-style kate  $^

$B/1403.pdf: $T/code.md
	$P $(LATEX_OPT) --highlight-style monochrome  $^

$B/1404.pdf: $T/code.md
	$P $(LATEX_OPT) --highlight-style espresso $^

$B/1405.pdf: $T/code.md
	$P $(LATEX_OPT) --highlight-style haddock $^

$B/1406.pdf: $T/code.md
	$P $(LATEX_OPT) --highlight-style tango $^

$B/1407.pdf: $T/code.md
	$P $(LATEX_OPT) --highlight-style zenburn $^

$B/1411.pdf: $T/code.md
	$P $(LATEX_OPT) --template tex/book1/template.tex --highlight-style pygments $^

$B/1412.pdf: $T/code_indentation.md
	$P $(LATEX_OPT) --template tex/book1/template.tex --highlight-style pygments $^

$B/1421.pdf: $T/sqlpostgresql.md
	$P $(LATEX_OPT) --template tex/book1/template.tex $^


##
## 144x : Listings
##

latex_listings_test: $B/1441.pdf $B/1442.pdf $B/1443.pdf $B/1444.tex $B/1445.pdf $B/1446.pdf

$B/1441.pdf: $T/code_indentation.md
	$P $(LATEX_OPT) --template tex/book1/template.tex --listings --highlight-style pygments $^

$B/1442.pdf: $T/code.md
	$P $(LATEX_OPT) --template tex/book1/template.tex --highlight-style pygments $^

$B/1443.pdf: $T/code.md
	$P $(LATEX_OPT) --template tex/book1/template.tex --listings --highlight-style pygments $^

$B/1444.tex: $T/code.md
	$P $(LATEX_OPT) --template tex/book1/template.tex --listings --highlight-style pygments $^

$B/1445.pdf: $T/dba4.md
	$P $(LATEX_OPT) --template tex/book1/template.tex --listings $^

$B/1446.pdf: $T/dba4.md
	$P $(LATEX_OPT) --template tex/audit/template.tex --pdf-engine-opt=-shell-escape --listings $^

# https://gitlab.dalibo.info/marketing/themes/issues/107
#$B/1447.pdf: $T/dba4.md
#	$P $(LATEX_OPT) --template tex/audit/template.tex --filter pandoc-minted --pdf-engine-opt=-shell-escape --listings $^


##
## 145x : citeproc
##
citeproc_test: $B/1451.tex $B/1452.pdf


$B/1451.tex: $T/citeproc.md
	$P $(LATEX_OPT) --bibliography $T/biblio.yaml --citeproc --csl tex/common/csl/ieee.csl $^


$B/1452.pdf: $T/citeproc.md
	$P $(LATEX_OPT) --bibliography $T/biblio.yaml --citeproc --csl tex/common/csl/ieee.csl $^


##
## 16XX : Eisvogel
##

latex_eisvogel_test: tests/1600_eisvogel.bats.log


###############################################################################
#
# 2000 = CSS to PDF  [ABANDONNED]
#
###############################################################################

# htmlpdf_test: buildir $B/2001.pdf $B/2002.pdf

# $B/2001.pdf: $T/s1.md
# 	$P -t html5 --css html/screen/github.css $^

# $B/2002.pdf: $T/livret.md
# 	$P -t html5 --css html/print/book2/book2.css $^


###############################################################################
#
# 3xxx = Beamer
#
###############################################################################

beamer: buildir beamer_basic beamer_dalibo beamer_bugs

##
## 30xx : Basic
##

beamer_basic: $B/3001.tex $B/3002.pdf

$B/3001.tex: $T/presentation.md
	TEXMFHOME=beamer $P -st beamer -V theme:Dalibo $^

$B/3002.pdf: $T/presentation.md
	TEXMFHOME=beamer $P -st beamer -V theme:Dalibo $^


##
## 31XX : Template Dalibo
##

beamer_dalibo: $B/3101.tex $B/3102.pdf

$B/3101.tex: $T/presentation.md
	TEXMFHOME=beamer $P -st beamer --template=./beamer/template.latex -V theme:Dalibo $^

$B/3102.pdf: $T/presentation.md
	TEXMFHOME=beamer $P -st beamer --template=./beamer/template.latex -V theme:Dalibo $^



##
## 32XX : Known Bugs
##

beamer_bugs: $B/3201.tex $B/3203.tex

$B/3201.tex: $T/bug_102_beamer_hashtags.md
	TEXMFHOME=beamer $P -st beamer --template=./beamer/template.latex -V theme:Dalibo $^

$B/3202.pdf: $T/bug_102_beamer_hashtags.md
	TEXMFHOME=beamer $P -st beamer --template=./beamer/template.latex -V theme:Dalibo $^


$B/3203.tex: $T/bug_103_beamer_pourcent.md
	TEXMFHOME=beamer $P -st beamer --template=./beamer/template.latex -V theme:Dalibo $^

$B/3204.pdf: $T/bug_103_beamer_pourcent.md
	TEXMFHOME=beamer $P -st beamer --template=./beamer/template.latex -V theme:Dalibo $^


###############################################################################
##
## 4xxx = Reveal
##
###############################################################################

REVEAL_OPT=-t revealjs --standalone --self-contained -V revealjs-url:reveal.js/

reveal_test: buildir reveal_basic_test reveal_title_position_test reveal_title_transform_test reveal_special_syntax_test reveal_local_test

##
## 400x= basic
##

reveal_basic_test: buildir $B/4001.html $B/4002.html $B/4005.html $B/4006.html $B/4007.html $B/4008.html

$B/4001.html: $T/s1.md
	$P $(REVEAL_OPT) $^

$B/4002.html: $T/s1.md
	$P $(REVEAL_OPT) --template=reveal.js/pandoc/templates/dalibo.revealjs $^

$B/4005.html: $T/reveal.config.md $T/s1.md
	$P $(REVEAL_OPT) --template=reveal.js/pandoc/templates/dalibo.revealjs $^

$B/4006.html: $T/bug_45_reveal_ascenceurs_code.md
	$P $(REVEAL_OPT) --template=reveal.js/pandoc/templates/dalibo.revealjs $^

$B/4007.html: $T/bug_52_reveal_ascenceurs_code_puces.md
	$P $(REVEAL_OPT) --template=reveal.js/pandoc/templates/dalibo.revealjs $^

$B/4008.html: $T/dba4.md
	$P $(REVEAL_OPT) --template=reveal.js/pandoc/templates/dalibo.revealjs $^

##
## 401x = title-position
##

TITLE_POSITION=$P $(REVEAL_OPT) --template=reveal.js/pandoc/templates/dalibo.revealjs $T/reveal_title_position.config.md

reveal_title_position_test: buildir $B/4011.html $B/4012.html $B/4013.html $B/4014.html $B/4015.html

$B/4011.html: $T/s1.md
	$(TITLE_POSITION) $^

$B/4012.html: $T/reveal.config.md $T/s1.md
	$(TITLE_POSITION) $^

$B/4013.html: $T/reveal.config.md $T/s1.md
	$(TITLE_POSITION) -V transition=Slide $^

$B/4014.html: $T/reveal.config.md $T/s1.md
	$(TITLE_POSITION) -V transition=Convex $^

$B/4015.html: $T/reveal.config.md $T/s1.md
	$P $(REVEAL_OPT) --template=reveal.js/pandoc/templates/dalibo.revealjs -V center=false $^

##
## 402x = title-transform
##

reveal_title_transform_test: buildir $B/4021.html

$B/4021.html: $T/reveal_title_transform.config.md  $T/s1.md
	$P $(REVEAL_OPT) --template=reveal.js/pandoc/templates/dalibo.revealjs $^

##
## 410x = test syntaxes spécifiques
##

reveal_special_syntax_test: buildir $B/4101.html $B/4102.html

$B/4101.html: $T/test_inline_code.md
	$P $(REVEAL_OPT) --template=reveal.js/pandoc/templates/dalibo.revealjs $^

$B/4102.html: $T/test_footnotes.md
	$P $(REVEAL_OPT) --template=reveal.js/pandoc/templates/dalibo.revealjs $^


##
## 42xx= reveal_local (--self-contained off)
##

REVEAL_LOCAL_OPT=-t revealjs --standalone

reveal_local_test: reveal_local_basic reveal_local_notes_server reveal_local_revealjscom


##
## 400X : reveal_local basic
##

reveal_local_basic: $B/4201.html $B/4202.html

$B/4201.html: $T/s1.md
	cp -r reveal.js/ $B
	$P $(REVEAL_LOCAL_OPT) -V revealjs-url:reveal.js $^

$B/4202.html: $T/s1.md
	cp -r reveal.js/ $B
	$P $(REVEAL_LOCAL_OPT) -V revealjs-url:reveal.js --template=reveal.js/pandoc/templates/dalibo.revealjs $^


##
## 421X : reveal_local + notes_server (full offline)
##

reveal_local_notes_server: $B/4211.html $B/4212.html

$B/4211.html: $T/reveal_notes_server.md $T/s1.md
	cp -r reveal.js/ $B
	$P $(REVEAL_LOCAL_OPT) -V revealjs-url:reveal.js $^

$B/4212.html: $T/reveal_notes_server.md $T/s1.md
	cp -r reveal.js/ $B
	$P $(REVEAL_LOCAL_OPT) -V revealjs-url:reveal.js --template=reveal.js/pandoc/templates/dalibo.revealjs $^


##
## 422X : reveal_local + http://revealjs.com
##

reveal_local_revealjscom: $B/4221.html $B/4222.html

$B/4221.html: $T/s1.md
	$P $(REVEAL_LOCAL_OPT) -V revealjs-url:https://revealjs.com $^


$B/4222.html: $T/s1.md
	$P $(REVEAL_LOCAL_OPT) -V revealjs-url:https://revealjs.com --template=reveal.js/pandoc/templates/dalibo.revealjs $^


###############################################################################
#
# 5xxx = Filtres
#
###############################################################################

filters_test: buildir pandoc_latex_environment_test pandoc_latex_tip_test pandoc_latex_adminition

#
# 50xx = filtres faits maison
#

# pandoc needs an absolute path for local filters
INSTALL_FILTER_LOCAL_TEMP=cp -pr filters /tmp


#
# 500x = slides_latex
# OBSOLETE
#

#dalibo_slides_latex: buildir $B/500*

#$B/5001.pdf: $T/s1.md
# 	$(INSTALL_FILTER_LOCAL_TEMP)
#	$P  $(LATEX_OPT) --template tex/book1/template.tex --filter /tmp/filters/python/slides.latex.py $^


#
# 501x = level_up
# Ce filtre est OBSOLETE
#

dalibo_latex_levelup:

$B/5011.pdf: $T/dba4.md
	$(INSTALL_FILTER_LOCAL_TEMP)
	$P  $(LATEX_OPT) --template tex/book1/template.tex --filter /tmp/filters/python/levelup.latex.py $^

#
# 502x = checks
#
filter_syntax_checks: buildir $B/5021.json

$B/5021.json: $T/bug_52_reveal_ascenceurs_code_puces.md
	$(INSTALL_FILTER_LOCAL_TEMP)
	$P  --filter /tmp/filters/python/syntax_checks.py -t json -o $@ $^

##
## 503x = mustache
##
filter_mustache: buildir $B/5031.md

$B/5031.md: $T/mustache/rapport.md
	$P  --filter pandoc-mustache --to markdown -o $@ $^

#
# 51xx = filtre pandoc-latex-environment
#

PANDOC_LATEX_ENVIRONMENT=$P $(LATEX_OPT) --template tex/book1/template.tex --filter  pandoc-latex-environment $T/pandoc-latex-env.config_framed.md

pandoc_latex_environment_test: $B/5101.pdf $B/5102.pdf $B/5103.pdf $B/5104.pdf $B/5104.tex $B/5105.pdf

$B/5101.pdf:  $T/pandoc-latex-env.test_simple.md
	$(PANDOC_LATEX_ENVIRONMENT) $^

$B/5102.pdf: $T/s1.md
	$(PANDOC_LATEX_ENVIRONMENT) $^

$B/5103.pdf: $T/pandoc-latex-env.slides_et_tips.md
	$(PANDOC_LATEX_ENVIRONMENT) $^

#https://gitlab.dalibo.info/marketing/themes/issues/27
$B/5104.pdf: $T/links-as-footnote.config.md $T/bug_27_liens_bas_de_page.md
	$(PANDOC_LATEX_ENVIRONMENT) $^

$B/5104.tex: $T/links-as-footnote.config.md $T/bug_27_liens_bas_de_page.md
	$(PANDOC_LATEX_ENVIRONMENT) $^ -s

$B/5105.pdf:  $T/latex.config.md $T/bug_28_cadre_vide.md
	$(PANDOC_LATEX_ENVIRONMENT) $^

#
# 520x = filtre pandoc-latex-tip
#

pandoc_latex_tip_test: buildir $B/5201.pdf $B/5202.pdf

$B/5201.pdf:
	#$P  $(LATEX_OPT) $T/pandoc-latex-tip.config.md $T/pandoc-latex-tip.basic.md --filter pandoc-latex-tip

$B/5202.pdf:
	#$P  $(LATEX_OPT) $T/pandoc-latex-tip.config.md $T/pandoc-latex-env.config_framed.md $T/pandoc-latex-tip.combined.md --filter pandoc-latex-tip --filter pandoc-latex-environment  --template tex/book1/template.tex


#
# 521x = filtre pandoc-latex-admonition
#

pandoc_latex_adminition: buildir $B/5211.pdf $B/5212.pdf

$B/5211.pdf: $T/pandoc-latex-admonition.sample.md
	$P  $(LATEX_OPT) --filter pandoc-latex-admonition $^

$B/5212.pdf: $T/pandoc-latex-admonition.dalibo.md $T/dba4.md
	$P  $(LATEX_OPT) --template tex/book1/template.tex --filter pandoc-latex-admonition $^




###############################################################################
#
#  6xxx : Basic HTML output (for revealjs see 4xxx)
#
###############################################################################

html_test: buildir html_adaptive_test html_uikit html_gilles_test

#
# 61xx = Adaptive template
#

HTML_OPT= --standalone --self-contained --toc --toc-depth=2

html_adaptive_test: buildir $B/6101.html

$B/6101.html: $T/dba4.md
	$P $(HTML_OPT) --template html/adaptive/standalone.html --css html/adaptive/template.css $^


#
# 62xx = uikit
#

html_uikit: buildir $B/6201.html $B/6202.html $B/6203.html

$B/6201.html: $T/dba4.md
	$P $(HTML_OPT) --template html/uikit/dalibo.html $^

$B/6202.html: $T/slide.md
	$P --template html/uikit/dalibo.html $^

$B/6203.html: $T/socle-postgresql-DAT.v13.md
	$P $(HTML_OPT) --template html/uikit/socle.html $^

#
# 63xx = gilles
# https://gitlab.dalibo.info/formation/manuels/issues/8
#

html_gilles_test: buildir $B/6301.html

$B/6301.html: $T/dba4.md
	$P $(HTML_OPT) --template html/gilles/template.html $^


###############################################################################
##
##  7xxx : Post-Production
##
###############################################################################

postprod_test: buildir peecho_test

##
## 70xx = Fichiers tests
##

postprod_sample_test: $B/7001.pdf

$B/7001.pdf: $T/dba4.md
	$P  $(LATEX_OPT) -s --template tex/book1/template.tex $^


##
## 71xx = Peecho
##

peecho_test: buildir $B/7101.pdf

$B/7101.pdf: book1_precompil postprod_sample_test
	$Y ./tex/book1/postprod.peecho.py $B/7001.pdf -o $@ -p tex/book1/publications.pdf -b tex/book1/backcover.pdf


##
## 72xx : Thumbnails
##

thumbnails_test: buildir $B/7201.png

$B/7201.png: $B/7101.pdf
	$(PDFTOPPM) -r 600 $^ > $@


###############################################################################
##
##  8xxx : EPUB
##
###############################################################################

epub_test: buildir basic_epub_test ebook_test

#
# 80xx : Basic
#
basic_epub_test: buildir $B/8001.epub

$B/8001.epub: $T/dba4.md
	$P $^
#
# 81xx = pandoc-ebook-template
#
EPUB_OPT= --toc --toc-depth=2 --epub-metadata=epub/pandoc-ebook-template/metadata.xml --epub-cover-image=epub/pandoc-ebook-template/images/cover.jpg

ebook_test: buildir $B/8101.epub $B/8102.epub

$B/8101.epub: $T/dba4.md
	$P $(EPUB_OPT) $^

$B/8102.epub: $T/s1.md
	$P $(EPUB_OPT) $^



###############################################################################
#
#  9xxx : S5
#
###############################################################################

s5: buildir basic_s5 dalibo_s5

S5_OPT= -t s5 --standalone --self-contained

##
## 90xx : Basic
##
basic_s5: buildir $B/9001.html $B/9003.html

$B/9001.html: $T/dba4.md
	$P $(S5_OPT) $^

$B/9003.html: $T/slides_ldap2pg_bersace.md
	$P $(S5_OPT) $^

##
## 91XX : Theme dalibo
##
dalibo_s5: buildir $B/9101.html $B/9102.html $B/9103.html

$B/9101.html: $T/dba4.md
	$P $(S5_OPT) -V s5-url:./s5/dalibo_pg/ $^

$B/9102.html: $T/s1.md
	 $P $(S5_OPT) -V s5-url:./s5/dalibo_pg/ $^

$B/9103.html: $T/slides_ldap2pg_bersace.md
	$P $(S5_OPT) -V s5-url:./s5/dalibo_pg/ $^


###############################################################################
##
##  10xxx : Weasyprint
##
###############################################################################

weasy: buildir weasy_basic weasy_manuel

WEASY_OPT= -t html5 --pdf-engine=weasyprint


##
## 100xx : Basic
##
weasy_basic: buildir $B/10001.pdf

$B/10001.pdf: $T/dba4.md
	$P $(WEASY_OPT) $^

##
## 101xx : Manuel
##

weasy_manuel: buildir $B/10101.html $B/10102.pdf $B/10103.pdf

$B/10101.html: $T/dba4.md
	$P --template=html/weasy-manuel/template.html --toc $^

$B/10102.pdf: $B/10101.html
	$(WEASY) -s html/weasy-manuel/report.css $^	$@

$B/10103.pdf: $T/dba4.md
	$P --pdf-engine=weasyprint --pdf-engine-opt="--stylesheet /pandoc/html/weasy-manuel/report.css" --template=html/weasy-manuel/template.html --toc $^

