hpr2107 :: Makefiles for Everyday Use
I talk about how I use Makefiles in my Lilypond and HTML projects
Hosted by Jon Kulp on Tuesday, 2016-08-30 is flagged as Clean and is released under a CC-BY-SA license.
Automation, Makefiles, Scripting, Programming.
3.
The show is available on the Internet Archive at: https://archive.org/details/hpr2107
Listen in ogg,
spx,
or mp3 format. Play now:
Duration: 00:23:12
general.
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.
SHELL=/bin/bash
FILE=workbook_main
OUTDIR=out
WEBDIR=htmlout
VIEWER=evince
BROWSER=firefox
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
pdf:
$(LILYBOOK_PDF)
$(PDF)
$(INDEX)
$(PDF)
$(PREVIEW)
web:
$(LILYBOOK_HTML)
$(HTML)
cp -R $(WEBDIR)/$(FILE)/ ./
sleep 1
sh html-sed-fixes.sh
$(BROWSER) $(FILE)/index.html &
keep: pdf
cp $(OUTDIR)/$(FILE).pdf gratis.pdf
pdftk gratis.pdf update_info gratis.info output GratisAdParnassum.pdf
clean:
rm -rf $(OUTDIR)
web-clean:
rm -rf $(WEBDIR)
archive:
tar -cvvf free-counterpoint.tar \
--exclude=out/* \
--exclude=*.tar \
--exclude=*.zip \
--exclude=htmlout/* \
--exclude=workbook_main/* \
--exclude=*midi \
--exclude=*pdf \
--exclude=*~ \
../FreeCounterpoint/*
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.
SHELL=/bin/bash
piece = lorca
#CPU_CORES=`cat /proc/cpuinfo | grep -m1 "cpu cores" | sed s/".*: "//`
LILY_CMD = lilypond -ddelete-intermediate-files \
-dno-point-and-click #-djob-count=$(CPU_CORES)
notes = \
cancioncilla.ily \
cantada.ily \
caracola.ily \
china.ily \
lagarto.ily \
nana.ily \
paisaje.ily \
remanso.ily
.SUFFIXES: .ly .ily .pdf .midi
#CURDIR = $(shell pwd)
VPATH = $(CURDIR)/Scores $(CURDIR)/PDF $(CURDIR)/Parts $(CURDIR)/Notes
%.ly: %.ily
%.pdf %.midi: %.ly
$(LILY_CMD) $<
mv *.pdf PDF/
mv *.midi MIDI/
$(piece).pdf: $(notes)
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
.PHONY: score
score: $(piece).pdf
keep: score
cp $(CURDIR)/PDF/$(piece).pdf $(CURDIR)/CancionesParaNinos.pdf
archive:
tar -cvvf lorca.tar \
--exclude=*.pdf \
--exclude=*.midi \
--exclude=*~ \
../Canciones/*
tar -xvvf lorca.tar
zip -r lorca.zip Canciones
rm -R Canciones