build: split out the base waf rules into buildtools/wafsamba/wscript
[samba.git] / source4 / dynconfig / wscript
1 import string, Utils, Options
2
3 # list of directory options to offer in configure
4 dir_options = {
5     'with-piddir'                         : [ '${PREFIX}/var/run', 'where to put pid files' ],
6     'with-privatedir'                     : [ '${PREFIX}/private', 'Where to put sam.ldb and other private files' ],
7     'with-winbindd-socket-dir'            : [ '${PREFIX}/var/lib/winbindd', 'winbind socket directory' ],
8     'with-winbindd-privileged-socket-dir' : [ '${PREFIX}/var/lib/winbindd_privileged', 'winbind privileged socket directory'],
9     'with-ntp-signd-socket-dir'           : [ '${PREFIX}/var/run/ntp_signd', 'NTP signed directory'],
10     'with-lockdir'                        : [ '${PREFIX}/var/locks', 'where to put lock files' ]
11     }
12
13 # list of cflags to use for dynconfig.c
14 dyn_cflags = {
15     'CONFIGFILE'                     : '${SYSCONFDIR}/smb.conf',
16     'BINDIR'                         : '${BINDIR}',
17     'SBINDIR'                        : '${SBINDIR}',
18     'LMHOSTSFILE'                    : '${SYSCONFDIR}/lmhosts',
19     'LOCKDIR'                        : '${LOCALSTATEDIR}/locks',
20     'PIDDIR'                         : '${LOCALSTATEDIR}/run',
21     'DATADIR'                        : '${DATADIR}',
22     'LOGFILEBASE'                    : '${LOCALSTATEDIR}',
23     'CONFIGDIR'                      : '${SYSCONFDIR}',
24     'NCALRPCDIR'                     : '${LOCALSTATEDIR}/ncalrpc',
25     'SWATDIR'                        : '${DATADIR}/swat',
26     'PRIVATE_DIR'                    : '${PRIVATEDIR}',
27     'MODULESDIR'                     : '${PREFIX}/modules',
28     'SETUPDIR'                       : '${DATADIR}/setup',
29     'WINBINDD_PRIVILEGED_SOCKET_DIR' : '${WINBINDD_PRIVILEGED_SOCKET_DIR}',
30     'WINBINDD_SOCKET_DIR'            : '${WINBINDD_SOCKET_DIR}',
31     'NTP_SIGND_SOCKET_DIR'           : '${NTP_SIGND_SOCKET_DIR}',
32     }
33
34 def get_varname(v):
35     '''work out a variable name from a configure option name'''
36     if v.startswith('with-'):
37         v = v[5:]
38     v = v.upper()
39     v = string.replace(v, '-', '_')
40     return v
41
42
43 def set_options(opt):
44     # get all the basic GNU options from the gnu_dirs tool
45     opt.tool_options('gnu_dirs')
46     for option in dir_options.keys():
47         default = dir_options[option][0]
48         help    = dir_options[option][1]
49         varname = get_varname(option)
50         opt.add_option('--%s' % option,
51                        help=(help + ' [%s]' % default),
52                        action="store", dest=varname, default=default)
53
54 def configure(conf):
55     # get all the basic GNU options from the gnu_dirs tool
56     conf.check_tool('gnu_dirs')
57     for option in dir_options.keys():
58         varname = get_varname(option)
59         value = getattr(Options.options, varname, None)
60         conf.ASSERT(value is not None, "Missing configure option %s" % varname)
61         conf.ASSERT(varname not in conf.env, "Variable %s already defined" % varname)
62         conf.env[varname] = value
63
64 def dynconfig_cflags(bld):
65     '''work out the extra CFLAGS for dynconfig.c'''
66     cflags = []
67     for f in dyn_cflags.keys():
68         # substitute twice, as we could have substitutions containing variables
69         v = Utils.subst_vars(dyn_cflags[f], bld.env)
70         v = Utils.subst_vars(v, bld.env)
71         bld.ASSERT(v != '', "Empty dynconfig value for %s" % f)
72         bld.ASSERT(v.find('${') == -1, "Unsubstituted variable in %s : %s : %s" % (f, dyn_cflags[f], v))
73         cflags.append('-D%s="%s"' % (f, v))
74     return cflags
75
76 def build(bld):
77     cflags = dynconfig_cflags(bld)
78     bld.SAMBA_SUBSYSTEM('DYNCONFIG',
79                         'dynconfig.c',
80                         deps='replace talloc',
81                         cflags=cflags)