next up previous contents
Next: About this document ... Up: Literate Programming: noweb Previous: Emacs   Contents

Makefile

I build noweb documents using the following type of Makefile. One thing is that it automatically generates all roots that look like file names (I exclude roots with spaces in case I have defined chunks but don't use them. This is the purpose of the sed script lines.)

Another thing that I do is to compile the latex file with a different file name (instead of compiling target.tex to target.dvi I compile target.aux.tex to target.aux.dvi) so that I can keep viewing the dvi file except for a split second when I copy the ne version over the old version.

# Change TARGETNAME to the name of your source: $(TARGETNAME).nw

TARGETNAME=target

NOWEAVE=noweave
NOTANGLE=notangle
NOROOTS=noroots
WEAVEFLAGS= -x -delay


$(TARGETNAME): $TARGETNAME).d $(TARGETNAME).dvi
$(TARGETNAME)source: $TARGETNAME).d
$(TARGETNAME)doc: $TARGETNAME).dvi

include target.d

# This generates a list of dependencies for each noweb file.  It only
# includes files which have no spaces and which end with some sort of
# extension.
%.d : %.nw
        echo "$*.all : \\" > $@
        $(SHELL) -ec '$(NOROOTS) $< \
                      | sed -n "s|<<\([^ ]*\.[^ ]*\)>>|\1\\\|gp" >> $@'
        echo >> $@
        $(SHELL) -ec '$(NOROOTS) $< \
                      | sed -n "s|<<\([^ ]*\.[^ ]*\)>>|\1 : $<|gp" >> $@'
        echo "$@: $<" >> $@

# Here is one source file
%.m :: qcd.nw
        $(NOTANGLE) $(TANGLEFLAGS) -R$@ $< > $@

# Implicit Rules
%.tex : %.nw
        $(NOWEAVE) $(WEAVEFLAGS) $< > $@

# We generate a spurious file so that we don't corrupt the .dvi file
# for a long period of time.  First we cancel the implicit rule.
%.dvi : %.tex

%.aux.dvi : %.aux.tex
        rm -f *.aux
        nice -n 19 latex $<
        nice -n 19 latex $< 
        rm -f $<

%.dvi : %.aux.dvi
        mv $< $@


%.aux.tex : %.tex
        cp $< $@


Michael McNeil Forbes 2006-05-26