vfs: Only call openat for valid params in fake_acls_stat
[samba4-gss.git] / dynconfig / wscript
blobc338fd348888c7987e0539552bec2afd6833ce34
1 #!/usr/bin/env python
3 import string
4 import os
5 import optparse
6 import textwrap
7 from waflib import Logs, Errors, Options, Build, Context
8 from samba_utils import EXPAND_VARIABLES
10 class SambaIndentedHelpFormatter (optparse.IndentedHelpFormatter):
11 """Format help with indented section bodies.
12 """
14 def __init__(self,
15 indent_increment=2,
16 max_help_position=12,
17 width=None,
18 short_first=1):
19 optparse.IndentedHelpFormatter.__init__(
20 self, indent_increment, max_help_position, width, short_first)
22 def format_option(self, option):
23 # The help for each option consists of two parts:
24 # * the opt strings and metavars
25 # eg. ("-x", or "-fFILENAME, --file=FILENAME")
26 # * the user-supplied help string
27 # eg. ("turn on expert mode", "read data from FILENAME")
29 # If possible, we write both of these on the same line:
30 # -x turn on expert mode
32 # But if the opt string list is too long, we put the help
33 # string on a second line, indented to the same column it would
34 # start in if it fit on the first line.
35 # -fFILENAME, --file=FILENAME
36 # read data from FILENAME
37 result = []
38 opts = self.option_strings[option]
39 opt_width = self.help_position - self.current_indent - 2
40 if len(opts) > opt_width:
41 opts = "%*s%s\n" % (self.current_indent, "", opts)
42 indent_first = self.help_position
43 else: # start help on same line as opts
44 opts = "%*s%-*s " % (self.current_indent, "", opt_width, opts)
45 indent_first = 0
46 result.append(opts)
47 if option.help:
48 help_text = self.expand_default(option)
49 if help_text.find('\n') == -1:
50 help_lines = textwrap.wrap(help_text, self.help_width)
51 else:
52 help_lines = help_text.splitlines()
53 result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
54 result.extend(["%*s%s\n" % (self.help_position, "", line)
55 for line in help_lines[1:]])
56 elif opts[-1] != "\n":
57 result.append("\n")
58 return "".join(result)
61 # list of directory options to offer in configure
63 # 'STD-PATH' - the default path without --enable-fhs
64 # 'FHS-PATH' - the default path with --enable-fhs
66 # 'OPTION' - the configure option to overwrite the default (optional)
67 # 'HELPTEXT' - the help text of the configure option (optional)
69 # 'OVERWRITE' - The option refers to itself and was already from
70 # the basic GNU options from the gnu_dirs tool.
71 # We may overwrite the related path. (Default: False)
73 # 'DELAY' - The option refers to other options in the dynconfig list.
74 # We delay the initialization into a later stage. This
75 # makes sure the recursion works. (Default: False)
77 dynconfig = {
78 'BINDIR' : {
79 'STD-PATH': '${BINDIR}',
80 'FHS-PATH': '${BINDIR}',
81 'OVERWRITE': True,
83 'SBINDIR' : {
84 'STD-PATH': '${SBINDIR}',
85 'FHS-PATH': '${SBINDIR}',
86 'OVERWRITE': True,
88 'LIBDIR' : {
89 'STD-PATH': '${LIBDIR}',
90 'FHS-PATH': '${LIBDIR}',
91 'OVERWRITE': True,
93 'LIBEXECDIR' : {
94 'STD-PATH': '${LIBEXECDIR}',
95 'FHS-PATH': '${LIBEXECDIR}',
96 'OVERWRITE': True,
98 'SAMBA_LIBEXECDIR' : {
99 'STD-PATH': '${LIBEXECDIR}/samba',
100 'FHS-PATH': '${LIBEXECDIR}/samba',
101 'OVERWRITE': True,
103 'DATADIR' : {
104 'STD-PATH': '${DATADIR}',
105 'FHS-PATH': '${DATADIR}',
106 'OVERWRITE': True,
108 'CTDB_DATADIR' : {
109 'STD-PATH': '${DATADIR}/ctdb',
110 'FHS-PATH': '${DATADIR}/ctdb',
111 'OVERWRITE': True,
113 'SAMBA_DATADIR' : {
114 'STD-PATH': '${DATADIR}/samba',
115 'FHS-PATH': '${DATADIR}/samba',
116 'OVERWRITE': True,
118 'LOCALEDIR' : {
119 'STD-PATH': '${LOCALEDIR}',
120 'FHS-PATH': '${LOCALEDIR}',
121 'OVERWRITE': True,
123 'PYTHONDIR' : {
124 'STD-PATH': '${PYTHONDIR}',
125 'FHS-PATH': '${PYTHONDIR}',
126 'OVERWRITE': True,
128 'PYTHONARCHDIR' : {
129 'STD-PATH': '${PYTHONARCHDIR}',
130 'FHS-PATH': '${PYTHONARCHDIR}',
131 'OVERWRITE': True,
133 'PERL_LIB_INSTALL_DIR' : {
134 'STD-PATH': '${PERL_LIB_INSTALL_DIR}',
135 'FHS-PATH': '${PERL_LIB_INSTALL_DIR}',
136 'OVERWRITE': True,
138 'PERL_ARCH_INSTALL_DIR' : {
139 'STD-PATH': '${PERL_ARCH_INSTALL_DIR}',
140 'FHS-PATH': '${PERL_ARCH_INSTALL_DIR}',
141 'OVERWRITE': True,
143 'INCLUDEDIR' : {
144 'STD-PATH': '${INCLUDEDIR}',
145 'FHS-PATH': '${INCLUDEDIR}/samba-4.0',
146 'OVERWRITE': True,
148 'SCRIPTSBINDIR' : {
149 'STD-PATH': '${SBINDIR}',
150 'FHS-PATH': '${SBINDIR}',
152 'SETUPDIR' : {
153 'STD-PATH': '${DATADIR}/setup',
154 'FHS-PATH': '${DATADIR}/samba/setup',
156 'PKGCONFIGDIR' : {
157 'STD-PATH': '${LIBDIR}/pkgconfig',
158 'FHS-PATH': '${LIBDIR}/pkgconfig',
160 'CODEPAGEDIR' : {
161 'STD-PATH': '${DATADIR}/codepages',
162 'FHS-PATH': '${DATADIR}/samba/codepages',
164 'PRIVATELIBDIR' : {
165 'STD-PATH': '${LIBDIR}/private',
166 'FHS-PATH': '${LIBDIR}/samba',
167 'OPTION': '--with-privatelibdir',
168 'HELPTEXT': 'Which directory to use for private Samba libraries',
169 'OVERWRITE': True,
171 'MODULESDIR' : {
172 'STD-PATH': '${LIBDIR}',
173 'FHS-PATH': '${LIBDIR}/samba',
174 'OPTION': '--with-modulesdir',
175 'HELPTEXT': 'Which directory to use for Samba modules',
176 'OVERWRITE': True,
178 'LDBMODULESDIR' : {
179 'STD-PATH': '${MODULESDIR}/ldb',
180 'FHS-PATH': '${MODULESDIR}/ldb',
181 'OPTION': '--with-ldbmodulesdir',
182 'HELPTEXT': 'Which directory to use for LDB modules',
183 'DELAY': True,
185 'PAMMODULESDIR' : {
186 'STD-PATH': '${LIBDIR}/security',
187 'FHS-PATH': '${LIBDIR}/security',
188 'OPTION': '--with-pammodulesdir',
189 'HELPTEXT': 'Which directory to use for PAM modules',
191 'CONFIGDIR' : {
192 'STD-PATH': '${SYSCONFDIR}',
193 'FHS-PATH': '${SYSCONFDIR}/samba',
194 'OPTION': '--with-configdir',
195 'HELPTEXT': 'Where to put configuration files',
197 'PRIVATE_DIR' : {
198 'STD-PATH': '${PREFIX}/private',
199 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/private',
200 'OPTION': '--with-privatedir',
201 'HELPTEXT': 'Where to put sam.ldb and other private files',
203 'BINDDNS_DIR' : {
204 'STD-PATH': '${PREFIX}/bind-dns',
205 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/bind-dns',
206 'OPTION': '--with-bind-dns-dir',
207 'HELPTEXT': 'bind-dns config directory',
209 'LOCKDIR' : {
210 'STD-PATH': '${LOCALSTATEDIR}/lock',
211 'FHS-PATH': '${LOCALSTATEDIR}/lock/samba',
212 'OPTION': '--with-lockdir',
213 'HELPTEXT': 'Where to put short term disposable state files',
215 'PIDDIR' : {
216 'STD-PATH': '${LOCALSTATEDIR}/run',
217 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
218 'OPTION': '--with-piddir',
219 'HELPTEXT': 'Where to put pid files',
221 'STATEDIR' : {
222 'STD-PATH': '${LOCALSTATEDIR}/locks',
223 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
224 'OPTION': '--with-statedir',
225 'HELPTEXT': 'Where to put persistent state files',
227 'CACHEDIR' : {
228 'STD-PATH': '${LOCALSTATEDIR}/cache',
229 'FHS-PATH': '${LOCALSTATEDIR}/cache/samba',
230 'OPTION': '--with-cachedir',
231 'HELPTEXT': 'Where to put temporary cache files',
233 'LOGFILEBASE' : {
234 'STD-PATH': '${LOCALSTATEDIR}',
235 'FHS-PATH': '${LOCALSTATEDIR}/log/samba',
236 'OPTION': '--with-logfilebase',
237 'HELPTEXT': 'Where to put log files',
239 'SOCKET_DIR' : {
240 'STD-PATH': '${LOCALSTATEDIR}/run',
241 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
242 'OPTION': '--with-sockets-dir',
243 'HELPTEXT': 'socket directory',
245 'PRIVILEGED_SOCKET_DIR' : {
246 'STD-PATH': '${LOCALSTATEDIR}/lib',
247 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
248 'OPTION': '--with-privileged-socket-dir',
249 'HELPTEXT': 'privileged socket directory',
251 'WINBINDD_SOCKET_DIR' : {
252 'STD-PATH': '${SOCKET_DIR}/winbindd',
253 'FHS-PATH': '${SOCKET_DIR}/winbindd',
254 'DELAY': True,
256 'NMBDSOCKETDIR' : {
257 'STD-PATH': '${SOCKET_DIR}/nmbd',
258 'FHS-PATH': '${SOCKET_DIR}/nmbd',
259 'DELAY': True,
261 'NTP_SIGND_SOCKET_DIR' : {
262 'STD-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
263 'FHS-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
264 'DELAY': True,
266 'NCALRPCDIR' : {
267 'STD-PATH': '${SOCKET_DIR}/ncalrpc',
268 'FHS-PATH': '${SOCKET_DIR}/ncalrpc',
269 'DELAY': True,
271 'CONFIGFILE' : {
272 'STD-PATH': '${CONFIGDIR}/smb.conf',
273 'FHS-PATH': '${CONFIGDIR}/smb.conf',
274 'DELAY': True,
276 'LMHOSTSFILE' : {
277 'STD-PATH': '${CONFIGDIR}/lmhosts',
278 'FHS-PATH': '${CONFIGDIR}/lmhosts',
279 'DELAY': True,
281 'SMB_PASSWD_FILE' : {
282 'STD-PATH': '${PRIVATE_DIR}/smbpasswd',
283 'FHS-PATH': '${PRIVATE_DIR}/smbpasswd',
284 'OPTION': '--with-smbpasswd-file',
285 'HELPTEXT': 'Where to put the smbpasswd file',
286 'DELAY': True,
288 'HIMMELBLAUD_HSM_PIN_PATH': {
289 'STD-PATH': '${LOCALSTATEDIR}/lib/himmelblaud/hsm-pin',
290 'FHS-PATH': '${LOCALSTATEDIR}/lib/himmelblaud/hsm-pin',
291 'OPTION': '--with-himmelblaud-hsm-pin-path',
292 'HELPTEXT': 'Where to store the hsm pin',
293 'DELAY': True,
297 def options(opt):
298 opt.parser.formatter = SambaIndentedHelpFormatter()
299 opt.parser.formatter.width=Logs.get_term_cols()
301 for k in ('--with-privatelibdir', '--with-modulesdir'):
302 option = opt.parser.get_option(k)
303 if option:
304 opt.parser.remove_option(k)
305 del opt.parser.defaults['PRIVATELIBDIR']
306 del opt.parser.defaults['MODULESDIR']
308 # get all the basic GNU options from the gnu_dirs tool
310 opt_group=opt.add_option_group('Samba-specific directory layout','')
312 fhs_help = "Use FHS-compliant paths (default no)\n"
313 fhs_help += "You should consider using this together with:\n"
314 fhs_help += "--prefix=/usr --sysconfdir=/etc --localstatedir=/var"
315 opt_group.add_option('--enable-fhs', help=fhs_help,
316 action="store_true", dest='ENABLE_FHS', default=False)
318 for varname in dynconfig.keys():
319 if 'OPTION' not in dynconfig[varname]:
320 continue
321 opt = dynconfig[varname]['OPTION']
322 if 'HELPTEXT' in dynconfig[varname]:
323 txt = dynconfig[varname]['HELPTEXT']
324 else:
325 txt = "dynconfig path %s" % (varname)
326 def_std = dynconfig[varname]['STD-PATH']
327 def_fhs = dynconfig[varname]['FHS-PATH']
329 help = "%s\n[STD-Default: %s]\n[FHS-Default: %s]" % (txt, def_std, def_fhs)
330 opt_group.add_option(opt, help=help, dest=varname, action="store")
332 def configure(conf):
333 # get all the basic GNU options from the gnu_dirs tool
335 if Options.options.ENABLE_FHS:
336 flavor = 'FHS-PATH'
337 else:
338 flavor = 'STD-PATH'
339 if conf.env.PREFIX == '/usr' or conf.env.PREFIX == '/usr/local':
340 Logs.error("Don't install directly under /usr or /usr/local without using the FHS option (--enable-fhs)")
341 raise Errors.WafError("ERROR: invalid --prefix=%s value" % (conf.env.PREFIX))
343 explicit_set ={}
345 dyn_vars = {}
346 for varname in dynconfig.keys():
347 dyn_vars[varname] = dynconfig[varname][flavor]
348 if 'OVERWRITE' in dynconfig[varname] and dynconfig[varname]['OVERWRITE']:
349 # we may overwrite this option
350 continue
351 conf.ASSERT(varname not in conf.env, "Variable %s already defined" % varname)
353 # the explicit block
354 for varname in dynconfig.keys():
355 if 'OPTION' not in dynconfig[varname]:
356 continue
357 value = getattr(Options.options, varname, None)
358 if value is None:
359 continue
360 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
361 conf.env[varname] = value
362 # mark it as explicit from the command line
363 explicit_set[varname] = value
365 # defaults stage 1 after the explicit block
366 for varname in dynconfig.keys():
367 if 'DELAY' in dynconfig[varname] and dynconfig[varname]['DELAY']:
368 # this option refers to other options,
369 # so it needs to wait for stage 2.
370 continue
371 value = EXPAND_VARIABLES(conf, dyn_vars[varname])
372 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
373 if varname not in explicit_set:
374 # only overwrite if not specified explicitly on the command line
375 conf.env[varname] = value
377 # defaults stage 2 after the explicit block
378 for varname in dynconfig.keys():
379 if 'DELAY' not in dynconfig[varname] or not dynconfig[varname]['DELAY']:
380 # this option was already handled in stage 1.
381 continue
382 value = EXPAND_VARIABLES(conf, dyn_vars[varname])
383 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
384 if varname not in explicit_set:
385 # only overwrite if not specified explicitly on the command line
386 conf.env[varname] = value
388 # display the expanded paths for the user
389 for varname in dynconfig.keys():
390 value = conf.env[varname]
391 conf.start_msg("Dynconfig[%s]: " % (varname))
392 conf.end_msg("'%s'" % (value), 'GREEN')
394 def get_override(bld):
395 override = { 'MODULESDIR' : 'bin/modules',
396 'PYTHONDIR' : 'bin/python',
397 'PYTHONARCHDIR' : 'bin/python',
398 'BINDIR' : 'bin',
399 'SBINDIR' : 'bin',
400 'LIBEXECDIR' : 'bin',
401 'SAMBA_LIBEXECDIR' : 'bin',
402 'CODEPAGEDIR' : 'codepages',
403 'SCRIPTSBINDIR' : 'source4/scripting/bin',
404 'SETUPDIR' : 'source4/setup'
406 return override
408 def dynconfig_cflags(bld, list=None):
409 '''work out the extra CFLAGS for dynconfig.c'''
410 cflags = []
411 for varname in dynconfig.keys():
412 if list and not varname in list:
413 continue
414 value = bld.env[varname]
415 if not bld.is_install:
416 override = get_override(bld)
417 if varname in override:
418 value = os.path.join(bld.env.srcdir, override[varname])
419 cflags.append('-D%s="%s"' % (varname, value))
420 return cflags
421 Build.BuildContext.dynconfig_cflags = dynconfig_cflags
423 def dynconfig_varnames(bld, list=None):
424 '''work out the dynconfig variables'''
425 varnames = []
426 for varname in dynconfig.keys():
427 if list and not varname in list:
428 continue
429 varnames.append(varname)
430 return varnames
431 Build.BuildContext.dynconfig_varnames = dynconfig_varnames
433 def pathconfig_entities(bld, list=None):
434 '''work out the extra entities for the docs'''
435 entities = []
436 for varname in dynconfig.keys():
437 if list and not varname in list:
438 continue
439 value = bld.env[varname]
440 if not bld.is_install:
441 override = get_override(bld)
442 if varname in override:
443 value = os.path.join(bld.env.srcdir, override[varname])
444 entities.append("<!ENTITY pathconfig.%s '%s'>" % (varname, value))
445 return entities
446 Build.BuildContext.pathconfig_entities = pathconfig_entities
448 def build(bld):
449 cflags = bld.dynconfig_cflags()
450 version_header = 'version.h'
451 bld.SAMBA_SUBSYSTEM('DYNCONFIG',
452 'dynconfig.c',
453 deps='replace',
454 public_headers=os.path.relpath(os.path.join(Context.launch_dir, version_header), bld.path.abspath()),
455 header_path='samba',
456 cflags=cflags)
458 # install some extra empty directories
459 bld.INSTALL_DIR("${CONFIGDIR}")
460 bld.INSTALL_DIR("${LOGFILEBASE}")
461 bld.INSTALL_DIR("${PRIVILEGED_SOCKET_DIR}")
462 bld.INSTALL_DIR("${PRIVATE_DIR}", 0o700)
463 bld.INSTALL_DIR("${BINDDNS_DIR}", 0o770)
464 bld.INSTALL_DIR("${STATEDIR}")
465 bld.INSTALL_DIR("${CACHEDIR}")
467 # these might be on non persistent storage
468 bld.INSTALL_DIRS("", "${LOCKDIR} ${PIDDIR} ${SOCKET_DIR}")