#!/usr/bin/make
+#
# Mutopia Makefile Project
#
+# Rename this file to GNUmakefile, and issue `make help'
+#
+
#
-# For testing installed lily
+# Magic: find and include LilyPond's StepMake rules
#
-make-root=$(wildcard $(HOME)/tmp/test/usr/share/lilypond/make)
-#make-root=$(wildcard $(HOME)/usr/src/lilypond/make)
+# 0: try local tree
+# 1: follow LILYPOND_DATADIR
+# 2: try source tree in home
+# 3: try installed tree in $HOME
+# 4: try system installed tree
+# 5: try system installed tree
+#
+make-root=$(wildcard $(depth)/make)
+make-root?=$(wildcard $(LILYPOND_DATADIR)/make)
+make-root?=$(wildcard $(HOME)/usr/src/lilypond/make)
+make-root?=$(wildcard $(HOME)/usr/share/lilypond/make)
make-root?=$(wildcard /usr/share/lilypond/make)
-
+make-root?=$(wildcard /usr/local/share/lilypond/make)
+#make-root=<LilyPond's datadir>/make
ifneq ($(make-root),)
-
-depth=$(make-root)/..
-LOCALSTEPMAKE_TEMPLATES=mutopia
+### some versions apparently choke on $(message)
+### $(message running from $(make-root))
+depth:=$(make-root)/..
+LOCALSTEPMAKE_TEMPLATES=ly mutopia
include $(make-root)/stepmake.make
-
else
- burp
-#
-# Minimalistic standalone part. I'd very much like to install make/*
-# and stepmake/stepmake/* in /usr/share/lilypond, and junk this.
+$(error can't find LilyPond's stepmake installation)
+endif
#
-outdir=out
-PAPERSIZE=
-LY_FILES=$(wildcard *.ly)
-
-default:
- echo $(DEP_FILES)
- $(examples)
-clean:
- rm -f $(outdir)/* $(outdir)-letter/*
-
#
-# stepmake/stepmake/files.ly
+# Mutopia/user targets.
+# This needs some work.
#
-DEP_FILES:=$(wildcard $(outdir)/*.dep)
#
-# stepmake/stepmake/generic-targets.make
+# Name of mutopia project
#
-include $(outdir)/dummy.dep $(DEP_FILES)
-
-$(outdir)/dummy.dep:
- -mkdir -p $(outdir)
- touch $(outdir)/dummy.dep
+name=book
+tarball=$(name)
+parts=$(patsubst %.ly,%,$(wildcard *-part.ly))
#
-# make/mutopia-rules.make
+# scores for target local-WWW (duh)
#
-
-# don't junk intermediate .dvi files. They're easier to view than
-# .ps or .png
-.PRECIOUS: $(outdir)/%.dvi
+examples=
#
-# should we dist ps-to-pngs?
+# scores for target mutopia
#
-$(outdir)/%.png: $(outdir)/%.ps
- ps-to-pngs $<
- -mv $(name-stem)-page*.png $(outdir)/
- touch $@
-
-$(outdir)/%.dvi: %.ly
- ly2dvi --outdir=$(outdir) --dependencies $<
- -mv $(basename $<)*.midi $(outdir)
-
-$(outdir)-$(PAPERSIZE)/%.dvi: %.ly
- ly2dvi.py --outdir=$(outdir)-$(PAPERSIZE) --dependencies --papersize=$(PAPERSIZE) $<
- -mv $(basename $<)*.midi $(outdir)-$(PAPERSIZE)
+mutopia-examples=$(name) $(parts)
-
-#
-# stepmake/stepmake/tex-rules.make
+# moved to ly-rules.make
+# Timothy's booklet
#
-$(outdir)/%.tex: %.tex
- cp $< $@
-
-$(outdir)/%.dvi: $(outdir)/%.tex
- (cd $(outdir); tex \\nonstopmode \\input $(<F))
-
-$(outdir)/%.dvi: $(outdir)/%.latex
- (cd $(outdir)&& \
- latex \\nonstopmode \\input $(<F)&&\
- (bibtex $(basename $(<F)) || true) && \
- latex \\nonstopmode \\input $(<F)&&\
- (makeindex $(basename $(<F)) || true) && \
- latex \\nonstopmode \\input $(<F) )
-
-$(outdir)/%.ps: $(outdir)/%.dvi
- cd $(outdir) && dvips -ta4 -o $(@F) $(<F)
-
-$(outdir)-$(PAPERSIZE)/%.ps: $(outdir)-$(PAPERSIZE)/%.dvi
- cd $(outdir) && dvips -t$(PAPERSIZE) -o $(@F) $(<F)
-
+#$(outdir)/%-book.ps: $(outdir)/%.ps
+# psbook $< $<.tmp
+# pstops '2:0L@.7(21cm,0)+1L@.7(21cm,14.85cm)' $<.tmp $@
#
-# make/ly-rules.make
+# Catch-all target: type `make foo' to make out/foo.ps,
+# or make `foo-book' to make out/foo-book.ps
#
-
-$(outdir)/%.latex: %.doc
- rm -f $@
- lilypond-book --outdir=$(outdir) --dependencies $<
- chmod -w $@
-
-endif
-
+%: $(outdir)/%.ps
+ @echo Generated $< for target $@.
#
-# Mutopia/user targets.
-# This needs some work.
+# Also clean hand-compiled stuff in cwd
#
+local-clean: local-auto-gen-clean
+# Compose string from two parts: must not remove myself.
+auto-gen-tag=Generated
+auto-gen-tag+= automatically by
-parts=$(patsubst %.ly,%,$(wildcard *-part.ly))
-
-tarball=coriolan
-mutopia-examples=coriolan $(parts)
-mutopia-letter=$(mutopia-examples:%=out-letter/%.ps.gz)
-
-
-mutopia:
- $(MAKE) examples="$(mutopia-examples)" PAPERSIZE=letter local-WWW $(mutopia-letter)
+local-auto-gen-clean:
+ rm -f `grep -l '$(auto-gen-tag)' *`
+ rm -f *.dvi *.png