#! /usr/bin/env python
# WAF build script for midori
# This file is licensed under the terms of the expat license, see the file EXPAT.

import pproc as subprocess
import os
import Utils

blddir = '_build' # recognized by ack

for module in ('midori', 'katze'):
    try:
        if not os.access (blddir, os.F_OK):
            Utils.check_dir (blddir)
        if not os.access (blddir + '/docs', os.F_OK):
            Utils.check_dir (blddir + '/docs')
        if not os.access (blddir + '/docs/api', os.F_OK):
            Utils.check_dir (blddir + '/docs/api')
        subprocess.call (['gtkdoc-scan', '--module=' + module,
            '--source-dir=' + module, '--output-dir=' + blddir + '/docs/api/' + module,
            '--rebuild-sections', '--rebuild-types'])
        os.chdir (blddir + '/docs/api/' + module)
        subprocess.call (['gtkdoc-mktmpl', '--module=' + module,
            '--output-dir=.' + module])
        subprocess.call (['gtkdoc-mkdb', '--module=' + module,
            '--source-dir=.', '--output-dir=xml',
            '--source-suffixes=c,h', '--output-format=xml',
            '--default-includes=%s/%s.h' % (module, module),
            '--sgml-mode', '--main-sgml-file=%s.sgml' % module])
        if not os.access ('html', os.F_OK):
            Utils.check_dir ('html')
            os.chdir ('html')
        subprocess.call (['gtkdoc-mkhtml', module, '../%s.sgml' % module])
        Utils.pprint ('YELLOW', "Created documentation for %s." % module)
        os.chdir ('../../../../..')
    except Exception, msg:
        print msg
        Utils.pprint ('RED', "Failed to create documentation for %s." % module)
