I talk about how I use Makefiles in my Lilypond and HTML projects
Hosted by Jon Kulp on 2016-08-30 is flagged as Clean and is released under a CC-BY-SA license.
Tags: Automation, Makefiles, Scripting, Programming.
Listen in ogg,
mp3 format. | Comments (3)
In this episode I talk about how I use Makefiles to ease the process of building complicated projects in Lilypond 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.
Here's an example. This is the Makefile for my Counterpoint workbook Gratis ad Parnassum, which I wrote in 2009. Written in a combination of LaTeX
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.
LILYBOOK_PDF=lilypond-book --output=$(OUTDIR) --pdf $(FILE).lytex
LILYBOOK_HTML=lilypond-book --output=$(WEBDIR) $(FILE).lytex
PDF=cd $(OUTDIR) && pdflatex $(FILE)
HTML=cd $(WEBDIR) && latex2html $(FILE)
INDEX=cd $(OUTDIR) && makeindex $(FILE)
PREVIEW=$(VIEWER) $(OUTDIR)/$(FILE).pdf >& /dev/null
all: pdf web
cp -R $(WEBDIR)/$(FILE)/ ./
$(BROWSER) $(FILE)/index.html &
cp $(OUTDIR)/$(FILE).pdf gratis.pdf
pdftk gratis.pdf update_info gratis.info output GratisAdParnassum.pdf
rm -rf $(OUTDIR)
rm -rf $(WEBDIR)
tar -cvvf free-counterpoint.tar \
tar -xvvf free-counterpoint.tar
zip -r free-counterpoint.zip FreeCounterpoint
rm -R FreeCounterpoint
And here is the Makefile for my song collection called Canciones para niños, using Lilypond source files.
piece = lorca
#CPU_CORES=`cat /proc/cpuinfo | grep -m1 "cpu cores" | sed s/".*: "//`
LILY_CMD = lilypond -ddelete-intermediate-files \
notes = \
.SUFFIXES: .ly .ily .pdf .midi
#CURDIR = $(shell pwd)
VPATH = $(CURDIR)/Scores $(CURDIR)/PDF $(CURDIR)/Parts $(CURDIR)/Notes
%.pdf %.midi: %.ly
mv *.pdf PDF/
mv *.midi MIDI/
cancioncilla.pdf: cancioncilla.ly cancioncilla.ily
cantada.pdf: cantada.ly cantada.ily
caracola.pdf: caracola.ly caracola.ily
china.pdf: china.ly china.ily
lagarto.pdf: lagarto.ly lagarto.ily
nana.pdf: nana.ly nana.ily
paisaje.pdf: paisaje.ly paisaje.ily
remanso.pdf: remanso.ly remanso.ily
cp $(CURDIR)/PDF/$(piece).pdf $(CURDIR)/CancionesParaNinos.pdf
tar -cvvf lorca.tar \
tar -xvvf lorca.tar
zip -r lorca.zip Canciones
rm -R Canciones
Comment #1 posted on 2016-08-31T11:29:26Z by Fweeb
Did a quick `info make` and scanned through it a bit. The .PHONY target is kind of a safety net. See, normally, targets in a makefile share the name of the exact file being made. However, in the case of something like `clean`, there's usually no file with that name being produced, just a series of deletions. *However*, if there is a file named `clean` in the same directory as your makefile, that can cause some confusion for the make command. So, by using `.PHONY: clean`, you're telling make to disregard a file named clean if it happens to see it.
I'm less sure about .SUFFIXES. The section on that in the manual was long and starts with the phrase "Old-Fashioned"... so perhaps it's something that's not entirely necessary for your makefile at this point.
Comment #2 posted on 2016-09-01T11:17:34Z by Jonathan Kulp
Thanks for the info. It's funny I guess I could read info pages myself but normally I just look at other people's Makefiles for examples and never really understand what they're doing. Once it all works I'm happy. Bit of trial and more error...
Comment #3 posted on 2016-09-01T14:00:14Z by Dave Morriss
"Copy and paste programming"
We have probably all been there. I believe the practice is called "copy and paste programming" nowadays. I have certainly written Makefiles by this method. I have tried to learn more about the subject by reading the GNU make manual but it's hard going!
I'd say it's certainly a subject for a series of HPR shows.
<< First, < Previous, Next >, Latest >>
Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.
Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).