Mercurial > parpg-core
annotate 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 |
rev | line source |
---|---|
16
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
2 # encoding: utf-8 |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
3 import sys |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
4 |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
5 from waflib import Utils, Options, Context |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
6 |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
7 option_values = { |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
8 'bindir' : ('user executables', '${EXEC_PREFIX}/bin'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
9 'sbindir' : ('system admin executables', '${EXEC_PREFIX}/sbin'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
10 'libexecdir' : ('program executables', '${EXEC_PREFIX}/libexec'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
11 'sysconfdir' : ('read-only single-machine data', '${PREFIX}/etc'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
12 'sharedstatedir': ('modifiable architecture-independent data', |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
13 '${PREFIX}/com'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
14 'localstatedir' : ('modifiable single-machine data', '${PREFIX}/var'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
15 'libdir' : ('object code libraries', '${EXEC_PREFIX}/lib'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
16 'includedir' : ('C header files', '${PREFIX}/include'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
17 'oldincludedir' : ('C header files for non-gcc', '/usr/include'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
18 'datarootdir' : ('read-only arch.-independent data root', |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
19 '${PREFIX}/share'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
20 # datadir definition deviates from GNU by appending the ${APPNAME}, but it |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
21 # makes the install script simpler since we don't have to redefine install |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
22 # paths on Windows. |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
23 'datadir' : ('read-only architecture-independent data', |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
24 '${DATAROOTDIR}/${APPNAME}'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
25 'infodir' : ('info documentation', '${DATAROOTDIR}/info'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
26 'localedir' : ('locale-dependent data', '${DATAROOTDIR}/locale'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
27 'mandir' : ('man documentation', '${DATAROOTDIR}/man'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
28 'docdir' : ('documentation root', '${DATAROOTDIR}/doc/${APPNAME}'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
29 'htmldir' : ('html documentation', '${DOCDIR}'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
30 'dvidir' : ('dvi documentation', '${DOCDIR}'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
31 'pdfdir' : ('pdf documentation', '${DOCDIR}'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
32 'psdir' : ('ps documentation', '${DOCDIR}'), |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
33 } |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
34 |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
35 if sys.platform == 'Windows': |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
36 option_values['PREFIX'][1] = '${PROGRAM_FILES}/${APPNAME}' |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
37 option_values['BINDIR'][1] = '${EXEC_PREFIX}' |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
38 option_values['SYSCONFDIR'][1] = '${PREFIX}' |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
39 option_values['DATAROOTDIR'][1] = '${PREFIX}' |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
40 option_values['DATADIR'][1] = '${DATAROOTDIR}/data' |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
41 option_values['DOCDIR'][1] = '${DATAROOTDIR}/doc' |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
42 |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
43 def get_param(varname, default): |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
44 return getattr(Options.options, varname, '') or default |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
45 |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
46 def configure(conf): |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
47 env = conf.env |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
48 env['LIBDIR'] = [] |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
49 env['BINDIR'] = [] |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
50 env['EXEC_PREFIX'] = get_param('EXEC_PREFIX', env['PREFIX']) |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
51 env['APPNAME'] = getattr(Context.g_module, 'APPNAME') |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
52 env['INSTALL_PATHS'] = ['PREFIX', 'EXEC_PREFIX'] |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
53 complete = False |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
54 iter = 0 |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
55 while not complete and iter < len(option_values) + 1: |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
56 iter += 1 |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
57 complete = True |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
58 for name in option_values: |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
59 help, default = option_values[name] |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
60 name = name.upper() |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
61 if not env[name]: |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
62 try: |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
63 env[name] = Utils.subst_vars(get_param(name, default), env) |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
64 except TypeError: |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
65 complete = False |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
66 env['INSTALL_PATHS'].append(name) |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
67 if not complete: |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
68 lst = [name for name in option_values if not env[name.upper()]] |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
69 raise Errors.WafError('Variable substitution failure %r' % lst) |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
70 |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
71 def options(opt): |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
72 inst_dir = opt.add_option_group( |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
73 'Installation directories', |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
74 'By default, "waf install" will install all files into their ' |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
75 'appropriate directories under ${PREFIX}. The installation prefix can ' |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
76 'be specified using the "--prefix" option, for example ' |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
77 '"--prefix=$HOME"' |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
78 ) |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
79 for k in ('--prefix', '--destdir'): |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
80 option = opt.parser.get_option(k) |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
81 if option: |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
82 opt.parser.remove_option(k) |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
83 inst_dir.add_option(option) |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
84 inst_dir.add_option( |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
85 '--exec-prefix', |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
86 help='installation prefix [Default: ${PREFIX}]', |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
87 default=inst_dir.defaults['prefix'], |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
88 dest='EXEC_PREFIX', |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
89 ) |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
90 dirs_options = opt.add_option_group( |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
91 'Pre-defined installation directories', |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
92 '' |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
93 ) |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
94 for name in option_values: |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
95 help, default = option_values[name] |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
96 option_name = '--' + name |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
97 str_help = '{0} [Default: %default]'.format(help) |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
98 dirs_options.add_option(option_name, help=str_help, default=default, |
927f2cf75357
Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
99 dest=name.upper()) |