build_dir = build
config_dir = config
docker = podman
library_dir = library
propers_dir = propers
template_dir = templates
# get dependencies from song_choices.csv and variables.tt
dynamic_deps = $(shell cat $(config_dir)/song_choices.csv | \
	       awk '!/#/' | \
	       awk 'NR>1' | \
	       awk -F '|' '{print $$4}' | \
	       sed 's/ //' | \
	       awk '{print "$(library_dir)/" $$0 "/*"}') \
	       $(shell cat $(config_dir)/variables.tt | \
	       grep '^\s*proper =' | awk -F '=' '{print $$2}' | \
	       sed 's/ //g' | \
	       sed "s/'//g" | \
	       awk '{print "$(propers_dir)/" $$0 ".tt"}')
tex_deps = $(template_dir)/*.tt $(config_dir)/qr_codes.csv $(config_dir)/variables.tt $(dynamic_deps)
.PHONY: all 
all: leadsheet_collection.pdf choir_scores.pdf print_a3.pdf clean_intermediate #print_a4.pdf
%.pdf: build
	$(MAKE) -C $(build_dir) $@
songsheet.tex: $(template_dir)/songsheet.tt $(tex_deps) $(template_dir)/header.tt $(template_dir)/head.tt $(template_dir)/footer.tt
%.tex: build
	$(MAKE) -C $(template_dir) $@
clean_intermediate:
	$(MAKE) -C $(build_dir) clean_intermediate
build: build-Makefile
	mkdir -p $(build_dir) && \
	cp build-Makefile $(build_dir)/Makefile && \
	cp -r library/gregorio_scores $(build_dir)
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

