annotate waf_paths.py @ 17:15107282d9eb

Redefined SYSCONFDIR installation path variable so that it appends APPNAME. * Although this deviates from GNU standards this relatively minor change makes it easier to write paths that are portable to Windows.
author M. George Hansen <technopolitica@gmail.com>
date Thu, 09 Jun 2011 21:40:51 -1000
parents 927f2cf75357
children 07ff8cf8a0f1
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 'sharedstatedir': ('modifiable architecture-independent data',
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
12 '${PREFIX}/com'),
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
13 'localstatedir' : ('modifiable single-machine data', '${PREFIX}/var'),
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
14 'libdir' : ('object code libraries', '${EXEC_PREFIX}/lib'),
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
15 'includedir' : ('C header files', '${PREFIX}/include'),
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
16 '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
17 'datarootdir' : ('read-only arch.-independent data root',
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
18 '${PREFIX}/share'),
17
15107282d9eb Redefined SYSCONFDIR installation path variable so that it appends APPNAME.
M. George Hansen <technopolitica@gmail.com>
parents: 16
diff changeset
19 # datadir and sysconfdir definitions deviate from GNU standards by
15107282d9eb Redefined SYSCONFDIR installation path variable so that it appends APPNAME.
M. George Hansen <technopolitica@gmail.com>
parents: 16
diff changeset
20 # appending the ${APPNAME}, but it makes the install script simpler since
15107282d9eb Redefined SYSCONFDIR installation path variable so that it appends APPNAME.
M. George Hansen <technopolitica@gmail.com>
parents: 16
diff changeset
21 # we don't have to redefine install paths on Windows.
16
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
22 'datadir' : ('read-only architecture-independent data',
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
23 '${DATAROOTDIR}/${APPNAME}'),
17
15107282d9eb Redefined SYSCONFDIR installation path variable so that it appends APPNAME.
M. George Hansen <technopolitica@gmail.com>
parents: 16
diff changeset
24 'sysconfdir' : ('read-only single-machine data',
15107282d9eb Redefined SYSCONFDIR installation path variable so that it appends APPNAME.
M. George Hansen <technopolitica@gmail.com>
parents: 16
diff changeset
25 '${PREFIX}/etc/${APPNAME}'),
16
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
26 'infodir' : ('info documentation', '${DATAROOTDIR}/info'),
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
27 'localedir' : ('locale-dependent data', '${DATAROOTDIR}/locale'),
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
28 'mandir' : ('man documentation', '${DATAROOTDIR}/man'),
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
29 'docdir' : ('documentation root', '${DATAROOTDIR}/doc/${APPNAME}'),
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
30 'htmldir' : ('html documentation', '${DOCDIR}'),
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
31 'dvidir' : ('dvi documentation', '${DOCDIR}'),
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
32 'pdfdir' : ('pdf documentation', '${DOCDIR}'),
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
33 'psdir' : ('ps documentation', '${DOCDIR}'),
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
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
36 if sys.platform == 'Windows':
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
37 option_values['PREFIX'][1] = '${PROGRAM_FILES}/${APPNAME}'
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
38 option_values['BINDIR'][1] = '${EXEC_PREFIX}'
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
39 option_values['SYSCONFDIR'][1] = '${PREFIX}'
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
40 option_values['DATAROOTDIR'][1] = '${PREFIX}'
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
41 option_values['DATADIR'][1] = '${DATAROOTDIR}/data'
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
42 option_values['DOCDIR'][1] = '${DATAROOTDIR}/doc'
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
43
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
44 def get_param(varname, default):
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
45 return getattr(Options.options, varname, '') or default
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
46
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
47 def configure(conf):
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
48 env = conf.env
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
49 env['LIBDIR'] = []
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
50 env['BINDIR'] = []
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
51 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
52 env['APPNAME'] = getattr(Context.g_module, 'APPNAME')
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
53 env['INSTALL_PATHS'] = ['PREFIX', 'EXEC_PREFIX']
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
54 complete = False
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
55 iter = 0
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
56 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
57 iter += 1
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
58 complete = True
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
59 for name in option_values:
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
60 help, default = option_values[name]
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
61 name = name.upper()
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
62 if not env[name]:
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
63 try:
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
64 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
65 except TypeError:
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
66 complete = False
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
67 env['INSTALL_PATHS'].append(name)
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
68 if not complete:
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
69 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
70 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
71
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
72 def options(opt):
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
73 inst_dir = opt.add_option_group(
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
74 'Installation directories',
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
75 '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
76 '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
77 '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
78 '"--prefix=$HOME"'
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
79 )
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
80 for k in ('--prefix', '--destdir'):
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
81 option = opt.parser.get_option(k)
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
82 if option:
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
83 opt.parser.remove_option(k)
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
84 inst_dir.add_option(option)
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
85 inst_dir.add_option(
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
86 '--exec-prefix',
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
87 help='installation prefix [Default: ${PREFIX}]',
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
88 default=inst_dir.defaults['prefix'],
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
89 dest='EXEC_PREFIX',
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
90 )
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
91 dirs_options = opt.add_option_group(
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
92 'Pre-defined installation directories',
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 )
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
95 for name in option_values:
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
96 help, default = option_values[name]
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
97 option_name = '--' + name
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
98 str_help = '{0} [Default: %default]'.format(help)
927f2cf75357 Changed build system from SCons to WAF.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
99 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
100 dest=name.upper())