.PHONY: all 
tex_deps = build variables.tt library/*/*/*.tt song_choices.csv song_template.tt propers/*.tt purpose_processing.tt
docker = podman
all: leadsheet_collection.pdf print_a3.pdf print_a4.pdf clean_intermediate
%.pdf: %.tex
	cd build && \
	lualatex --shell-escape $<
print_a3.pdf: songsheet_a3part.pdf
	cd build && \
	pdftk A=$< B=$< shuffle A B output -  | pdfjam -o a4.pdf --nup 1x2 --paper a4paper --clip true /dev/stdin && \
	pdfbook2 --paper a3paper -s -n -o 0 -i 0 -t 0 -b 0 a4.pdf && \
	mv a4-book.pdf print_a3.pdf && \
	rm a4.pdf
print_a4.pdf: songsheet_a4part.pdf
	cd build && \
	pdftk A=$< B=$< shuffle A B output - | pdfjam -o $@ --nup 1x2 --paper a4paper /dev/stdin;
songsheet_a3part.pdf: songsheet_a5.pdf
	cd build && \
	pdftk $< cat ~3-4 output $@
#	cp $< $@
songsheet_a4part.pdf: songsheet_a5.pdf
#	cp $< $@
# Uncomment this if songsheet.pdf has 12 pages or less, and you want to use an a4 sheet inside a folded a3 sheet
	cd build && \
	pdftk $< cat 3-4 output $@
songsheet_a5.pdf: songsheet.pdf
	cd build && \
	pdfjam -o $@ --nup 2x1 --paper a5paper --landscape $<
songsheet.tex: songsheet.tt $(tex_deps) header.tt head.tt footer.tt
	tpage $< > build/$@
musician_scores.tex: musician_scores.tt $(tex_deps)
	tpage $< > build/$@
leadsheet_collection.tex: musician_scores.tt $(tex_deps)
	tpage --define parts=band $< > build/$@
chornoten.tex: musician_scores.tt $(tex_deps)
	tpage --define parts=choir $< > build/$@
clean_intermediate:
	cd build && \
	rm songsheet_a3part.pdf songsheet_a4part.pdf songsheet_a5.pdf
build:
	mkdir build
clean:
	rm -r build
init:
	git submodule update --init --recursive
build_docker_image:
	$(docker) build -t songsheet_generator .
pull_docker:
	$(docker) pull gitea.leopold.fajtak.at/leopold/songsheet_generator:latest
build_in_docker:
	$(docker) run -v `pwd`:/data songsheet_generator make

