import os, sys
from waflib import Options, Logs

def build(bld):
    pass


def configure(conf):
    """Set the values needed by xmms_defs.h.in in the environment."""

    # Get default output plugin
    l = sorted(conf.env.XMMS_OUTPUT_PLUGINS)
    prio, outdefault = l[-1]
    if not conf.options.without_xmms2d and prio == -1:
        Logs.warn("No output plugin found, this is bad!")
    if conf.options.default_output_plugin:
        preferred = conf.options.default_output_plugin
        if preferred in [o[1] for o in l]:
            outdefault = preferred
        else:
            conf.fatal('The "%s" output plugin could not be found.' % (preferred))

    if Options.platform == 'darwin':
        uconf = 'Library/xmms2'
        ucache = 'Library/xmms2/logs'
    else:
        uconf = '.config/xmms2'
        ucache = '.cache/xmms2'

    sharedir = os.path.join(conf.env.DATADIR, 'xmms2')
    if Options.platform == 'win32':
        # The plugin path in Windows should be relative, not absolute
        conf.env.PLUGINDIR = 'Plugins/'
    else:
        conf.env.PLUGINDIR = os.path.join(conf.env.LIBDIR, 'xmms2')

    defs = dict(
        PKGLIBDIR = conf.env.PLUGINDIR,
        BINDIR = conf.env.BINDIR,
        SHAREDDIR = sharedir,
        SCRIPTDIR = os.path.join(sharedir, 'scripts', 'startup.d'),
        XMMS_VERSION = conf.env.VERSION,
        XMMS_OUTPUT_DEFAULT = outdefault,
        USERCONFDIR = uconf,
        USERCACHEDIR = ucache,
        SYSCONFDIR = '/etc/xmms2',
    )

    conf.env.update(defs)

    for i in defs:
        conf.define(i, defs[i])

    if not conf.options.without_xmms2d:
        Logs.pprint('Normal', "\nDefault output plugin: ", sep='')
        Logs.pprint('BLUE', outdefault)

    return True


def options(opt):
    pass
