#
#   Makefile Short Duets - Henry Purcell
#
# 2012-11-08 JvO, www dot chaosgeordend dot nl
#
# To Do
# =====
# add A4 and Letter format option
# lilypond -dno-point-and-click -dpaper-size=\"a4\" filename.ly
# lilypond -dno-point-and-click -dpaper-size=\"letter\" filename.ly
# http://lilypond.1069038.n5.nabble.com/page-formatting-and-lilypond-book-td26593.html
#

#
# Definitions...
#

OUTDIR=out

BOOK=Purcell_Duets_Book

TITLE=Purcell_Duets_Title

SCORES=01_Rondo \
02_Song_Tune \
03_Menuet_Fairest_Isle \
04_Boree \
05_Air \
06_Sarabande \
07_Hornpipe \
08_Rigaudon \
09_Menuet \
10_Menuet \
11_Country_Dance \
12_Air \
13_Scotch_Tune \
14_Hornpipe \
15_Song_Tune

#
# Make booklet...
#

all: $(BOOK)

$(BOOK): $(BOOK).tex
	cd $(OUTDIR);\
	pdflatex $(BOOK).tex;

$(BOOK).tex: Purcell_Duets_Title.lytex Purcell_Duets_Book.lytex
	lilypond-book --output=$(OUTDIR) --pdf $(BOOK).lytex

#
# Make book title pages only...
#

title: $(TITLE).tex
	cd $(OUTDIR);\
	pdflatex Purcell_Duets_Title_standalone.tex;

$(TITLE).tex: Purcell_Duets_Title_standalone.lytex
	lilypond-book --output=$(OUTDIR) --pdf Purcell_Duets_Title_standalone.lytex

#
# Make individual score PDF...
# http://stackoverflow.com/questions/4279383/dynamic-target-in-make
#

define MAKE_SCORE_RULE
$(1):
	lilypond $(1).ly
endef

$(foreach s, $(SCORES), \
	$(eval $(call MAKE_SCORE_RULE,$(s))) \
)

#
# Clean all pdf and intermediate files...
#

clean:
#	rm $(OUTDIR)/*.pdf;
	rm -R $(OUTDIR);
	
#
# Help info
#

help:
	@echo "usage: make <score-rule>"
	@echo "score-rule:"
	@echo "  all               Build the (twosided A4 PDF) booklet comprising all scores"
	@echo "  title             Build booklet title pages only"
	@echo "  <score>           Build a A4 PDF score"
	@echo "score:"
	@for score in $(SCORES); do echo "  $$score"; done

#
# End
#