3 # Support both Python 2 and 3
4 from __future__ import print_function
6 import os, sys, argparse, subprocess
10 xsltproc = '@XSLTPROC@'
14 parser = argparse.ArgumentParser(description='gtkdoc-mkpdf version %s - generate documentation in pdf format' % version)
16 parser.add_argument('--verbose', default=False, action='store_true',
17 help='Print extra output while processing.')
18 parser.add_argument('--path', default=[], action='append',
19 help='Extra source directories.')
20 parser.add_argument('--imgdir', default=[], action='append',
21 help='Extra image directories.')
22 parser.add_argument('--version', default=False, action='store_true',
23 help='Print the version of this program')
24 parser.add_argument('--uninstalled', action='store_true', default=False,
26 parser.add_argument('args', nargs=2,
27 help='MODULE DRIVER_FILE')
29 def cleanexit(exitval):
31 fname = module + '.fo'
32 if os.path.exists(fname):
36 options = parser.parse_args()
42 module=options.args[0]
43 document=options.args[1]
45 if options.uninstalled:
46 # this does not work from buiddir!=srcdir
48 # MAKE_SCRDIR=$(abs_srcdir) MAKE_BUILDDIR=$(abs_builddir) gtkdoc-mkpdf ...
49 gtkdocdir=os.path.split(sys.argv[0])[0]
50 logging.debug("uninstalled, gtkdocdir=" + gtkdocdir)
52 # the first vars are needed to resolve datadir
54 datarootdir="@datarootdir@".replace('${prefix}', prefix)
55 datadir="@datadir@".replace('${datarootdir}', datarootdir)
56 gtkdocdir=os.path.join(datadir, 'gtk-doc/data')
58 # We need to use a wrapper because there's no other way to conditionally pass
59 # a `--path $searchpath` argument with proper quoting for the path
60 def run_xsltproc(args):
61 global options, xsltproc
62 # we could do "--path $PWD "
63 # to avoid needing rewriting entities that are copied from the header
65 if len(options.path) == 0:
66 cmd = [xsltproc] + args
68 cmd = [xsltproc, '--path'] + options.searchpath + args
69 pc = subprocess.Popen(cmd, stderr=subprocess.PIPE)
70 (o, stde) = pc.communicate()
71 open('profile.txt', 'wb').write(stde)
72 if pc.returncode != 0:
73 cleanexit(pc.returncode)
76 # extra options to consider
78 # -V is useful for debugging
79 # -T db2latex : different style
80 # -d : keep transient files (for debugging)
81 # -P abc.def=$quiet : once the stylesheets have a quiet mode
82 # xsltproc is already called with --xinclude
83 # does not work: --xslt-opts "--path $searchpath --nonet $@"
84 dblatex_options=['-o', module + '.pdf']
85 for i in options.imgdir:
86 dblatex_options += ['-I', i]
87 dblatex_options.append(document)
88 if not options.verbose:
89 pc = subprocess.Popen([dblatex, '--help'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
90 (stdo, stde) = pc.communicate()
91 if b'--quiet' in stdo or b'--quiet' in stde:
92 dblatex_options= ['--quiet'] + dblatex_options
93 dbcmd = [dblatex] + dblatex_options
94 pc = subprocess.Popen(dbcmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
95 (stde, _) = pc.communicate()
96 for line in stde.split('\n'):
99 if 'programlisting or screen' in line:
101 # This happens when dblatex has no support for some special chars
102 if 'Missing character' in line:
110 run_xsltproc(['--nonet',
122 'chunker.output.quiet',
128 gtkdocdir + '/gtk-doc-fo.xsl',
130 # fop dies too easily :(
131 # @FOP@ $module.fo $module.pdf
133 print("dblatex or fop must be installed to use gtkdoc-mkpdf.")
136 open('pdf.stamp', 'w').write('timestamp')