# encoding: utf-8
#
# WAF build scripts for XMMS2
# Copyright (C) 2006-2007 XMMS2 Team
#

import sys,os
import Common

source = """config.c
            mediainfo.c
            sqlite.c
            medialib.c
            object.c
            error.c
            output.c
            playlist.c
            collection.c
            collquery.c
            collserial.c
            ipc.c
            log.c
            plugin.c
            magic.c
            ringbuf.c
            xform.c
            streamtype.c
            converter_plugin.c
            ringbuf_xform.c
            outputplugin.c
            strfunc.c
            bindata.c
            sample.genpy
            utils.c""".split()

def build(bld):
    if sys.platform == 'win32':
        lib = bld.create_obj('cc', 'shlib')
        lib.uselib_local = 'xmmsipc xmmssocket xmmsutils xmmstypes'
    else:
        lib = bld.create_obj('cc', 'staticlib')
    lib.target = 'xmms2core'
    lib.includes = '. ../include ../includepriv'
    lib.install_in = 0
    lib.uselib = 'glib2 gmodule2 gthread2 sqlite3 statfs socket'
    lib.source = source

    env = bld.env_of_name("default")
    lib.source.append("statfs_%s.c" % env["statfs_os"])

    prog = bld.create_obj('cc', 'program')
    prog.target = 'xmms2d'
    prog.includes = '. ../include ../includepriv'
    prog.source = ["main.c"]
    if sys.platform == 'win32':
        prog.source.append("signal_dummy.c")
    else:
        prog.source.append("signal_unix.c")
    prog.uselib_local = 'xmms2core xmmsipc xmmssocket xmmsutils xmmstypes'
    prog.uselib = 'glib2 gmodule2 gthread2 sqlite3 statfs socket'

    obj = bld.create_obj('man')
    obj.files = ['xmms2d.1']

def configure(conf):
    conf.check_tool('python-generator', tooldir=os.path.abspath('waftools'))
    conf.check_pkg2('gmodule-2.0', '2.6.0', uselib='gmodule2')
    conf.check_pkg2('gthread-2.0', '2.6.0', uselib='gthread2')
    conf.check_pkg2('sqlite3', '0.0', uselib='sqlite3')

    # Check for the sin function in the math lib
    test = conf.create(enumerator='function')
    test.function = 'sin'
    test.headers = ['math.h']
    test.libs = ['m']
    test.mandatory = 1
    test.run()

    # Detect the type of stat call used

    # This function is ploped down here for now because the change has
    # been submitted to upstream, and will hopefully get rolled back
    # into the waf dist.
    def check_header(header_name, mandatory=0):
        test = conf.create(enumerator='header')
        test.name = header_name
        test.mandatory = mandatory
        return test.run()

    if check_header('sys/vfs.h'):
        if sys.platform == 'sunos5':
            conf.env['statfs_os'] = 'solaris'
        else:
            conf.env['statfs_os'] = 'linux'
    elif check_header('sys/param.h'):
        conf.env['statfs_os'] = 'bsd'
    else:
        conf.env['statfs_os'] = 'dummy'

    # Add Darwin stuff
    if sys.platform == 'darwin':
        conf.env['LINKFLAGS'] += ['-framework', 'CoreFoundation']

    conf.env.append_value('XMMS_PKGCONF_FILES', ('xmms2-plugin', ''))

def set_options(opt):
    pass
