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

import os
import Common

def configure(conf):
    conf.env['ENABLE_GCONF'] = bool(conf.check_pkg(
            'gconf-2.0 >= 2.12 pygobject-2.0',
            destvar='GCONF', mandatory=False))

def codegen(bld, module):
    cmd = bld.create_obj('command-output')
    cmd.command = 'pygtk-codegen-2.0'
    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 bld.env()['ENABLE_GCONF']:
        codegen(bld, 'gconf')
        pyext = bld.create_obj('cc', 'plugin', 'pyext')
        pyext.source = 'gconfmodule.c gconf.c gconf-fixes.c gconf-types.c'
        pyext.target = 'gconf'
        pyext.uselib = 'GCONF'
        pyext.env.append_value('CPPPATH', '../gconf') # work around possible WAF bug
        pyext.install_var = 'PYTHONDIR'
        pyext.install_subdir = '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')
