import os
import Params
import Common

def build(bld):
    obj = bld.create_obj('cc', 'perlext', 'perlext')
    obj.target = 'XMMSClient'
    obj.includes = '. ../../../include ../../../includepriv'
    obj.source = """
                 perl_xmmsclient.c
                 XMMSClient.xs
                 XMMSClientPlaylist.xs
                 XMMSClientCollection.xs
                 XMMSClientResult.xs
                 XMMSClientResultPropDict.xs
                 XMMSClientResultPropDictTie.xs
                 """.split()
    obj.uselib_local = 'xmmsclient'
    obj.install_var = "INSTALLDIR_PERL_AUTO"

    Common.install_files('INSTALLDIR_PERL_LIB', '', 'pm/XMMSClient.pm')
    Common.install_files('INSTALLDIR_PERL_LIB', 'XMMSClient', 'pm/XMMSClient/Sync.pm')
    Common.install_files('INSTALLDIR_PERL_LIB', 'XMMSClient', 'pm/XMMSClient/Glib.pm')
    Common.install_files('INSTALLDIR_PERL_LIB', 'XMMSClient', 'pm/XMMSClient/Collection.pm')

def configure(conf):
    conf.check_tool('perl')

    if not conf.check_perl_version((5,7,3)):
        return False

    conf.check_perl_ext_devel()

    if not os.path.commonprefix([conf.env['ARCHDIR_PERL'], conf.env['PREFIX']]).startswith(conf.env['PREFIX']):
        Params.warning('default perl libdir is not under PREFIX. specify path '
                + 'manually using --with-perl-archdir if you don\'t want the '
                + 'perl bindings to be installed to ' + conf.env['ARCHDIR_PERL'])

    conf.env['INSTALLDIR_PERL_AUTO'] = os.path.join(conf.env['ARCHDIR_PERL'], "auto", "Audio", "XMMSClient")
    conf.env['INSTALLDIR_PERL_LIB'] = os.path.join(conf.env['ARCHDIR_PERL'], "Audio")

    return True

def set_options(opt):
    opt.tool_options('perl')
