Next / Previous / Contents / Shipman's homepage

19.2. make-lit: A Makefile for literate programming

This example Makefile implements the literate programming technique described in Lightweight literate programming. The basic idea is that rather than trying to embed documentation in your program, instead you embed the source code for your program within a DocBook document.

You will need to install , which is described (in literate form, of course) in : A source extractor for lightweight literate programming.

The beginning section is similar to Section 19.1, “make-basic: A basic Makefile.

# Makefile for DocBook projects: Literate version
#   This file is extracted automatically from:
#     /
# Definitions
# BASENAME:        The base file name of the DocBook file.
# SOURCE:          The .xml file containing the document.
# WEB_DIR:         Subdirectory where .html files live.
#   To move all .html files to subdirectory web/, set this
#   variable to "web/" and use an .htaccess file to redirect
#   browsers there.
# WEB_TARGET:      Top-level generated HTML page name.
# FO_TARGET:       Intermediate file for generated PDF.
# PDF_TARGET:      Generated PDF file name.
# INDEX_BASE:      Base name for index of section id values.
# INDEX_FO:        Intermediate file for section index.
# INDEX_PDF:       Section index PDF file name.
# ZDP_XSL:         Where the local customization layer lives.
# HTML_TRANSFORM:  XSLT to build the HTML rendering.
# PDF_TRANSFORM:   XSLT to build the PDF rendering.
# XSLT_HTML_OPT passes options to xsltproc to build the HTML form.
#     To push chunking down to subsections:
#        --stringparam chunk.section.depth 2 
#     To move the first subsection to its own chunk:
#        --stringparam chunk.first.sections 1
#     To show subsubsections in the table of contents:
#        --stringparam toc.section.depth 3
# XSLT_FO_OPT:  Options for hardcopy.
#     To show subsubsections in the table of contents:
#        --stringparam toc.section.depth 3
# XEP_OPT:  Options to xep
#     To suppress most output:
#        -quiet
BASENAME        =  your-project-name-here
SOURCE          =  $(BASENAME).xml
WEB_DIR         =  
WEB_TARGET      =  $(WEB_DIR)index.html
FO_TARGET       =  $(BASENAME).fo
PDF_TARGET      =  $(BASENAME).pdf
INDEX_BASE      =  toc
INDEX_FO        =  $(INDEX_BASE).fo
INDEX_PDF       =  $(INDEX_BASE).pdf
ZDP_XSL         =  /u/shipman/www//
HTML_TRANSFORM  =  $(ZDP_XSL)zdp_html.xsl
FO_TRANSFORM    =  $(ZDP_XSL)zdp_fo.xsl
XSLT_HTML_OPT   =  --stringparam chunk.section.depth 2 \
                   --stringparam chunk.first.sections 1
XSLT_FO_OPT     =  
XEP_OPT         =  -quiet

In the EXECUTABLES define, enumerate any files that are to be extracted and then made executable (we are assuming a Unix-based system here). Additionally, if there are any files that are to be extracted but do not need to be made executable, enumerate them in the MODULES define.

# EXECUTABLES:  Files to be extracted and then made executable.
# MODULES:      Files to be extracted from the DocBook source.
MODULES         =

The next section is the same as in make-basic.

# Add the suffixes that we are interested in
# .fo       XSL-FO output
# .html     HTML web pages                 
# .pdf      Page Description Format (Abode)
# .xml      Input files in DocBook XML format
.SUFFIXES: .fo .html .pdf .xml

# Default suffix rules
	xsltproc -o $@ $(XSLT_HTML_OPT) $(HTML_TRANSFORM) $<
	xsltproc -o $@ $(XSLT_FO_OPT) $(FO_TRANSFORM) $<

	xep $(XEP_OPT) $< $@ 

In the target section, we define a new target named code. The rule for this target runs . We also define a target named index that runs to build a toc.pdf file enumerating all the section ID values.

# Targets
all: web pdf index code

web: $(WEB_TARGET)

	xsltproc -o $@ $(XSLT_HTML_OPT) $(HTML_TRANSFORM) $<

pdf: $(PDF_TARGET)


index: $(INDEX_PDF)


	rm -f $(INDEX_FO); \
	docbook5index $(SOURCE)


# If there are any executables, change this rule to:
#       litdocbook5 $<; \
#       chmod +x $(EXECUTABLES)
	litdocbook5 $<

	rm -f *.fo *.html *.pdf $(CODE_TARGETS)