README: add some build instructions
[gtk-doc.git] / gtkdoc / mkhtml.py
blob73eda121e53dd49b3f53e4ad06831025de101d32
1 # -*- python; coding: utf-8 -*-
3 # gtk-doc - GTK DocBook documentation generator.
4 # Copyright (C) 1998 Owen Taylor
5 # 2001-2005 Damon Chaplin
6 # 2009-2017 Stefan Sauer
7 # 2017 Jussi Pakkanen
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 import logging
25 import os
26 import sys
27 import subprocess
28 import shutil
29 from glob import glob
31 from . import config
34 def run_xsltproc(options, args):
35 command = [config.xsltproc]
36 # we could do "$path_option $PWD " to avoid needing rewriting entities that
37 # are copied from the header into docs under xml
38 if os.environ.get("GTKDOC_PROFILE", '') == '':
39 if len(options.path):
40 command += ['--path', ':'.join(options.path)]
41 logging.info('running "%s"', ' '.join(command + args))
42 return subprocess.call(command + args)
43 else:
44 command += ['--profile']
45 if len(options.path):
46 command += ['--path', ':'.join(options.path)]
47 logging.info('running "%s"', ' '.join(command + args))
48 return subprocess.call(command + args, stderr=open('profile.txt', 'w'))
51 def get_dirs(uninstalled):
52 if uninstalled:
53 # this does not work from buiddir!=srcdir
54 gtkdocdir = os.path.split(sys.argv[0])[0]
55 if not os.path.exists(gtkdocdir + '/gtk-doc.xsl'):
56 # try 'srcdir' (set from makefiles) too
57 if os.path.exists(os.environ.get("ABS_TOP_SRCDIR", '') + '/gtk-doc.xsl'):
58 gtkdocdir = os.environ['ABS_TOP_SRCDIR']
59 styledir = gtkdocdir + '/style'
60 else:
61 gtkdocdir = os.path.join(config.datadir, 'gtk-doc/data')
62 styledir = gtkdocdir
63 return (gtkdocdir, styledir)
66 def run(options):
67 logging.info('options: %s', str(options.__dict__))
69 module = options.args[0]
70 document = options.args[1]
71 if options.verbose:
72 quiet = '0'
73 else:
74 quiet = '1'
75 remaining_args = options.args[2:]
77 (gtkdocdir, styledir) = get_dirs(options.uninstalled)
79 res = run_xsltproc(options, [
80 '--nonet',
81 '--xinclude',
82 '--stringparam',
83 'gtkdoc.bookname',
84 module,
85 '--stringparam',
86 'gtkdoc.version',
87 config.version,
88 '--stringparam',
89 'chunk.quietly',
90 quiet,
91 '--stringparam',
92 'chunker.output.quiet',
93 quiet] + remaining_args + [gtkdocdir + '/gtk-doc.xsl', document])
95 # profiling
96 if os.environ.get("GTKDOC_PROFILE", '') != '':
97 subprocess.check_call('cat profile.txt | gprof2dot.py -e 0.01 -n 0.01 | dot -Tpng -o profile.png', shell=True)
99 # copy navigation images and stylesheets to html directory ...
100 for f in glob(styledir + '/*.png') + glob(styledir + '/*.css'):
101 shutil.copy(f, '.')
103 with open('../html.stamp', 'w') as h:
104 h.write('timestamp')
105 return res