s3-param: Add "server role" as global parameter
[samba.git] / dynconfig / wscript
1 #!/usr/bin/env python
2
3 import string, Logs, Utils, Options, sys, Build, os, intltool, optparse, textwrap
4 from samba_utils import EXPAND_VARIABLES, os_path_relpath
5
6 class SambaIndentedHelpFormatter (optparse.IndentedHelpFormatter):
7     """Format help with indented section bodies.
8     """
9
10     def __init__(self,
11                  indent_increment=2,
12                  max_help_position=12,
13                  width=None,
14                  short_first=1):
15         optparse.IndentedHelpFormatter.__init__(
16             self, indent_increment, max_help_position, width, short_first)
17
18     def format_option(self, option):
19         # The help for each option consists of two parts:
20         #   * the opt strings and metavars
21         #     eg. ("-x", or "-fFILENAME, --file=FILENAME")
22         #   * the user-supplied help string
23         #     eg. ("turn on expert mode", "read data from FILENAME")
24         #
25         # If possible, we write both of these on the same line:
26         #   -x      turn on expert mode
27         #
28         # But if the opt string list is too long, we put the help
29         # string on a second line, indented to the same column it would
30         # start in if it fit on the first line.
31         #   -fFILENAME, --file=FILENAME
32         #           read data from FILENAME
33         result = []
34         opts = self.option_strings[option]
35         opt_width = self.help_position - self.current_indent - 2
36         if len(opts) > opt_width:
37             opts = "%*s%s\n" % (self.current_indent, "", opts)
38             indent_first = self.help_position
39         else:                       # start help on same line as opts
40             opts = "%*s%-*s  " % (self.current_indent, "", opt_width, opts)
41             indent_first = 0
42         result.append(opts)
43         if option.help:
44             help_text = self.expand_default(option)
45             if string.find(help_text, '\n') == -1:
46                 help_lines = textwrap.wrap(help_text, self.help_width)
47             else:
48                 help_lines = help_text.splitlines()
49             result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
50             result.extend(["%*s%s\n" % (self.help_position, "", line)
51                            for line in help_lines[1:]])
52         elif opts[-1] != "\n":
53             result.append("\n")
54         return "".join(result)
55
56
57 # list of directory options to offer in configure
58 #
59 # 'STD-PATH'  - the default path without --enable-fhs
60 # 'FHS-PATH'  - the default path with --enable-fhs
61 #
62 # 'OPTION'    - the configure option to overwrite the default (optional)
63 # 'HELPTEXT'  - the help text of the configure option (optional)
64 #
65 # 'OVERWRITE' - The option referrs to itself and was already from
66 #               the basic GNU options from the gnu_dirs tool.
67 #               We may overwrite the related path. (Default: False)
68 #
69 # 'DELAY'     - The option referrs to other options in the dynconfig list.
70 #               We delay the intialization into a later stage. This
71 #               makes sure the recursion works. (Default: False)
72 #
73 dynconfig = {
74     'BINDIR' : {
75          'STD-PATH':  '${BINDIR}',
76          'FHS-PATH':  '${BINDIR}',
77          'OVERWRITE': True,
78     },
79     'SBINDIR' : {
80          'STD-PATH':  '${SBINDIR}',
81          'FHS-PATH':  '${SBINDIR}',
82          'OVERWRITE': True,
83     },
84     'LIBDIR' : {
85          'STD-PATH':  '${LIBDIR}',
86          'FHS-PATH':  '${LIBDIR}',
87          'OVERWRITE': True,
88     },
89     'LIBEXECDIR' : {
90          'STD-PATH':  '${LIBEXECDIR}',
91          'FHS-PATH':  '${LIBEXECDIR}',
92          'OVERWRITE': True,
93     },
94     'DATADIR' : {
95          'STD-PATH':  '${DATADIR}',
96          'FHS-PATH':  '${DATADIR}',
97          'OVERWRITE': True,
98     },
99     'LOCALEDIR' : {
100          'STD-PATH':  '${LOCALEDIR}',
101          'FHS-PATH':  '${LOCALEDIR}',
102          'OVERWRITE': True,
103     },
104     'PYTHONDIR' : {
105          'STD-PATH':  '${PYTHONDIR}',
106          'FHS-PATH':  '${PYTHONDIR}',
107          'OVERWRITE': True,
108     },
109     'PYTHONARCHDIR' : {
110          'STD-PATH':  '${PYTHONARCHDIR}',
111          'FHS-PATH':  '${PYTHONARCHDIR}',
112          'OVERWRITE': True,
113     },
114     'MODULESDIR' : {
115          'STD-PATH':  '${MODULESDIR}',
116          'FHS-PATH':  '${MODULESDIR}/samba',
117          'OVERWRITE': True,
118     },
119     'INCLUDEDIR' : {
120          'STD-PATH':  '${INCLUDEDIR}',
121          'FHS-PATH':  '${INCLUDEDIR}/samba-4.0',
122          'OVERWRITE': True,
123     },
124     'SCRIPTSBINDIR' : {
125          'STD-PATH':  '${SBINDIR}',
126          'FHS-PATH':  '${SBINDIR}',
127     },
128     'SETUPDIR' : {
129          'STD-PATH':  '${DATADIR}/setup',
130          'FHS-PATH':  '${DATADIR}/samba/setup',
131     },
132     'PKGCONFIGDIR' : {
133          'STD-PATH':  '${LIBDIR}/pkgconfig',
134          'FHS-PATH':  '${LIBDIR}/pkgconfig',
135     },
136     'SWATDIR' : {
137          'STD-PATH':  '${DATADIR}/swat',
138          'FHS-PATH':  '${DATADIR}/samba/swat',
139     },
140     'CODEPAGEDIR' : {
141          'STD-PATH':  '${DATADIR}/codepages',
142          'FHS-PATH':  '${DATADIR}/samba/codepages',
143     },
144     'PAMMODULESDIR' : {
145          'STD-PATH':  '${LIBDIR}/security',
146          'FHS-PATH':  '${LIBDIR}/security',
147          'OPTION':    '--with-pammodulesdir',
148          'HELPTEXT':  'Which directory to use for PAM modules',
149     },
150     'CONFIGDIR' : {
151          'STD-PATH':  '${SYSCONFDIR}',
152          'FHS-PATH':  '${SYSCONFDIR}/samba',
153          'OPTION':    '--with-configdir',
154          'HELPTEXT':  'Where to put configuration files',
155     },
156     'PRIVATE_DIR' : {
157          'STD-PATH':  '${PREFIX}/private',
158          'FHS-PATH':  '${LOCALSTATEDIR}/lib/samba/private',
159          'OPTION':    '--with-privatedir',
160          'HELPTEXT':  'Where to put sam.ldb and other private files',
161     },
162     'LOCKDIR' : {
163          'STD-PATH':  '${LOCALSTATEDIR}/lock',
164          'FHS-PATH':  '${LOCALSTATEDIR}/lock/samba',
165          'OPTION':    '--with-lockdir',
166          'HELPTEXT':  'Where to put short term disposable state files',
167     },
168     'PIDDIR' : {
169          'STD-PATH':  '${LOCALSTATEDIR}/run',
170          'FHS-PATH':  '${LOCALSTATEDIR}/run/samba',
171          'OPTION':    '--with-piddir',
172          'HELPTEXT':  'Where to put pid files',
173     },
174     'STATEDIR' : {
175          'STD-PATH':  '${LOCALSTATEDIR}/locks',
176          'FHS-PATH':  '${LOCALSTATEDIR}/lib/samba',
177          'OPTION':    '--with-statedir',
178          'HELPTEXT':  'Where to put persistent state files',
179     },
180     'CACHEDIR' : {
181          'STD-PATH':  '${LOCALSTATEDIR}/cache',
182          'FHS-PATH':  '${LOCALSTATEDIR}/cache/samba',
183          'OPTION':    '--with-cachedir',
184          'HELPTEXT':  'Where to put temporary cache files',
185     },
186     'LOGFILEBASE' : {
187          'STD-PATH':  '${LOCALSTATEDIR}',
188          'FHS-PATH':  '${LOCALSTATEDIR}/log/samba',
189          'OPTION':    '--with-logfilebase',
190          'HELPTEXT':  'Where to put log files',
191     },
192     'SOCKET_DIR' : {
193          'STD-PATH':  '${LOCALSTATEDIR}/run',
194          'FHS-PATH':  '${LOCALSTATEDIR}/run/samba',
195          'OPTION':    '--with-sockets-dir',
196          'HELPTEXT':  'socket directory',
197     },
198     'PRIVILEGED_SOCKET_DIR' : {
199          'STD-PATH':  '${LOCALSTATEDIR}/lib',
200          'FHS-PATH':  '${LOCALSTATEDIR}/lib/samba',
201          'OPTION':    '--with-privileged-socket-dir',
202          'HELPTEXT':  'privileged socket directory',
203     },
204     'WINBINDD_SOCKET_DIR' : {
205          'STD-PATH':  '${SOCKET_DIR}/winbindd',
206          'FHS-PATH':  '${SOCKET_DIR}/winbindd',
207          'DELAY':     True,
208     },
209     'WINBINDD_PRIVILEGED_SOCKET_DIR' : {
210          'STD-PATH':  '${PRIVILEGED_SOCKET_DIR}/winbindd_privileged',
211          'FHS-PATH':  '${PRIVILEGED_SOCKET_DIR}/winbindd_privileged',
212          'DELAY':     True,
213     },
214     'NMBDSOCKETDIR' : {
215          'STD-PATH':  '${SOCKET_DIR}/nmbd',
216          'FHS-PATH':  '${SOCKET_DIR}/nmbd',
217          'DELAY':     True,
218     },
219     'NTP_SIGND_SOCKET_DIR' : {
220          'STD-PATH':  '${SOCKET_DIR}/ntp_signd',
221          'FHS-PATH':  '${SOCKET_DIR}/ntp_signd',
222          'DELAY':     True,
223     },
224     'NCALRPCDIR' : {
225          'STD-PATH':  '${SOCKET_DIR}/ncalrpc',
226          'FHS-PATH':  '${SOCKET_DIR}/ncalrpc',
227          'DELAY':     True,
228     },
229     'CONFIGFILE' : {
230          'STD-PATH':  '${CONFIGDIR}/smb.conf',
231          'FHS-PATH':  '${CONFIGDIR}/smb.conf',
232          'DELAY':     True,
233     },
234     'LMHOSTSFILE' : {
235          'STD-PATH':  '${CONFIGDIR}/lmhosts',
236          'FHS-PATH':  '${CONFIGDIR}/lmhosts',
237          'DELAY':     True,
238     },
239     'SMB_PASSWD_FILE' : {
240          'STD-PATH':  '${PRIVATE_DIR}/smbpasswd',
241          'FHS-PATH':  '${PRIVATE_DIR}/smbpasswd',
242          'DELAY':     True,
243     },
244 }
245
246 def set_options(opt):
247     opt.parser.formatter = SambaIndentedHelpFormatter()
248     opt.parser.formatter.width=Utils.get_term_cols()
249
250     # get all the basic GNU options from the gnu_dirs tool
251
252     opt_group=opt.add_option_group('Samba-specific directory layout','')
253
254     fhs_help  = "Use FHS-compliant paths (default no)\n"
255     fhs_help += "You should consider using this together with:\n"
256     fhs_help += "--prefix=/usr --sysconfdir=/etc --locatestatedir=/var"
257     opt_group.add_option('--enable-fhs', help=fhs_help,
258                    action="store_true", dest='ENABLE_FHS', default=False)
259
260     for varname in dynconfig.keys():
261         if 'OPTION' not in dynconfig[varname]:
262             continue
263         opt = dynconfig[varname]['OPTION']
264         if 'HELPTEXT' in dynconfig[varname]:
265             txt = dynconfig[varname]['HELPTEXT']
266         else:
267             txt = "dynconfig path %s" % (varname)
268         def_std = dynconfig[varname]['STD-PATH']
269         def_fhs = dynconfig[varname]['FHS-PATH']
270
271         help = "%s\n[STD-Default: %s]\n[FHS-Default: %s]" % (txt, def_std, def_fhs)
272         opt_group.add_option(opt, help=help, dest=varname, action="store")
273
274 def configure(conf):
275     # get all the basic GNU options from the gnu_dirs tool
276
277     if Options.options.ENABLE_FHS:
278         flavor = 'FHS-PATH'
279     else:
280         flavor = 'STD-PATH'
281         if conf.env.PREFIX == '/usr' or conf.env.PREFIX == '/usr/local':
282            Logs.error("Don't install directly under /usr or /usr/local without using the FHS option (--enable-fhs)")
283            raise Utils.WafError("ERROR: invalid --prefix=%s value" % (conf.env.PREFIX))
284
285     explicit_set ={}
286
287     dyn_vars = {}
288     for varname in dynconfig.keys():
289         dyn_vars[varname] = dynconfig[varname][flavor]
290         if 'OVERWRITE' in dynconfig[varname] and dynconfig[varname]['OVERWRITE']:
291             # we may overwrite this option
292             continue
293         conf.ASSERT(varname not in conf.env, "Variable %s already defined" % varname)
294
295     # the explicit block
296     for varname in dynconfig.keys():
297         if 'OPTION' not in dynconfig[varname]:
298             continue
299         value = getattr(Options.options, varname, None)
300         if value is None:
301            continue
302         conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
303         conf.env[varname] = value
304         # mark it as explicit from the command line
305         explicit_set[varname] = value
306
307     # defaults stage 1 after the explicit block
308     for varname in dynconfig.keys():
309         if 'DELAY' in dynconfig[varname] and dynconfig[varname]['DELAY']:
310             # this option referrs to other options,
311             # so it needs to wait for stage 2.
312             continue
313         value = EXPAND_VARIABLES(conf, dyn_vars[varname])
314         conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
315         if varname not in explicit_set:
316             # only overwrite if not specified explicitly on the command line
317             conf.env[varname] = value
318
319     # defaults stage 2 after the explicit block
320     for varname in dynconfig.keys():
321         if 'DELAY' not in dynconfig[varname] or not dynconfig[varname]['DELAY']:
322             # this option was already handled in stage 1.
323             continue
324         value = EXPAND_VARIABLES(conf, dyn_vars[varname])
325         conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
326         if varname not in explicit_set:
327             # only overwrite if not specified explicitly on the command line
328             conf.env[varname] = value
329
330     # display the expanded pathes for the user
331     for varname in dynconfig.keys():
332         value = conf.env[varname]
333         conf.start_msg("Dynconfig[%s]: " % (varname))
334         conf.end_msg("'%s'" % (value), 'GREEN')
335
336 def dynconfig_cflags(bld, list=None):
337     '''work out the extra CFLAGS for dynconfig.c'''
338     cflags = []
339     # override some paths when running from the build directory
340     override = { 'MODULESDIR'    : 'bin/modules',
341                  'PYTHONDIR'     : 'bin/python',
342                  'PYTHONARCHDIR' : 'bin/python',
343                  'CODEPAGEDIR'   : os.path.join(bld.env.srcdir, 'codepages'),
344                  'SCRIPTSBINDIR' : os.path.join(bld.env.srcdir, 'source4/scripting/bin'),
345                  'SETUPDIR'      : os.path.join(bld.env.srcdir, 'source4/setup') }
346     for varname in dynconfig.keys():
347         if list and not varname in list:
348             continue
349         value = bld.env[varname]
350         if not Options.is_install:
351             if varname in override:
352                 value = os.path.join(os.getcwd(), override[varname])
353         cflags.append('-D%s="%s"' % (varname, value))
354     return cflags
355 Build.BuildContext.dynconfig_cflags = dynconfig_cflags
356
357 def build(bld):
358     cflags = bld.dynconfig_cflags()
359     version_header = 'version.h'
360     bld.SAMBA_SUBSYSTEM('DYNCONFIG',
361                         'dynconfig.c',
362                         deps='replace talloc',
363                         public_headers=os_path_relpath(os.path.join(Options.launch_dir, version_header), bld.curdir),
364                         header_path='samba',
365                         cflags=cflags)
366
367     # install some extra empty directories
368     bld.INSTALL_DIRS("", "${CONFIGDIR} ${PRIVATE_DIR} ${LOGFILEBASE}");
369     bld.INSTALL_DIRS("", "${PRIVATE_DIR} ${PRIVILEGED_SOCKET_DIR}")
370     bld.INSTALL_DIRS("", "${STATEDIR} ${CACHEDIR}");
371
372     # these might be on non persistent storage
373     bld.INSTALL_DIRS("", "${LOCKDIR} ${PIDDIR} ${SOCKET_DIR}")