s3: libsmb: In cli_qpathinfo_send() (SMBtrans2:TRANSACT2_QPATHINFO) check for DFS...
[Samba.git] / dynconfig / wscript
blobc62afa25399c86f9b817c218fc4151ef4aaaf4ad
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 initalization 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 'SAMBA_DATADIR' : {
109 'STD-PATH': '${DATADIR}/samba',
110 'FHS-PATH': '${DATADIR}/samba',
111 'OVERWRITE': True,
113 'LOCALEDIR' : {
114 'STD-PATH': '${LOCALEDIR}',
115 'FHS-PATH': '${LOCALEDIR}',
116 'OVERWRITE': True,
118 'PYTHONDIR' : {
119 'STD-PATH': '${PYTHONDIR}',
120 'FHS-PATH': '${PYTHONDIR}',
121 'OVERWRITE': True,
123 'PYTHONARCHDIR' : {
124 'STD-PATH': '${PYTHONARCHDIR}',
125 'FHS-PATH': '${PYTHONARCHDIR}',
126 'OVERWRITE': True,
128 'PERL_LIB_INSTALL_DIR' : {
129 'STD-PATH': '${PERL_LIB_INSTALL_DIR}',
130 'FHS-PATH': '${PERL_LIB_INSTALL_DIR}',
131 'OVERWRITE': True,
133 'PERL_ARCH_INSTALL_DIR' : {
134 'STD-PATH': '${PERL_ARCH_INSTALL_DIR}',
135 'FHS-PATH': '${PERL_ARCH_INSTALL_DIR}',
136 'OVERWRITE': True,
138 'INCLUDEDIR' : {
139 'STD-PATH': '${INCLUDEDIR}',
140 'FHS-PATH': '${INCLUDEDIR}/samba-4.0',
141 'OVERWRITE': True,
143 'SCRIPTSBINDIR' : {
144 'STD-PATH': '${SBINDIR}',
145 'FHS-PATH': '${SBINDIR}',
147 'SETUPDIR' : {
148 'STD-PATH': '${DATADIR}/setup',
149 'FHS-PATH': '${DATADIR}/samba/setup',
151 'PKGCONFIGDIR' : {
152 'STD-PATH': '${LIBDIR}/pkgconfig',
153 'FHS-PATH': '${LIBDIR}/pkgconfig',
155 'CODEPAGEDIR' : {
156 'STD-PATH': '${DATADIR}/codepages',
157 'FHS-PATH': '${DATADIR}/samba/codepages',
159 'PRIVATELIBDIR' : {
160 'STD-PATH': '${LIBDIR}/private',
161 'FHS-PATH': '${LIBDIR}/samba',
162 'OPTION': '--with-privatelibdir',
163 'HELPTEXT': 'Which directory to use for private Samba libraries',
164 'OVERWRITE': True,
166 'MODULESDIR' : {
167 'STD-PATH': '${LIBDIR}',
168 'FHS-PATH': '${LIBDIR}/samba',
169 'OPTION': '--with-modulesdir',
170 'HELPTEXT': 'Which directory to use for Samba modules',
171 'OVERWRITE': True,
173 'PAMMODULESDIR' : {
174 'STD-PATH': '${LIBDIR}/security',
175 'FHS-PATH': '${LIBDIR}/security',
176 'OPTION': '--with-pammodulesdir',
177 'HELPTEXT': 'Which directory to use for PAM modules',
179 'CONFIGDIR' : {
180 'STD-PATH': '${SYSCONFDIR}',
181 'FHS-PATH': '${SYSCONFDIR}/samba',
182 'OPTION': '--with-configdir',
183 'HELPTEXT': 'Where to put configuration files',
185 'PRIVATE_DIR' : {
186 'STD-PATH': '${PREFIX}/private',
187 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/private',
188 'OPTION': '--with-privatedir',
189 'HELPTEXT': 'Where to put sam.ldb and other private files',
191 'BINDDNS_DIR' : {
192 'STD-PATH': '${PREFIX}/bind-dns',
193 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/bind-dns',
194 'OPTION': '--with-bind-dns-dir',
195 'HELPTEXT': 'bind-dns config directory',
197 'LOCKDIR' : {
198 'STD-PATH': '${LOCALSTATEDIR}/lock',
199 'FHS-PATH': '${LOCALSTATEDIR}/lock/samba',
200 'OPTION': '--with-lockdir',
201 'HELPTEXT': 'Where to put short term disposable state files',
203 'PIDDIR' : {
204 'STD-PATH': '${LOCALSTATEDIR}/run',
205 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
206 'OPTION': '--with-piddir',
207 'HELPTEXT': 'Where to put pid files',
209 'STATEDIR' : {
210 'STD-PATH': '${LOCALSTATEDIR}/locks',
211 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
212 'OPTION': '--with-statedir',
213 'HELPTEXT': 'Where to put persistent state files',
215 'CACHEDIR' : {
216 'STD-PATH': '${LOCALSTATEDIR}/cache',
217 'FHS-PATH': '${LOCALSTATEDIR}/cache/samba',
218 'OPTION': '--with-cachedir',
219 'HELPTEXT': 'Where to put temporary cache files',
221 'LOGFILEBASE' : {
222 'STD-PATH': '${LOCALSTATEDIR}',
223 'FHS-PATH': '${LOCALSTATEDIR}/log/samba',
224 'OPTION': '--with-logfilebase',
225 'HELPTEXT': 'Where to put log files',
227 'SOCKET_DIR' : {
228 'STD-PATH': '${LOCALSTATEDIR}/run',
229 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
230 'OPTION': '--with-sockets-dir',
231 'HELPTEXT': 'socket directory',
233 'PRIVILEGED_SOCKET_DIR' : {
234 'STD-PATH': '${LOCALSTATEDIR}/lib',
235 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
236 'OPTION': '--with-privileged-socket-dir',
237 'HELPTEXT': 'privileged socket directory',
239 'WINBINDD_SOCKET_DIR' : {
240 'STD-PATH': '${SOCKET_DIR}/winbindd',
241 'FHS-PATH': '${SOCKET_DIR}/winbindd',
242 'DELAY': True,
244 'NMBDSOCKETDIR' : {
245 'STD-PATH': '${SOCKET_DIR}/nmbd',
246 'FHS-PATH': '${SOCKET_DIR}/nmbd',
247 'DELAY': True,
249 'NTP_SIGND_SOCKET_DIR' : {
250 'STD-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
251 'FHS-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
252 'DELAY': True,
254 'NCALRPCDIR' : {
255 'STD-PATH': '${SOCKET_DIR}/ncalrpc',
256 'FHS-PATH': '${SOCKET_DIR}/ncalrpc',
257 'DELAY': True,
259 'CONFIGFILE' : {
260 'STD-PATH': '${CONFIGDIR}/smb.conf',
261 'FHS-PATH': '${CONFIGDIR}/smb.conf',
262 'DELAY': True,
264 'LMHOSTSFILE' : {
265 'STD-PATH': '${CONFIGDIR}/lmhosts',
266 'FHS-PATH': '${CONFIGDIR}/lmhosts',
267 'DELAY': True,
269 'SMB_PASSWD_FILE' : {
270 'STD-PATH': '${PRIVATE_DIR}/smbpasswd',
271 'FHS-PATH': '${PRIVATE_DIR}/smbpasswd',
272 'OPTION': '--with-smbpasswd-file',
273 'HELPTEXT': 'Where to put the smbpasswd file',
274 'DELAY': True,
278 def options(opt):
279 opt.parser.formatter = SambaIndentedHelpFormatter()
280 opt.parser.formatter.width=Logs.get_term_cols()
282 for k in ('--with-privatelibdir', '--with-modulesdir'):
283 option = opt.parser.get_option(k)
284 if option:
285 opt.parser.remove_option(k)
286 del opt.parser.defaults['PRIVATELIBDIR']
287 del opt.parser.defaults['MODULESDIR']
289 # get all the basic GNU options from the gnu_dirs tool
291 opt_group=opt.add_option_group('Samba-specific directory layout','')
293 fhs_help = "Use FHS-compliant paths (default no)\n"
294 fhs_help += "You should consider using this together with:\n"
295 fhs_help += "--prefix=/usr --sysconfdir=/etc --localstatedir=/var"
296 opt_group.add_option('--enable-fhs', help=fhs_help,
297 action="store_true", dest='ENABLE_FHS', default=False)
299 for varname in dynconfig.keys():
300 if 'OPTION' not in dynconfig[varname]:
301 continue
302 opt = dynconfig[varname]['OPTION']
303 if 'HELPTEXT' in dynconfig[varname]:
304 txt = dynconfig[varname]['HELPTEXT']
305 else:
306 txt = "dynconfig path %s" % (varname)
307 def_std = dynconfig[varname]['STD-PATH']
308 def_fhs = dynconfig[varname]['FHS-PATH']
310 help = "%s\n[STD-Default: %s]\n[FHS-Default: %s]" % (txt, def_std, def_fhs)
311 opt_group.add_option(opt, help=help, dest=varname, action="store")
313 def configure(conf):
314 # get all the basic GNU options from the gnu_dirs tool
316 if Options.options.ENABLE_FHS:
317 flavor = 'FHS-PATH'
318 else:
319 flavor = 'STD-PATH'
320 if conf.env.PREFIX == '/usr' or conf.env.PREFIX == '/usr/local':
321 Logs.error("Don't install directly under /usr or /usr/local without using the FHS option (--enable-fhs)")
322 raise Errors.WafError("ERROR: invalid --prefix=%s value" % (conf.env.PREFIX))
324 explicit_set ={}
326 dyn_vars = {}
327 for varname in dynconfig.keys():
328 dyn_vars[varname] = dynconfig[varname][flavor]
329 if 'OVERWRITE' in dynconfig[varname] and dynconfig[varname]['OVERWRITE']:
330 # we may overwrite this option
331 continue
332 conf.ASSERT(varname not in conf.env, "Variable %s already defined" % varname)
334 # the explicit block
335 for varname in dynconfig.keys():
336 if 'OPTION' not in dynconfig[varname]:
337 continue
338 value = getattr(Options.options, varname, None)
339 if value is None:
340 continue
341 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
342 conf.env[varname] = value
343 # mark it as explicit from the command line
344 explicit_set[varname] = value
346 # defaults stage 1 after the explicit block
347 for varname in dynconfig.keys():
348 if 'DELAY' in dynconfig[varname] and dynconfig[varname]['DELAY']:
349 # this option refers to other options,
350 # so it needs to wait for stage 2.
351 continue
352 value = EXPAND_VARIABLES(conf, dyn_vars[varname])
353 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
354 if varname not in explicit_set:
355 # only overwrite if not specified explicitly on the command line
356 conf.env[varname] = value
358 # defaults stage 2 after the explicit block
359 for varname in dynconfig.keys():
360 if 'DELAY' not in dynconfig[varname] or not dynconfig[varname]['DELAY']:
361 # this option was already handled in stage 1.
362 continue
363 value = EXPAND_VARIABLES(conf, dyn_vars[varname])
364 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
365 if varname not in explicit_set:
366 # only overwrite if not specified explicitly on the command line
367 conf.env[varname] = value
369 # display the expanded paths for the user
370 for varname in dynconfig.keys():
371 value = conf.env[varname]
372 conf.start_msg("Dynconfig[%s]: " % (varname))
373 conf.end_msg("'%s'" % (value), 'GREEN')
375 def get_override(bld):
376 override = { 'MODULESDIR' : 'bin/modules',
377 'PYTHONDIR' : 'bin/python',
378 'PYTHONARCHDIR' : 'bin/python',
379 'BINDIR' : 'bin',
380 'SBINDIR' : 'bin',
381 'LIBEXECDIR' : 'bin',
382 'SAMBA_LIBEXECDIR' : 'bin',
383 'CODEPAGEDIR' : 'codepages',
384 'SCRIPTSBINDIR' : 'source4/scripting/bin',
385 'SETUPDIR' : 'source4/setup'
387 return override
389 def dynconfig_cflags(bld, list=None):
390 '''work out the extra CFLAGS for dynconfig.c'''
391 cflags = []
392 for varname in dynconfig.keys():
393 if list and not varname in list:
394 continue
395 value = bld.env[varname]
396 if not bld.is_install:
397 override = get_override(bld)
398 if varname in override:
399 value = os.path.join(bld.env.srcdir, override[varname])
400 cflags.append('-D%s="%s"' % (varname, value))
401 return cflags
402 Build.BuildContext.dynconfig_cflags = dynconfig_cflags
404 def dynconfig_varnames(bld, list=None):
405 '''work out the dynconfig variables'''
406 varnames = []
407 for varname in dynconfig.keys():
408 if list and not varname in list:
409 continue
410 varnames.append(varname)
411 return varnames
412 Build.BuildContext.dynconfig_varnames = dynconfig_varnames
414 def pathconfig_entities(bld, list=None):
415 '''work out the extra entities for the docs'''
416 entities = []
417 for varname in dynconfig.keys():
418 if list and not varname in list:
419 continue
420 value = bld.env[varname]
421 if not bld.is_install:
422 override = get_override(bld)
423 if varname in override:
424 value = os.path.join(bld.env.srcdir, override[varname])
425 entities.append("<!ENTITY pathconfig.%s '%s'>" % (varname, value))
426 return entities
427 Build.BuildContext.pathconfig_entities = pathconfig_entities
429 def build(bld):
430 cflags = bld.dynconfig_cflags()
431 version_header = 'version.h'
432 bld.SAMBA_SUBSYSTEM('DYNCONFIG',
433 'dynconfig.c',
434 deps='replace',
435 public_headers=os.path.relpath(os.path.join(Context.launch_dir, version_header), bld.path.abspath()),
436 header_path='samba',
437 cflags=cflags)
439 # install some extra empty directories
440 bld.INSTALL_DIR("${CONFIGDIR}")
441 bld.INSTALL_DIR("${LOGFILEBASE}")
442 bld.INSTALL_DIR("${PRIVILEGED_SOCKET_DIR}")
443 bld.INSTALL_DIR("${PRIVATE_DIR}", 0o700)
444 bld.INSTALL_DIR("${BINDDNS_DIR}", 0o770)
445 bld.INSTALL_DIR("${STATEDIR}")
446 bld.INSTALL_DIR("${CACHEDIR}")
448 # these might be on non persistent storage
449 bld.INSTALL_DIRS("", "${LOCKDIR} ${PIDDIR} ${SOCKET_DIR}")