all: freenet-slides-nup.pdf freenet-slides.pdf freenet-slides-nup-thumb.png freenet-slides-thumb.png

freenet-slides-nup-thumb.png: the-long-game-nup.pdf
	gs -dNOPAUSE -dBATCH -sDEVICE=png16m -r145 -dDownScaleFactor=6 -dFirstPage=1 -dLastPage=1 -sOutputFile="$@" "$<"
freenet-slides-thumb.png: freenet-slides.pdf
	gs -dNOPAUSE -dBATCH -sDEVICE=png16m -r300 -dDownScaleFactor=4 -dFirstPage=1 -dLastPage=1 -sOutputFile="$@" "$<"


freenet-slides-nup.pdf : the-long-game-nup.pdf
	cp "$<" "$@"
freenet-slides.pdf : the-long-game.pdf
	cp "$<" "$@"

the-long-game-nup.pdf : the-long-game.pdf
	pdfjam --nup 3x6 --no-landscape "$<" -o "$@"

the-long-game.pdf : the-long-game.tex ref.bib
	pdflatex -interaction=nonstopmode -halt-on-error -shell-escape $(basename $<) || (rm *.aux ; pdflatex -interaction=nonstopmode -halt-on-error -shell-escape $(basename $<)) || true
	bibtex $(basename $<) || true # do not fail without citations
	pdflatex -interaction=nonstopmode -halt-on-error -shell-escape $(basename $<)
	bibtex $(basename $<) || true # do not fail without citations
	pdflatex -interaction=nonstopmode -halt-on-error -shell-escape $(basename $<)
	pdflatex -interaction=nonstopmode -halt-on-error -shell-escape $(basename $<)
	pdflatex -interaction=nonstopmode -halt-on-error -shell-escape $(basename $<)

# need to set HOME to grab the project-specific emacs config, but set ditaa command here to access the original HOME for guix libraries.
the-long-game.tex: the-long-game.org
	HOME=$(shell echo $$(dirname $$(realpath "$<"))) emacs -eval "(setq org-babel-ditaa-java-cmd \"LD_LIBRARY_PATH=$${LD_LIBRARY_PATH}:$$HOME/.guix-profile/lib/ java\" plantuml-executable-path \"plantuml\" org-plantuml-jar-path \"$${GUIX_ENVIRONMENT=/home/$(whoami)/.guix-profile}/share/java/plantuml.jar\" org-plantuml-exec-mode 'plantuml)" -find-file $< -e org-beamer-export-to-latex -e kill-emacs
