diff waf_paths.py @ 16:927f2cf75357

Changed build system from SCons to WAF. * WAF is an old fork of SCons that is now for all intents and purposes a different build system. * Unlike SCons which requires a system install of the scons library to work, the entire WAF library is self-contained in a single 'waf' Python script provided with PARPG. * Build instructions are a little different from SCons - execute the local 'waf' script with the arguments 'configure install'. * To make a local install for testing, add the '--destdir=<directory>' option to make all files install under <directory> as a fake root (e.g. '--destdir=dev_install' would make WAF install all files under the 'dev_install' directory in the PARPG source). * Added a waf_paths.py WAF tool to set GNU-compatible installation path variables (i.e. PREFIX, EXEC_PREFIX, LIBDIR, etc.). These variables should be initialized to sane defaults on Windows, where GNU standards don't usually apply.
author M. George Hansen <technopolitica@gmail.com>
date Thu, 09 Jun 2011 21:35:19 -1000
parents
children 15107282d9eb
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/waf_paths.py	Thu Jun 09 21:35:19 2011 -1000
@@ -0,0 +1,99 @@
+#! /usr/bin/env python
+# encoding: utf-8
+import sys
+
+from waflib import Utils, Options, Context
+
+option_values = {
+    'bindir'        : ('user executables', '${EXEC_PREFIX}/bin'),
+    'sbindir'       : ('system admin executables', '${EXEC_PREFIX}/sbin'),
+    'libexecdir'    : ('program executables', '${EXEC_PREFIX}/libexec'),
+    'sysconfdir'    : ('read-only single-machine data', '${PREFIX}/etc'),
+    '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 definition deviates from GNU 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}'),
+    '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 sys.platform == 'Windows':
+    option_values['PREFIX'][1] = '${PROGRAM_FILES}/${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'
+
+def get_param(varname, default):
+        return getattr(Options.options, varname, '') or default
+
+def configure(conf):
+    env = conf.env
+    env['LIBDIR'] = []
+    env['BINDIR'] = []
+    env['EXEC_PREFIX'] = get_param('EXEC_PREFIX', env['PREFIX'])
+    env['APPNAME'] = getattr(Context.g_module, 'APPNAME')
+    env['INSTALL_PATHS'] = ['PREFIX', 'EXEC_PREFIX']
+    complete = False
+    iter = 0
+    while not complete and iter < len(option_values) + 1:
+        iter += 1
+        complete = True
+        for name in option_values:
+            help, default = option_values[name]
+            name = name.upper()
+            if not env[name]:
+                try:
+                    env[name] = Utils.subst_vars(get_param(name, default), env)
+                except TypeError:
+                    complete = False
+            env['INSTALL_PATHS'].append(name)
+    if not complete:
+        lst = [name for name in option_values if not env[name.upper()]]
+        raise Errors.WafError('Variable substitution failure %r' % lst)
+
+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"'
+    )
+    for k in ('--prefix', '--destdir'):
+        option = opt.parser.get_option(k)
+        if option:
+            opt.parser.remove_option(k)
+            inst_dir.add_option(option)
+    inst_dir.add_option(
+        '--exec-prefix',
+        help='installation prefix [Default: ${PREFIX}]',
+        default=inst_dir.defaults['prefix'],
+        dest='EXEC_PREFIX',
+    )
+    dirs_options = opt.add_option_group(
+        'Pre-defined installation directories',
+        ''
+    )
+    for name in option_values:
+        help, default = option_values[name]
+        option_name = '--' + name
+        str_help = '{0} [Default: %default]'.format(help)
+        dirs_options.add_option(option_name, help=str_help, default=default,
+                                dest=name.upper())