Source

pyGAP / game / tools / config.py

#!/usr/bin/env python
# encoding: utf-8

from waflib import Options

SVG = False
PEP8 = False

if PEP8:
    # pylint: disable=W0611
    import tools.pep8


TARGETS = {
    '3ds_noe': {
        'languages': 'fr gb de it es'.split(),
        'padding': 4,
        'm64': False,
        'big_endian': False,
        'zip_module': 'zlib',
        'zip_level': 9,
        'lib_path': '',
        'platform': '',
    },
    'linux_x64': {
        'languages': 'fr gb jp tw'.split(),
        'padding': 4,
        'm64': True,
        'big_endian': False,
        'zip_module': 'zlib',
        'zip_level': 9,
        'platform': 'x11',
        'lib_path': '',
        'libs': 'X11 Xrandr GL rt'.split(),
    },
    'win_x64': {
        'languages': 'fr gb jp tw'.split(),
        'padding': 4,
        'm64': True,
        'big_endian': False,
        'zip_module': 'zlib',
        'zip_level': 9,
        'platform': 'win32',
        'lib_path': '../../libs/vc2010_x64',
        'libs': 'user32 gdi32 opengl32'.split(),
    }
}


def options(opt):
    if SVG:
        opt.load('parallel_debug')
    if PEP8:
        opt.load('pep8')
    opt.add_option('--m64', action='store_true', default=False, dest='m64',
                   help='align pointers for 64 bits OSes')
    opt.add_option('-b', '--big-endian', action='store_true', default=False,
                   dest='big_endian', help='force the endianness')
    opt.add_option('-z', '--zip', type='string', default='zlib', dest='zip',
                   help='specify the compression module to use \
                        e.g. lzma, zlib, lzo')
    opt.add_option('-l', '--zip-level', type='int', default='1',
                   dest='zip_level', help='specify the compression level')
    opt.add_option('--padding', type='int', default='4',
                   dest='padding', help='specify the file padding')
    opt.add_option('--target', type='string', default=None,
                   dest='target', help='specify the targeted platform')
    opt.add_option('-w', '--warning', action='store_true', default=False, dest='warning',
                   help='display compilation warnings.')


def configure(conf):
    if SVG:
        conf.load('parallel_debug')
    if PEP8:
        conf.load('pep8')

    conf.env.languages = 'fr us'.split()
    conf.env.padding = conf.options.padding
    conf.env.m64 = conf.options.m64
    conf.env.big_endian = conf.options.big_endian
    conf.env.endianness = '>' if conf.env.big_endian else '<'
    conf.env.zip_module = conf.options.zip
    if conf.env.zip_module == 'lzma':
        # no need to set level more than 6, use too much memory
        conf.env.zip_level = min(conf.options.zip_level, 6)
    else:
        conf.env.zip_level = conf.options.zip_level

    if conf.options.target in TARGETS:
        conf.env.STLIBPATH = TARGETS[conf.options.target]['lib_path']
        conf.env.target = conf.options.target
        Options.lockfile = '.lock-waf%s' % conf.options.target
        for key, value in TARGETS[conf.options.target].items():
            conf.env[key] = value

    conf.start_msg('Checking file system alignment')
    conf.end_msg(conf.env.padding)
    conf.start_msg('Checking architecture')
    conf.end_msg('x64' if conf.env.m64 else 'x86')
    conf.start_msg('Checking endianness')
    conf.end_msg('big endian' if conf.env.big_endian else 'little endian')
    conf.start_msg('Checking compression module')
    try:
        module = __import__(conf.env.zip_module)
    except ImportError:
        fmt = 'Module not found. Try pip install %s'
        conf.fatal(fmt % conf.options.zip_module)
    conf.end_msg('%s (level: %d)' % (module.__name__, conf.env.zip_level))
    conf.start_msg('Languages')
    conf.end_msg(' '.join(lang.upper() for lang in conf.env.languages))