1#!/usr/bin/env python3
2#
3# Copyright (C) 2017 Carlos Garcia Campos <carlosgc@gnome.org>
4# Copyright (C) 2019 Albert Astals Cid <aacid@kde.org>
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20import argparse
21import logging
22import os
23from gtkdoc import PkgConfigGTKDoc
24
25def configure_logging(verbose):
26    level = logging.DEBUG if verbose else logging.INFO
27    logger = logging.getLogger('gtkdoc')
28    logger.setLevel(level)
29    handler = logging.StreamHandler()
30    handler.setLevel(level)
31    logger.addHandler(handler)
32    if level == logging.DEBUG:
33        handler.setFormatter(logging.Formatter('[%(asctime)s]  %(message)s'))
34    else:
35        handler.setFormatter(logging.Formatter('%(message)s'))
36
37
38parser = argparse.ArgumentParser(description='Make poppler GLib API documentation.')
39parser.add_argument('-v', '--verbose', action='store_true', default = False,
40                    help='Whether or not to run in verbose mode.')
41parser.add_argument('--skip-html', action='store_true',
42                    help='Whether or not to skip HTML generation, which can be slow.')
43parser.add_argument('-s', '--src-dir', action='store', default='.', dest='src_dir',
44                    help='The source directory')
45parser.add_argument('-b', '--build-dir', action='store', default='build', dest='build_dir',
46                    help='The build directory')
47args = parser.parse_args()
48configure_logging(args.verbose)
49
50pkgconfig_file = os.path.join(args.build_dir, 'poppler-glib.pc')
51pkgconfig_path = os.environ.get("PKG_CONFIG_PATH")
52os.environ['PKG_CONFIG_PATH'] = args.build_dir
53if pkgconfig_path:
54    os.environ['PKG_CONFIG_PATH'] += ':' + pkgconfig_path
55
56gtkdoc = PkgConfigGTKDoc(pkgconfig_file, {
57    'library_path': os.path.join(args.build_dir, 'glib'),
58    'module_name': 'poppler',
59    'doc_dir': os.path.join(args.src_dir, 'glib', 'reference'),
60    'output_dir': os.path.join(args.build_dir, 'glib', 'reference'),
61    'main_sgml_file': 'poppler-docs.sgml',
62    'source_dirs': [os.path.join(args.src_dir, 'glib'), os.path.join(args.build_dir, 'glib')],
63    'cflags': '-I%s' % os.path.join(args.src_dir, 'glib'),
64    'ignored_files': ['poppler-private.h', 'poppler-input-stream.h', 'poppler-cached-file-loader.h', 'demo']
65})
66
67gtkdoc.generate(not args.skip_html)
68