Converted mkpdf, mkman and mkhtml to Python.
[gtk-doc.git] / gtkdoc-mkhtml.in
blob2a4c4202342742d26ea24989877f31e70eec410f
1 #!@PYTHON@
3 # Support both Python 2 and 3
4 from __future__ import print_function
6 import os, sys, argparse, subprocess, shutil
7 from glob import glob
9 version = '@VERSION@'
10 xsltproc = '@XSLTPROC@'
12 parser = argparse.ArgumentParser(description='gtkdoc-mkhtml version %s - generate documentation in html format' % version)
14 parser.add_argument('--verbose', default=False, action='store_true',
15                     help='Print extra output while processing')
16 parser.add_argument('--path', default=[], action='append',
17                     help='Extra source directories')
18 parser.add_argument('--version', default=False, action='store_true',
19                     help='Print the version of this program')
20 parser.add_argument('args', nargs='*',
21                     help='MODULE DRIVER_FILE')
22 parser.add_argument('--uninstalled', action='store_true', default=False,
23                     help='???')
25 options = parser.parse_args()
26 if options.version:
27     print(version)
28     sys.exit(0)
30 if len(options.args) < 2:
31     sys.exit('Too few arguments')
33 module=options.args[0]
34 document=options.args[1]
35 if options.verbose:
36     quiet = '0'
37 else:
38     quiet = '1'
39 remaining_args = options.args[2:]
41 if options.uninstalled:
42     # this does not work from buiddir!=srcdir
43     gtkdocdir = os.path.split(sys.argv[0])[0]
44     # traditional Bourne shells may not support -e here, use -f
45     if not os.path.exists(gtkdocdir + '/gtk-doc.xsl'):
46         # try to src dir (set from makefiles) too
47         if os.path.exists(os.path.environ.get("ABS_TOP_SRCDIR", '') + '/gtk-doc.xsl'):
48             gtkdocdir=os.path.environ['ABS_TOP_SRCDIR']
49     styledir=gtkdocdir + '/style'
50     #echo "uninstalled, gtkdocdir=$gtkdocdir, cwd=$PWD"
51 else:
52     # the first two are needed to resolve datadir
53     prefix='@prefix@'
54     datarootdir='@datarootdir@'
55     gtkdocdir='@datadir@/gtk-doc/data'
56     styledir=gtkdocdir
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     # we could do "$path_option $PWD "
62     # to avoid needing rewriting entities that are copied from the header
63     # into docs under xml
64     if os.environ.get("GTKDOC_PROFILE", '') == '':
65         if len(options.path):
66             subprocess.check_call([xsltproc] + args)
67         else:
68             subprocess.check_call([xsltproc, '--path'] + options.path + args)
69     else:
70         if len(options.path) == 0:
71             subprocess.check_call([xsltproc, '--profile'] + args, stderr=open('profile.txt', 'w'))
72         else:
73             subprocess.check_call([xsltproc ,'--profile', '--path'] + options.path + args, stderr=open('profile.txt', 'w'))
75 run_xsltproc(['--nonet',
76               '--xinclude',
77               '--stringparam',
78               'gtkdoc.bookname',
79               module,
80               '--stringparam',
81               'gtkdoc.version',
82               version,
83               '--stringparam',
84               'chunk.quietly',
85               quiet,
86               '--stringparam',
87               'chunker.output.quiet',
88               quiet] + remaining_args + \
89              [gtkdocdir + '/gtk-doc.xsl',
90               document])
92 # profiling
93 if os.environ.get("GTKDOC_PROFILE", '') != '':
94    subprocess.check_call('cat profile.txt | gprof2dot.py -e 0.01 -n 0.01 | dot -Tpng -o profile.png', shell=True)
96 # copy navigation images and stylesheets to html directory ...
97 for f in glob(styledir + '/*.png') + glob(styledir + '/*.css'):
98      shutil.copy(f, '.')
100 open('../html.stamp', 'w').write('timestamp')