Mercurial > parpg-core
changeset 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 | 6ff6a2f74f1e |
children | 15107282d9eb |
files | .hgignore bin/parpg.bat.in bin/parpg.sh.in parpg.cfg.in waf waf_paths.py wscript |
diffstat | 7 files changed, 187 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Mon Jun 06 16:23:53 2011 -1000 +++ b/.hgignore Thu Jun 09 21:35:19 2011 -1000 @@ -1,5 +1,5 @@ glob:**.py[co] -glob:.sconsign.dblite +glob:.* syntax: regexp
--- a/bin/parpg.bat.in Mon Jun 06 16:23:53 2011 -1000 +++ b/bin/parpg.bat.in Thu Jun 09 21:35:19 2011 -1000 @@ -1,5 +1,5 @@ @ECHO OFF -SET PYTHONPATH=%PYTHONPATH%;"@PY_PACKAGES_DIR@" +SET PYTHONPATH=%PYTHONPATH%;"@PYTHONDIR@" CD %~dp0 -START "@PYTHON@" -m parpg.main "@SYS_CONF_DIR@" %* \ No newline at end of file +START "@PYTHON@" -m parpg.main "@SYSCONFDIR@" %* \ No newline at end of file
--- a/bin/parpg.sh.in Mon Jun 06 16:23:53 2011 -1000 +++ b/bin/parpg.sh.in Thu Jun 09 21:35:19 2011 -1000 @@ -1,5 +1,5 @@ #!/bin/bash -export PYTHONPATH=${PYTHONPATH}:"@PY_PACKAGES_DIR@" +export PYTHONPATH=${PYTHONPATH}:"@PYTHONDIR@" cd $(dirname $0) -"@PYTHON@" -m parpg.main "@SYS_CONF_DIR@" $@ +"@PYTHON@" -m parpg.main "@SYSCONFDIR@" $@
--- a/parpg.cfg.in Mon Jun 06 16:23:53 2011 -1000 +++ b/parpg.cfg.in Thu Jun 09 21:35:19 2011 -1000 @@ -74,7 +74,7 @@ [parpg] # System directory where all data files are located (path) -DataPath = "@DATA_DIR@" +DataPath = "@DATADIR@" # System subdirectory to load maps from (path) MapsPath = maps
--- /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())
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wscript Thu Jun 09 21:35:19 2011 -1000 @@ -0,0 +1,82 @@ +#!/usr/bin/env python +# encoding: utf-8 +import sys +import os + +APPNAME = 'parpg' +VERSION = '0.2.0' + +def options(opt): + opt.load('waf_paths python') + +def configure(cnf): + cnf.load('waf_paths python') + if sys.platform == 'Windows': + min_python_version = (2, 7) + else: + min_python_version = (2, 6) + cnf.check_python_version(min_python_version) + +def build(bld): + subst_vars = _get_subst_vars(bld) + + if sys.platform == 'Windows': + launcher_template = 'bin/parpg.bat.in' + launcher = 'parpg.bat' + else: + launcher_template = 'bin/parpg.sh.in' + launcher = 'parpg' + args = dict( + features='subst', + source=launcher_template, + target=launcher, + install_path='${BINDIR}', + chmod=0755, + ) + args.update(subst_vars) + bld(**args) + + bld( + features='py', + source=bld.path.ant_glob('src/parpg/**/*.py', dir=True), + install_from='src', + ) + + args = dict( + features='subst', + source='parpg.cfg.in', + target='parpg.cfg', + install_path='${SYSCONFDIR}', + chmod=0644, + ) + args.update(subst_vars) + bld(**args) + + bld.install_files( + files=bld.path.find_node('data').ant_glob('**/*'), + dest='${DATADIR}', + relative_trick=True, + chmod=0644, + ) + +def _get_subst_vars(cnf): + # Set up substitution variables for the launcher and configuration files. + subst_vars = {} + install_path_names = cnf.env['INSTALL_PATHS'] + for path_name in install_path_names + ['PYTHONDIR']: + subst_vars[path_name] = cnf.env[path_name] + # If the destdir option is used we'll have to manually prefix any path + # variables with it since env doesn't get updated. + # NOTE M. George Hansen 2011-06-09: This should probably be done + # automatically. Maybe we should patch WAF and contribute it the WAF + # project. + destdir = cnf.options.destdir + if destdir: + for key, path in subst_vars.items(): + # If this is an absolute path, prefix it with the destdir. + if os.path.isabs(path): + subst_vars[key] = os.path.join( + destdir, + os.path.splitdrive(path)[1].lstrip('/\\'), + ) + return subst_vars \ No newline at end of file