File: wscript

package info (click to toggle)
xmms2 0.8%2Bdfsg-12
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,388 kB
  • ctags: 16,835
  • sloc: ansic: 63,792; python: 12,801; cpp: 5,718; xml: 1,479; perl: 338; ruby: 243; makefile: 82; sh: 59; asm: 7
file content (526 lines) | stat: -rw-r--r-- 19,500 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# encoding: utf-8
#
# WAF build scripts for XMMS2
# Copyright (C) 2006-2001 XMMS2 Team
#

import sys
if sys.version_info < (2,4):
    raise RuntimeError("Python 2.4 or newer is required")

import os

# Waf removes the current dir from the python path. We readd it to import waf
# tools stuff.
sys.path.insert(0, os.getcwd())

from waflib import Configure, Options, Utils, Errors, Logs

from waftools.compiler_flags import compiler_flags
from waftools import gittools

BASEVERSION="0.8 DrO_o"
APPNAME='xmms2'

top = '.'
out = '_build_'

_waf_hexversion = 0x01060700
_waf_mismatch_msg = """
You are building xmms2 with a waf version that is different from the one
distributed with xmms2. This is not supported by the XMMS2 Team. Before
reporting any errors with this setup, please rebuild XMMS2 using './waf
configure build install'
"""

####
## Patch undefine so that HAVE_* envs are still defined after
## we write the configuration header file.
####
@Configure.conf
def undefine(self, key):
    ban = key + '='
    lst = [x for x in self.env['DEFINES'] if not x.startswith(ban)]
    self.env['DEFINES'] = lst
    self.env.append_unique('define_key', key)

####
## Initialization
####
def init(ctx):
    import gc
    gc.disable()

    from waflib import Context
    if _waf_hexversion != Context.HEXVERSION:
        Logs.warn(_waf_mismatch_msg)

subdirs = """
src/lib/xmmstypes
src/lib/xmmssocket
src/lib/xmmsipc
src/lib/xmmsutils
src/lib/xmmsvisualization
src/clients/lib/xmmsclient
src/clients/lib/xmmsclient-glib
src/include
src/includepriv
""".split()

optional_subdirs = """
src/clients/nycli
src/clients/launcher
src/clients/et
src/clients/mdns
src/clients/medialib-updater
src/clients/vistest
src/clients/lib/xmmsclient-ecore
src/clients/lib/xmmsclient++
src/clients/lib/xmmsclient++-glib
src/clients/lib/xmmsclient-cf
src/clients/lib/python
src/clients/lib/perl
src/clients/lib/ruby
tests
pixmaps
""".split()

def is_plugin(x):
    return os.path.exists(os.path.join("src/plugins", x, "wscript"))

all_optionals = set(os.path.basename(o) for o in optional_subdirs)
all_plugins = set(p for p in os.listdir("src/plugins") if is_plugin(p))

def get_newest(*dirs):
    m = 0
    for d in dirs:
        m = max([m]+[os.stat(os.path.join(sd, "wscript")).st_mtime for sd in d])
    return m

####
## Build
####
def build(bld):
    if bld.env.BUILD_XMMS2D:
        subdirs.append("src/xmms")

    plugins = bld.env.XMMS_PLUGINS_ENABLED
    plugindirs = ["src/plugins/%s" % plugin for plugin in plugins]
    optionaldirs = bld.env.XMMS_OPTIONAL_BUILD

    newest = get_newest(subdirs, plugindirs, optionaldirs)
    if bld.env.NEWEST_WSCRIPT_SUBDIR and newest > bld.env.NEWEST_WSCRIPT_SUBDIR:
        bld.fatal("You need to run waf configure")
        raise SystemExit()

    bld.add_subdirs(subdirs)
    bld.add_subdirs(plugindirs)
    bld.add_subdirs(optionaldirs)

    for name, lib in bld.env.XMMS_PKGCONF_FILES:
        bld(features = 'subst',
            source = 'xmms2.pc.in',
            target = name + '.pc',
            install_path = '${PKGCONFIGDIR}',
            NAME = name,
            LIB = lib+' ', # Avoid error in waf 1.6 if lib == ''
            PREFIX = bld.env.PREFIX,
            BINDIR = bld.env.BINDIR,
            LIBDIR = bld.env.LIBDIR,
            INCLUDEDIR = os.path.join(bld.env.INCLUDEDIR, "xmms2"),
            VERSION = bld.env.VERSION
            )

    bld.install_files('${SHAREDDIR}', "silence-cellule_snippet.ogg")

    bld.add_post_fun(shutdown)

####
## Configuration
####
def _configure_optionals(conf):
    """Process the optional xmms2 subprojects"""
    def _check_exist(optionals, msg):
        unknown_optionals = optionals.difference(all_optionals)
        if unknown_optionals:
            conf.fatal(msg%dict(unknown_optionals=', '.join(unknown_optionals)))
            raise SystemExit()
        return optionals

    conf.env.XMMS_OPTIONAL_BUILD = []

    if conf.options.enable_optionals is not None:
        selected_optionals = _check_exist(set(conf.options.enable_optionals),
                "The following optional(s) were requested, "
                "but don't exist: %(unknown_optionals)s")
        optionals_must_work = True
    elif conf.options.disable_optionals is not None:
        disabled_optionals = _check_exist(set(conf.options.disable_optionals),
                "The following optional(s) were disabled, "
                "but don't exist: %(unknown_optionals)s")
        selected_optionals = all_optionals.difference(disabled_optionals)
        optionals_must_work = False
    else:
        selected_optionals = all_optionals
        optionals_must_work = False

    failed_optionals = set()
    succeeded_optionals = set()

    for o in selected_optionals:
        x = [x for x in optional_subdirs if os.path.basename(x) == o][0]
        try:
            conf.sub_config(x)
            conf.env.append_value('XMMS_OPTIONAL_BUILD', x)
            succeeded_optionals.add(o)
        except Errors.ConfigurationError:
            failed_optionals.add(o)

    if optionals_must_work and failed_optionals:
        conf.fatal("The following required optional(s) failed to configure: %s"
                % ', '.join(failed_optionals))
        raise SystemExit(1)

    disabled_optionals = set(all_optionals)
    disabled_optionals.difference_update(succeeded_optionals)

    return succeeded_optionals, disabled_optionals

def _configure_plugins(conf):
    """Process ll xmms2d plugins"""
    def _check_exist(plugins, msg):
        unknown_plugins = plugins.difference(all_plugins)
        if unknown_plugins:
            conf.fatal(msg%dict(unknown_plugins=', '.join(unknown_plugins)))
            raise SystemExit(1)
        return plugins

    conf.env.XMMS_PLUGINS_ENABLED = []

    if conf.options.enable_plugins is not None:
        selected_plugins = _check_exist(set(conf.options.enable_plugins),
                "The following plugin(s) were requested, "
                "but don't exist: %(unknown_plugins)s")
        disabled_plugins = all_plugins.difference(selected_plugins)
        plugins_must_work = True
    elif conf.options.disable_plugins is not None:
        disabled_plugins = _check_exist(set(conf.options.disable_plugins),
                "The following plugin(s) were disabled, "
                "but don't exist: %(unknown_plugins)s")
        selected_plugins = all_plugins.difference(disabled_plugins)
        plugins_must_work = False
    elif conf.options.without_xmms2d:
        disabled_plugins = all_plugins
        selected_plugins = set()
        plugins_must_work = False
    else:
        selected_plugins = all_plugins
        disabled_plugins = set()
        plugins_must_work = False

    for plugin in selected_plugins:
        try:
            conf.sub_config("src/plugins/%s" % plugin)
            if (not conf.env.XMMS_PLUGINS_ENABLED or
                    (len(conf.env.XMMS_PLUGINS_ENABLED) > 0 and
                        conf.env.XMMS_PLUGINS_ENABLED[-1] != plugin)):
                disabled_plugins.add(plugin)
        except Errors.ConfigurationError:
            disabled_plugins.add(plugin)

    if plugins_must_work:
        broken_plugins = selected_plugins.intersection(disabled_plugins)
        if broken_plugins:
            conf.fatal("The following required plugin(s) failed to configure: "
                    "%s" % ', '.join(broken_plugins))
            raise SystemExit(1)

    return conf.env.XMMS_PLUGINS_ENABLED, disabled_plugins

def _output_summary(enabled_plugins, disabled_plugins,
                    enabled_optionals, disabled_optionals,
                    output_plugins):
    enabled_plugins = [x for x in enabled_plugins if x not in output_plugins]
    Logs.pprint('Normal', "\n")

    Logs.pprint('Normal', "Optional configuration:\n"
                          "=======================")
    Logs.pprint('Normal', "Enabled: ", sep='')
    Logs.pprint('BLUE', ', '.join(sorted(enabled_optionals)))
    Logs.pprint('Normal', "Disabled: ", sep='')
    Logs.pprint('BLUE', ', '.join(sorted(disabled_optionals)))

    Logs.pprint('Normal', "Plugins configuration:\n"
                          "======================")
    Logs.pprint('Normal', 'Output: ', sep='')
    Logs.pprint('BLUE', ', '.join(sorted(output_plugins)))
    Logs.pprint('Normal', 'XForm/Other: ', sep='')
    Logs.pprint('BLUE', ', '.join(sorted(enabled_plugins)))
    Logs.pprint('Normal', 'Disabled: ', sep='')
    Logs.pprint('BLUE', ', '.join(sorted(disabled_plugins)))

def configure(conf):
    has_platform_support = os.name in ('nt', 'posix')
    conf.msg('Platform code for %s' % os.name, has_platform_support)
    if not has_platform_support:
        conf.fatal('xmms2 only has platform support for Windows and POSIX operating systems.')
        raise SystemExit(1)

    if 'PKG_CONFIG_PREFIX' in os.environ:
        prefix = os.environ['PKG_CONFIG_PREFIX']
        if not os.path.isabs(prefix):
            pretix = os.path.abspath(prefix)
        conf.env.PKG_CONFIG_DEFINES = dict(prefix=prefix)

    conf.env.BUILD_XMMS2D = False
    if not conf.options.without_xmms2d:
        conf.env.BUILD_XMMS2D = True
        subdirs.insert(0, "src/xmms")

    conf.check_tool('gnu_dirs')
    conf.check_tool('man', tooldir=os.path.abspath('waftools'))
    conf.check_tool('misc')
    conf.check_tool('gcc')
    conf.check_tool('g++')

    if conf.options.target_platform:
        Options.platform = conf.options.target_platform

    nam,changed = gittools.get_info()
    conf.msg("git commit id", nam)
    if conf.options.customversion:
        conf.env.VERSION = "%s (%s + %s)" % (BASEVERSION, nam, conf.options.customversion)
    else:
        dirty = changed and "-dirty" or ""
        conf.msg("uncommited changed", changed and "yes" or "no")
        conf.env.VERSION = "%s (git commit: %s%s)" % (BASEVERSION, nam, dirty)

    if conf.options.with_profiling:
        conf.env.with_profiling = True
        conf.env.append_unique('CFLAGS', ['--coverage'])
        conf.env.append_unique('LINKFLAGS', ['--coverage'])

    flags = compiler_flags(conf)

    flags.enable_c_warning('all')
    flags.enable_c_warning('empty-body')
    flags.enable_c_warning('format=2')
    flags.enable_c_warning('format-nonliteral')
    flags.enable_c_warning('format-security')
    flags.enable_c_warning('ignored-qualifiers')
    flags.enable_c_warning('missing-prototypes')
    flags.enable_c_warning('strict-prototypes')
    flags.enable_c_warning('type-limits')
    flags.enable_c_warning('write-strings')

    flags.disable_c_warning('format-extra-args')
    flags.disable_c_warning('format-zero-length')

    flags.enable_feature('diagnostics-show-option')

    flags.enable_c_error('implicit-function-declaration')

    conf.env.XMMS_PKGCONF_FILES = []
    conf.env.XMMS_OUTPUT_PLUGINS = [(-1, "NONE")]

    if conf.options.pkgconfigdir:
        conf.env.PKGCONFIGDIR = conf.options.pkgconfigdir
        Logs.pprint('Normal', conf.env.PKGCONFIGDIR) #XXX What is it ?
    else:
        conf.env.PKGCONFIGDIR = os.path.join(conf.env.LIBDIR, 'pkgconfig')

    if conf.options.config_prefix:
        for d in conf.options.config_prefix:
            if not os.path.isabs(d):
                d = os.path.abspath(d)
            conf.env.prepend_value('LIBPATH', os.path.join(d, 'lib'))
            conf.env.prepend_value('CPPPATH', os.path.join(d, 'include'))

    if Options.platform != 'win32':
        conf.env.append_unique('CFLAGS_cstlib', ['-fPIC', '-DPIC'])
        conf.env.append_unique('CPPFLAGS_cxxshlib', ['-fPIC', '-DPIC'])
    else:
        # As we have to change target platform after the tools
        # have been loaded there are a few variables that needs
        # to be initiated if building for win32.

        # Make sure we don't have -fPIC and/or -DPIC in our CFLAGS
        conf.env.CFLAGS_cshlib = []
        conf.env.CXXFLAGS_cxxshlib = []

        # Setup various prefixes
        conf.env.cshlib_PATTERN = 'lib%s.dll'
        conf.env.cprogram_PATTERN = '%s.exe'

    if Options.platform == 'darwin':
        conf.env.append_value('LINKFLAGS', '-multiply_defined_suppress')
        conf.env.explicit_install_name = True
    else:
        conf.env.explicit_install_name = False

    if Options.platform == 'sunos':
        conf.check_cc(function_name='socket', lib='socket', header_name='sys/socket.h', uselib_store='socket')
        if not conf.env.HAVE_SOCKET:
            conf.fatal("xmms2 requires libsocket on Solaris.")
            raise SystemExit(1)
        conf.env.append_unique('CFLAGS', '-D_POSIX_PTHREAD_SEMANTICS')
        conf.env.append_unique('CFLAGS', '-D_REENTRANT')
        conf.env.append_unique('CFLAGS', '-std=gnu99')
        conf.env.socket_impl = 'socket'
    elif Options.platform == 'win32':
        if conf.options.winver:
            major, minor = [int(x) for x in Options.options.winver.split('.')]
        else:
            try:
                majot, minor = sys.getwindowsversion()[:2]
            except AttributeError:
                Logs.warn("No Windows version found and no version set. "
                          "Defaulting to 5.1 (XP). You will not be able to use "
                          "this build of XMMS2 on older Windows versions.")
                major, minor = (5, 1)
        need_wspiapi = True
        if ((major, minor) >= (5, 1)):
            need_wspiapi = False

        # check_cc is mandatory by default.
        for lib in 'wsock32 ws2_32'.split():
            conf.check_cc(lib=lib, uselib_store="socket")
        for hdr in 'windows.h ws2tcpip.h winsock2.h'.split():
            conf.check_cc(header_name=hdr, uselib="socket")
        code = """
#include <ws2tcpip.h>
#include <wspiapi.h>

int main() { return 0; }
"""
        if not conf.check_cc(header_name="wspiapi.h", fragment=code,
                uselib="socket", mandatory=need_wspiapi):
            Logs.warn('This XMMS2 will only run on Windows XP and newer '
                    'machines. If you are planning to use XMMS2 on older '
                    'versions of Windows or are packaging a binary, please '
                    'consider installing the WSPiApi.h header for '
                    'compatibility. It is provided by the Platform SDK.')
        conf.env.DEFINES += [
                '_WIN32_WINNT=0x%02x%02x' % (major, minor),
                'HAVE_WINSOCK2=1'
                ]
        conf.env.socket_impl = 'wsock32'
    else:
        conf.env.socket_impl = 'posix'

    conf.env.xmms_icon = False
    if Options.platform == 'win32':
        try:
            conf.check_tool('winres')
        except Errors.ConfigurationError:
            pass
        else:
            conf.env.WINRCFLAGS = '-I%s' % os.path.abspath('pixmaps')
            conf.env.xmms_icon = True

    # TaskGen.mac_bundle option seems to be no longer silently ignored
    # if gcc -bundle option is not available.
    # TODO: Add --no-mac-bundle in options ?
    conf.env.mac_bundle_enabled = Options.platform == 'darwin'

    conf.check_cfg(package='glib-2.0', atleat_version='2.8.0',
            uselib_store='glib2', args='--cflags --libs')

    enabled_plugins, disabled_plugins = _configure_plugins(conf)
    enabled_optionals, disabled_optionals = _configure_optionals(conf)

    plugins = conf.env.XMMS_PLUGINS_ENABLED
    plugindirs = ["src/plugins/%s" % plugin for plugin in plugins]
    optionaldirs = conf.env.XMMS_OPTIONAL_BUILD
    newest = get_newest(subdirs, plugindirs, optionaldirs)
    conf.env.NEWEST_WSCRIPT_SUBDIR = newest

    [conf.sub_config(s) for s in subdirs]
    conf.write_config_header('xmms_configuration.h')

    output_plugins = [name for x, name in conf.env.XMMS_OUTPUT_PLUGINS if x > 0]

    _output_summary(
            enabled_plugins, disabled_plugins,
            enabled_optionals, disabled_optionals,
            output_plugins)

    # Do not link against unused libraries (make dpkg-shlibdeps happy).
    conf.env.LINKFLAGS += ['-Wl,--as-needed']

    return True

####
## Options
####
def _list_cb(option, opt, value, parser):
    """Callback that lets you specify lists of targets."""
    vals = value.replace(' ','').split(',')
    if vals == ['']:
        vals = []
    if getattr(parser.values, option.dest):
        vals += getattr(parser.values, option.dest)
    setattr(parser.values, option.dest, vals)

def options(opt):
    opt.tool_options('gnu_dirs')
    opt.tool_options('gcc')

    opt.add_option('--with-custom-version', type='string',
                   dest='customversion', help="Override git commit hash version")
    opt.add_option('--with-plugins', action="callback", callback=_list_cb,
                   type="string", dest="enable_plugins", default=None,
                   help="Comma separated list of plugins to build")
    opt.add_option('--without-plugins', action="callback", callback=_list_cb,
                   type="string", dest="disable_plugins", default=None,
                   help="Comma separated list of plugins to skip")
    opt.add_option('--with-default-output-plugin', type='string',
                   dest='default_output_plugin',
                   help="Force a default output plugin")
    opt.add_option('--with-optionals', action="callback", callback=_list_cb,
                   type="string", dest="enable_optionals", default=None,
                   help="Comma separated list of optionals to build")
    opt.add_option('--without-optionals', action="callback", callback=_list_cb,
                   type="string", dest="disable_optionals", default=None,
                   help="Comma separated list of optionals to skip")
    opt.add_option('--conf-prefix', action="callback", callback=_list_cb,
                   type='string', dest='config_prefix',
                   help="Specify a directory to prepend to configuration prefix")
    opt.add_option('--without-xmms2d', action='store_true', default=False,
                   dest='without_xmms2d', help="Skip build of xmms2d")
    opt.add_option('--with-pkgconfigdir', type='string', dest='pkgconfigdir',
                   help="Specify directory where to install pkg-config files")
    opt.add_option('--with-target-platform', type='string',
                   dest='target_platform',
                   help="Force a target platform (cross-compilation)")
    opt.add_option('--with-windows-version', type='string', dest='winver',
                   help="Force a specific Windows version (cross-compilation)")
    opt.add_option('--with-profiling', action="store_true", default=False,
                   dest='with_profiling', help="Enable profiling")
    opt.add_option('--with-ldconfig', action='store_true', default=None,
                   dest='ldconfig', help="Run ldconfig after install even if not root")
    opt.add_option('--without-ldconfig', action='store_false',
                   dest='ldconfig', help="Don't run ldconfig after install")

    opt.sub_options("src/xmms")
    for o in optional_subdirs + subdirs:
        opt.sub_options(o)

def shutdown(ctx):
    if ctx.cmd != 'install':
        return

    # explicitly avoid running ldconfig on --without-ldconfig
    if ctx.options.ldconfig is False:
        return

    # implicitly run ldconfig when running as root if not told otherwise
    if ctx.options.ldconfig is None and os.geteuid() != 0:
        return

    if not os.path.isfile('/sbin/ldconfig'):
        return

    libprefix = Utils.subst_vars('${LIBDIR}', ctx.env)
    Logs.info("- ldconfig '%s'" % libprefix)
    ctx.exec_command('/sbin/ldconfig %s' % libprefix)