# Makefile

# Version: 2001/03/05

# This file is useful when editing musical scores with Lilypond.

# Copyright (C) 2001 by Bernd Warken <bwarken@mayn.de>

# This is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 or (at your option) any later
# version.

# This software is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License.  If
# not, you can find it in the internet at <http://www.gnu.org/copyleft/>
# or write to the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA, 02111-1307, USA.

### formatters
LILY = lilypond
LYDVI = ly2dvi
TEX = tex

### converters

# direct postscript output of lilypond is very buggy, use dvips instead
DVIPS = dvips -f

# EPS image converter, ps2eps is better
PSEPSI = ps2epsi

# pseps is available at the CTAN support directory at TeX Dante mirrors
# e.g. ftp.dante.org
PSEPS = ps2eps

### viewers
XDVI = xdvi
GHOSTVIEW = ghostview
KGHOSTVIEW = kghostview

########################################################################

.PHONY:	help
help :
	@echo "To compile a lilypond file named "\`filename.ly\'" call"
	@echo "  "\`"make filename.tex"\'" to produce TeX output,"
	@echo "  "\`"make filename.dvi"\'" for dvi output,"
	@echo "  "\`"make filename.ps"\'" for Postscript output,"
	@echo "  "\`"make filename.eps"\'" for EPS image,"
	@echo "  "\`"make filename.epsi"\'" for EPSI image,"
	@echo "  "\'"make filename.all"\'" for ps and dvi output,"
	@echo "  "\'"make filename.xdvi"\'" to display with xdvi,"
	@echo "  "\'"make filename.gv"\'" to display with ghostscript,"
	@echo "  "\'"make filename.kgv"\'" to use kghostscript,"
	@echo "To compile all lilypond files call"
	@echo -n "  "\`"make dvi"\'","
	@echo " "\`"make ps"\'", or "\`"make all"\'"."

%.tex :	%.ly
	$(LILY) -f tex $<
	@echo

%.dvi : %.ly
	$(LYDVI) $<

%.ps :	%.dvi
	${DVIPS} <$< >$@

# excellent for generating EPS images
%.eps: %.ps
	$(PSEPS) $< >$@

# common EPS/EPSI converter, but unreliable results
%.epsi:	%.ps
	$(PSEPSI) $< $@

.PHONY: %.all
%.all :
	make $*.dvi
	${DVIPS} <$*.dvi >$@

.PHONY: %.xdvi
%.xdvi: %.dvi
	$(VIEWDVI) $<

.PHONY: %.gv
%.gv :	%.ps
	$(GHOSTVIEW) $<

.PHONY: %.kgv
%.kgv :	%.ps
	$(KGHOSTVIEW) $<

.PHONY : dvi
dvi :
	for i in *.ly; do make `basename $$i .ly`.dvi ; done

.PHONY : ps
ps :	dvi
	for i in *.dvi; do make `basename $$i .dvi`.ps ; done

.PHONY : all
all :	dvi ps

.PHONY : clean
clean :
	$(RM) *~ *.dvi *.ps *.eps *.epsi *.log *.tex *.midi
