python:=python3

# Start LibreOffice Calc in server-mode
%.ods/localc:
	export PYSCRIPT_LOG_STDOUT=1
	export PYSCRIPT_LOG_LEVEL=DEBUG
	localc --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" $*.ods

# Put a macro into an Open Document Spreadsheet
%.ods/pack_macro: %.py
	$(python) pack_macro.py $*.py $*.ods

# Generate ballots for a Majority Judgment
ballots:
	$(python) -c "import jugements; jugements.MakeBallots()"
	pdfnup --a4paper --nup 2x2 --outfile bulletins.pdf bulletins/*.pdf

# Generate results of a Majority Judgment
results:
	$(python) -c "import jugements; jugements.MakeResults()"

# Join PDFs
sécu-sauvage.pdf: présentation.pdf résultats.pdf
	pdfjoin --outfile $@ --paper a4paper --rotateoversize false $^

# Watermark PDF
%-prototype.pdf: %.pdf
	pdftk $*.pdf background prototype.pdf output $*-prototype.pdf