# -*- python -*-
# encoding: utf-8

import os
import Common

def configure(conf):
    conf.env.append_value('MODULES_AVAILABLE', 'gconf')
    if 'gconf' in conf.env['ENABLE_MODULES'] or 'all' in conf.env['ENABLE_MODULES']:
        if conf.check_pkg('gconf-2.0 >= 2.12 pygobject-2.0',
                          destvar='GCONF', mandatory=False):
            conf.env.append_value('MODULES_TO_BUILD', 'gconf')


def codegen(bld, module):
    cmd = bld.create_obj('command-output')
    cmd.command = bld.env()['CODEGEN']
    cmd.command_is_external = True
    cmd.prio = 5
    cmd.argv = [
        '--py_ssize_t-clean',
        '--load-types', cmd.input_file('gconf-arg-types.py'),
        '--prefix', 'py'+module,
        '--override', cmd.input_file("%s.override" % module),
        cmd.input_file("%s.defs" % module),
        ]
    cmd.stdout = '%s.c' % module
    return cmd


def build(bld):
    
    if 'gconf' in bld.env()['MODULES_TO_BUILD']:
        codegen(bld, 'gconf')
        pyext = bld.create_pyext()
        pyext.source = 'gconfmodule.c gconf.c gconf-fixes.c gconf-types.c'
        pyext.target = 'gconf'
        pyext.uselib = 'GCONF'
        pyext.includes = '.'
        pyext.inst_var = 'PYTHONDIR'
        pyext.inst_dir = 'gtk-2.0'

        Common.install_files('DATADIR', os.path.join('pygtk', '2.0', 'defs'),
                             ['gconf.defs'])

        Common.install_files('DATADIR', os.path.join('pygtk', '2.0', 'argtypes'),
                             'gconf-arg-types.py')
