A script in the Python language extracts the various output files from DocBook source files. Command line arguments are:
litsource file ...
Each DocBook-XML source file named on the command line is
read, and all the programlisting
elements with the correct role
attribute are assembled and written to the corresponding
files.
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.
First, in the part of your Makefile that defines variables, define a variable named
CODE_TARGET that contains the name
of the source file you want to build. If you are
building multiple source files, any of them will work.
For instance, if your source file is called run.c, the rule would look like this:
CODE_TARGET = run.c
Then, in the rules part of your Makefile, add this rule:
code: $(CODE_TARGET)
$(CODE_TARGET): $(TARGET).xml
litsource $<
Make sure that the last line starts with an actual tab character.
Here's one more refinement. Suppose you are generating
an executable script in some scripting language like Perl
or Python, and you need to make that script executable
under Unix. Assume further that the script's name is in
the $(CODE_TARGET) variable. You
can automate making the script executable with a rule
like this:
$(CODE_TARGET): $(TARGET).xml
litsource $<; \
chmod +x $(CODE_TARGET)