view waf_paths.py @ 123:d1364aeb61c6

Removed gfx field from FifeAgent.
author KarstenBock@gmx.net
date Tue, 27 Sep 2011 15:51:11 +0200
parents feceb6130570
children
line wrap: on
line source

#! /usr/bin/env python
# encoding: utf-8
import os
import platform
import re

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

try:
    from collections import OrderedDict
except ImportError:
    # Python 2.6 doesn't have an OrderedDict, so we'll provide one.
    from ordereddict import OrderedDict

prefix_values = OrderedDict(
    [
        ('prefix', ['installation prefix', '/usr/local']),
        ('exec_prefix',
         ['installation prefix for platform-dependent binary files',
          '${PREFIX}'])
    ]
)

option_values = OrderedDict(
    [
        ('bindir', ['user executables', '${EXEC_PREFIX}/bin']),
        ('sbindir', ['system admin executables', '${EXEC_PREFIX}/sbin']),
        ('libexecdir', ['program executables', '${EXEC_PREFIX}/libexec']),
        ('sharedstatedir', ['modifiable architecture-independent data',
                            '${PREFIX}/com']),
        ('localstatedir', ['modifiable single-machine data', '${PREFIX}/var']),
        ('libdir', ['object code libraries', '${EXEC_PREFIX}/lib']),
        ('includedir', ['C header files', '${PREFIX}/include']),
        ('oldincludedir', ['C header files for non-gcc', '/usr/include']),
        ('datarootdir', ['read-only arch.-independent data root',
                         '${PREFIX}/share']),
        # datadir and sysconfdir definitions deviate from GNU standards by
        # appending the ${APPNAME}, but it makes the install script simpler
        # since we don't have to redefine install paths on Windows.
        ('datadir', ['read-only architecture-independent data',
                     '${DATAROOTDIR}/${APPNAME}']),
        ('sysconfdir', ['read-only single-machine data',
                        '${PREFIX}/etc/${APPNAME}']),
        ('infodir', ['info documentation', '${DATAROOTDIR}/info']),
        ('localedir', ['locale-dependent data', '${DATAROOTDIR}/locale']),
        ('mandir', ['man documentation', '${DATAROOTDIR}/man']),
        ('docdir', ['documentation root', '${DATAROOTDIR}/doc/${APPNAME}']),
        ('htmldir', ['html documentation', '${DOCDIR}']),
        ('dvidir', ['dvi documentation', '${DOCDIR}']),
        ('pdfdir', ['pdf documentation', '${DOCDIR}']),
        ('psdir', ['ps documentation', '${DOCDIR}']),
    ]
)

if platform.system() == 'Windows':
    prefix_values['prefix'][1] = '${PROGRAMFILES}/${APPNAME}'
    
    option_values['bindir'][1] = '${EXEC_PREFIX}'
    option_values['sysconfdir'][1] = '${PREFIX}'
    option_values['datarootdir'][1] = '${PREFIX}'
    option_values['datadir'][1] = '${DATAROOTDIR}/data'
    option_values['docdir'][1] = '${DATAROOTDIR}/doc'
    del option_values['oldincludedir']
    del option_values['mandir']

def options(opt):
    inst_dir = opt.add_option_group(
        'Installation directories',
        'By default, "waf install" will install all files into their '
        'appropriate directories under ${PREFIX}. The installation prefix can '
        'be specified using the "--prefix" option, for example '
        '"--prefix=$HOME"'
    )
    help_template = '{0} [Default: %default]'
    for prefix_name in prefix_values.keys():
        # Remove any of the core WAF options if they conflict with our options.
        if opt.parser.get_option(prefix_name):
            opt.parser.remove_option(prefix_name)
        help, default = prefix_values[prefix_name]
        option_name = '--' + prefix_name
        inst_dir.add_option(option_name, help=help_template.format(help),
                            default=default, dest=prefix_name)
    
    # Move the --destdir option to the inst_dir group for consistency.
    destdir_option = opt.parser.get_option('destdir')
    if destdir_option:
        opt.parser.remove_option('destdir')
        inst_dir.add_option(destdir_option)
    
    predef_dirs = opt.add_option_group(
        'Pre-defined installation directories',
        ''
    )
    for name in option_values:
        help, default = option_values[name]
        option_name = '--' + name
        predef_dirs.add_option(option_name, help=help_template.format(help),
                               default=default, dest=name)

def configure(conf):
    def set_env_paths(path_values):
        errors_raised = False
        index = 0
        for option_name in path_values.keys():
            help, default = path_values[option_name]
            upper_option_name = option_name.upper()
            try:
                env[upper_option_name] = Utils.subst_vars(
                    getattr(conf.options, option_name),
                    env,
                )
            except TypeError:
                errors_raised = True
            env['INSTALL_PATHS'].append(upper_option_name)
        if errors_raised:
            failed_path_names = [name for name in option_values if
                                 upper_option_name not in env]
        else:
            failed_path_names = []
        return failed_path_names
    
    env = conf.env
    if platform.system() == 'Windows':
        try:
            env['PROGRAMFILES'] = os.environ['PROGRAMFILES']
        except KeyError:
            Logs.warn('PROGRAMFILES environmental variable is not set')
            if re.search(r'\$\{PROGRAMFILES\}', conf.options.prefix):
                Logs.error(
                    'unable to find path to Program Files direcotry, please '
                    'set the PROGRAMFILES environmental variable or '
                    'override installation prefix with --prefix'
                )
    if 'APPNAME' not in env:
        env['APPNAME'] = Context.g_module.APPNAME
    env['INSTALL_PATHS'] = []
    failed_path_names = []
    failed_path_names.extend(set_env_paths(prefix_values))
    failed_path_names.extend(set_env_paths(option_values))
    if failed_path_names:
        error_message = 'failed to expand install paths {0!r}'
        raise Errors.ConfigurationError(
            error_message.format(failed_path_names)
        )