Next / Previous / Contents / Shipman's homepage

3.1. Suggested Makefile rules

If you are using the Unix make utility to build your document and source files, you can add lines to your Makefile to take care of building the program source files.

The exact rules depend on whether your literate programs are executable or not. We'll assume that both executable and non-executable programs are produced, and that the variable BASENAME is the name of your DocBook file minus its “.xml” extension. below.

First, define three variables like this:

MODULES        =  m1 m2 ...
EXECUTABLES    =  e1 e2 ...
CODE_TARGETS   =  $(EXECUTABLES) $(MODULES)

where m1, m2, and so forth are the names of non-executable files, and e1, e2, and so on are the names of your executable files.

Then, in the rules part of your Makefile, change the first (default) target to read like this:

all: web pdf code

Add these rules:

code: $(CODE_TARGETS)

$(CODE_TARGETS): $(BASENAME).xml
        litlxml $<; \
        chmod +x $(EXECUTABLES)

If no executables are produced, change the latter rule to:

$(CODE_TARGETS): $(BASENAME).xml
        litlxml $<

A model Makefile is included in Writing documentation with DocBook-XML 4.3.