<p>In this episode I talk about how I use Makefiles to ease the process of building complicated projects in <a href="https://lilypond.org/">Lilypond</a> and HTML. You can use Makefiles to run any kinds of commands you want. It does not have to be building actual computer programs. In my case I use them to build musical scores and web pages. Keep in mind I'm not an expert on this, and I'm hoping I will make enough mistakes that it will prompt a series of follow-up episodes by people who actually know what they're talking about.</p>

<p>Here's an example. This is the Makefile for my Counterpoint workbook <a href="https://jonathankulp.org/gratis.html"><em>Gratis ad Parnassum</em></a>, which I wrote in 2009. Written in a combination of <a href="https://www.latex-project.org/"><span style="font-family: 'CMU Serif', cmr10, LMRoman10-Regular, 'Nimbus Roman No9 L', 'Times New Roman', Times, serif;">L<span style="text-transform: uppercase; font-size: 70%; margin-left: -0.36em; vertical-align: 0.3em; line-height: 0; margin-right: -0.15em;">a</span>T<span style="text-transform: uppercase; margin-left: -0.1667em; vertical-align: -0.5ex; line-height: 0; margin-right: -0.125em;">e</span>X</span></a>
 and Lilypond, this requires very complicated and long commands to build the workbook, and I found that the only way to do this project in a sane manner was to create a Makefile that would keep track of changes in the files and only rebuild when necessary. It also meant that the only commands I would have to type were very simple, because the long command line options were all stored in the Makefile.</p>

<pre>SHELL=/bin/bash<br/>FILE=workbook_main<br/>OUTDIR=out<br/>WEBDIR=htmlout<br/>VIEWER=evince<br/>BROWSER=firefox<br/>LILYBOOK_PDF=lilypond-book&nbsp;--output=$(OUTDIR)&nbsp;--pdf&nbsp;$(FILE).lytex<br/>LILYBOOK_HTML=lilypond-book&nbsp;--output=$(WEBDIR)&nbsp;$(FILE).lytex<br/>PDF=cd&nbsp;$(OUTDIR)&nbsp;&amp;&amp;&nbsp;pdflatex&nbsp;$(FILE)<br/>HTML=cd&nbsp;$(WEBDIR)&nbsp;&amp;&amp;&nbsp;latex2html&nbsp;$(FILE)<br/>INDEX=cd&nbsp;$(OUTDIR)&nbsp;&amp;&amp;&nbsp;makeindex&nbsp;$(FILE)<br/>PREVIEW=$(VIEWER)&nbsp;$(OUTDIR)/$(FILE).pdf&nbsp;&gt;&amp;&nbsp;/dev/null<br/><br/>all:&nbsp;pdf&nbsp;web<br/><br/>pdf:<br/>	$(LILYBOOK_PDF)<br/>	$(PDF)<br/>	$(INDEX)<br/>	$(PDF)<br/>	$(PREVIEW)<br/><br/>web:<br/>	$(LILYBOOK_HTML)<br/>	$(HTML)<br/>	cp&nbsp;-R&nbsp;$(WEBDIR)/$(FILE)/&nbsp;./<br/>	sleep&nbsp;1<br/>	sh&nbsp;html-sed-fixes.sh<br/>	$(BROWSER)&nbsp;$(FILE)/index.html&nbsp;&amp;<br/><br/>keep:&nbsp;pdf<br/>	cp&nbsp;$(OUTDIR)/$(FILE).pdf&nbsp;gratis.pdf<br/>	pdftk&nbsp;gratis.pdf&nbsp;update_info&nbsp;gratis.info&nbsp;output&nbsp;GratisAdParnassum.pdf<br/><br/>clean:<br/>	rm&nbsp;-rf&nbsp;$(OUTDIR)<br/><br/>web-clean:<br/>	rm&nbsp;-rf&nbsp;$(WEBDIR)<br/><br/>archive:<br/>	tar&nbsp;-cvvf&nbsp;free-counterpoint.tar&nbsp;\<br/>	--exclude=out/*&nbsp;\<br/>	--exclude=*.tar&nbsp;\<br/>	--exclude=*.zip&nbsp;\<br/>	--exclude=htmlout/*&nbsp;\<br/>	--exclude=workbook_main/*&nbsp;\<br/>	--exclude=*midi&nbsp;\<br/>	--exclude=*pdf&nbsp;\<br/>	--exclude=*~&nbsp;\<br/>	../FreeCounterpoint/*<br/>	tar&nbsp;-xvvf&nbsp;free-counterpoint.tar<br/>	zip&nbsp;-r&nbsp;free-counterpoint.zip&nbsp;FreeCounterpoint<br/>	rm&nbsp;-R&nbsp;FreeCounterpoint<br/></pre>

<p>And here is the Makefile for my song collection called <a href="https://jonathankulp.org/lorca.html"><em>Canciones para niños</em></a>, using Lilypond source files.</p>

<pre>SHELL=/bin/bash<br/>piece&nbsp;=&nbsp;lorca<br/>#CPU_CORES=`cat&nbsp;/proc/cpuinfo&nbsp;|&nbsp;grep&nbsp;-m1&nbsp;&quot;cpu&nbsp;cores&quot;&nbsp;|&nbsp;sed&nbsp;s/&quot;.*:&nbsp;&quot;//`<br/>LILY_CMD&nbsp;=&nbsp;lilypond&nbsp;-ddelete-intermediate-files&nbsp;\<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-dno-point-and-click&nbsp;#-djob-count=$(CPU_CORES)<br/><br/>notes&nbsp;=&nbsp;\<br/>cancioncilla.ily&nbsp;\<br/>cantada.ily&nbsp;\<br/>caracola.ily&nbsp;\<br/>china.ily&nbsp;\<br/>lagarto.ily&nbsp;\<br/>nana.ily&nbsp;\<br/>paisaje.ily&nbsp;\<br/>remanso.ily<br/><br/>.SUFFIXES:&nbsp;.ly&nbsp;.ily&nbsp;.pdf&nbsp;.midi<br/><br/>#CURDIR&nbsp;=&nbsp;$(shell&nbsp;pwd)<br/>VPATH&nbsp;=&nbsp;$(CURDIR)/Scores&nbsp;$(CURDIR)/PDF&nbsp;$(CURDIR)/Parts&nbsp;$(CURDIR)/Notes<br/><br/>%.ly:&nbsp;%.ily<br/>%.pdf&nbsp;%.midi:&nbsp;&nbsp;%.ly&nbsp;<br/>	$(LILY_CMD)&nbsp;$&lt;<br/>	mv&nbsp;*.pdf&nbsp;PDF/<br/>	mv&nbsp;*.midi&nbsp;MIDI/<br/><br/>$(piece).pdf:&nbsp;$(notes)&nbsp;<br/><br/>cancioncilla.pdf:&nbsp;cancioncilla.ly&nbsp;cancioncilla.ily<br/>cantada.pdf:&nbsp;cantada.ly&nbsp;cantada.ily<br/>caracola.pdf:&nbsp;caracola.ly&nbsp;caracola.ily<br/>china.pdf:&nbsp;china.ly&nbsp;china.ily<br/>lagarto.pdf:&nbsp;lagarto.ly&nbsp;lagarto.ily<br/>nana.pdf:&nbsp;nana.ly&nbsp;nana.ily<br/>paisaje.pdf:&nbsp;paisaje.ly&nbsp;paisaje.ily<br/>remanso.pdf:&nbsp;remanso.ly&nbsp;remanso.ily<br/><br/>.PHONY:&nbsp;score<br/>score:&nbsp;$(piece).pdf<br/><br/>keep:&nbsp;score<br/>	cp&nbsp;$(CURDIR)/PDF/$(piece).pdf&nbsp;$(CURDIR)/CancionesParaNinos.pdf<br/><br/>archive:<br/>	tar&nbsp;-cvvf&nbsp;lorca.tar&nbsp;\<br/>	--exclude=*.pdf&nbsp;\<br/>	--exclude=*.midi&nbsp;\<br/>	--exclude=*~&nbsp;\<br/>	../Canciones/*<br/>	tar&nbsp;-xvvf&nbsp;lorca.tar<br/>	zip&nbsp;-r&nbsp;lorca.zip&nbsp;Canciones<br/>	rm&nbsp;-R&nbsp;Canciones<br/></pre>

<h2>Links</h2>

<ul>
	<li><a href="https://lilypond.org/">Lilypond</a></li>
	<li><a href="https://www.gnu.org/software/make/">GNU Make</a></li>
	<li><a href="https://www.latex-project.org/"><span style="font-family: 'CMU Serif', cmr10, LMRoman10-Regular, 'Nimbus Roman No9 L', 'Times New Roman', Times, serif;">L<span style="text-transform: uppercase; font-size: 70%; margin-left: -0.36em; vertical-align: 0.3em; line-height: 0; margin-right: -0.15em;">a</span>T<span style="text-transform: uppercase; margin-left: -0.1667em; vertical-align: -0.5ex; line-height: 0; margin-right: -0.125em;">e</span>X</span></a></li>
	<li><a href="https://jonathankulp.org/gratis.html">My Counterpoint projects</a></li>
</ul>
