Add tests for talloc_memlimit
[Samba.git] / dynconfig / wscript
blobdc4075a62b16ead0eb949090267e6a2464c1ce86
1 #!/usr/bin/env python
3 import string, Logs, Utils, Options, sys, Build, os, intltool, optparse, textwrap
4 from samba_utils import EXPAND_VARIABLES, os_path_relpath
6 class SambaIndentedHelpFormatter (optparse.IndentedHelpFormatter):
7 """Format help with indented section bodies.
8 """
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)
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")
25 # If possible, we write both of these on the same line:
26 # -x turn on expert mode
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)
57 # list of directory options to offer in configure
59 # 'STD-PATH' - the default path without --enable-fhs
60 # 'FHS-PATH' - the default path with --enable-fhs
62 # 'OPTION' - the configure option to overwrite the default (optional)
63 # 'HELPTEXT' - the help text of the configure option (optional)
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)
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)
73 dynconfig = {
74 'BINDIR' : {
75 'STD-PATH': '${BINDIR}',
76 'FHS-PATH': '${BINDIR}',
77 'OVERWRITE': True,
79 'SBINDIR' : {
80 'STD-PATH': '${SBINDIR}',
81 'FHS-PATH': '${SBINDIR}',
82 'OVERWRITE': True,
84 'LIBDIR' : {
85 'STD-PATH': '${LIBDIR}',
86 'FHS-PATH': '${LIBDIR}',
87 'OVERWRITE': True,
89 'LIBEXECDIR' : {
90 'STD-PATH': '${LIBEXECDIR}',
91 'FHS-PATH': '${LIBEXECDIR}',
92 'OVERWRITE': True,
94 'DATADIR' : {
95 'STD-PATH': '${DATADIR}',
96 'FHS-PATH': '${DATADIR}',
97 'OVERWRITE': True,
99 'LOCALEDIR' : {
100 'STD-PATH': '${LOCALEDIR}',
101 'FHS-PATH': '${LOCALEDIR}',
102 'OVERWRITE': True,
104 'PYTHONDIR' : {
105 'STD-PATH': '${PYTHONDIR}',
106 'FHS-PATH': '${PYTHONDIR}',
107 'OVERWRITE': True,
109 'PYTHONARCHDIR' : {
110 'STD-PATH': '${PYTHONARCHDIR}',
111 'FHS-PATH': '${PYTHONARCHDIR}',
112 'OVERWRITE': True,
114 'PERL_LIB_INSTALL_DIR' : {
115 'STD-PATH': '${PERL_LIB_INSTALL_DIR}',
116 'FHS-PATH': '${PERL_LIB_INSTALL_DIR}',
117 'OVERWRITE': True,
119 'PERL_ARCH_INSTALL_DIR' : {
120 'STD-PATH': '${PERL_ARCH_INSTALL_DIR}',
121 'FHS-PATH': '${PERL_ARCH_INSTALL_DIR}',
122 'OVERWRITE': True,
124 'INCLUDEDIR' : {
125 'STD-PATH': '${INCLUDEDIR}',
126 'FHS-PATH': '${INCLUDEDIR}/samba-4.0',
127 'OVERWRITE': True,
129 'SCRIPTSBINDIR' : {
130 'STD-PATH': '${SBINDIR}',
131 'FHS-PATH': '${SBINDIR}',
133 'SETUPDIR' : {
134 'STD-PATH': '${DATADIR}/setup',
135 'FHS-PATH': '${DATADIR}/samba/setup',
137 'PKGCONFIGDIR' : {
138 'STD-PATH': '${LIBDIR}/pkgconfig',
139 'FHS-PATH': '${LIBDIR}/pkgconfig',
141 'SWATDIR' : {
142 'STD-PATH': '${DATADIR}/swat',
143 'FHS-PATH': '${DATADIR}/samba/swat',
145 'CODEPAGEDIR' : {
146 'STD-PATH': '${DATADIR}/codepages',
147 'FHS-PATH': '${DATADIR}/samba/codepages',
149 'PRIVATELIBDIR' : {
150 'STD-PATH': '${LIBDIR}/private',
151 'FHS-PATH': '${LIBDIR}/samba',
152 'OPTION': '--with-privatelibdir',
153 'HELPTEXT': 'Which directory to use for private Samba libraries',
154 'OVERWRITE': True,
156 'MODULESDIR' : {
157 'STD-PATH': '${LIBDIR}',
158 'FHS-PATH': '${LIBDIR}/samba',
159 'OPTION': '--with-modulesdir',
160 'HELPTEXT': 'Which directory to use for Samba modules',
161 'OVERWRITE': True,
163 'PAMMODULESDIR' : {
164 'STD-PATH': '${LIBDIR}/security',
165 'FHS-PATH': '${LIBDIR}/security',
166 'OPTION': '--with-pammodulesdir',
167 'HELPTEXT': 'Which directory to use for PAM modules',
169 'CONFIGDIR' : {
170 'STD-PATH': '${SYSCONFDIR}',
171 'FHS-PATH': '${SYSCONFDIR}/samba',
172 'OPTION': '--with-configdir',
173 'HELPTEXT': 'Where to put configuration files',
175 'PRIVATE_DIR' : {
176 'STD-PATH': '${PREFIX}/private',
177 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/private',
178 'OPTION': '--with-privatedir',
179 'HELPTEXT': 'Where to put sam.ldb and other private files',
181 'LOCKDIR' : {
182 'STD-PATH': '${LOCALSTATEDIR}/lock',
183 'FHS-PATH': '${LOCALSTATEDIR}/lock/samba',
184 'OPTION': '--with-lockdir',
185 'HELPTEXT': 'Where to put short term disposable state files',
187 'PIDDIR' : {
188 'STD-PATH': '${LOCALSTATEDIR}/run',
189 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
190 'OPTION': '--with-piddir',
191 'HELPTEXT': 'Where to put pid files',
193 'STATEDIR' : {
194 'STD-PATH': '${LOCALSTATEDIR}/locks',
195 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
196 'OPTION': '--with-statedir',
197 'HELPTEXT': 'Where to put persistent state files',
199 'CACHEDIR' : {
200 'STD-PATH': '${LOCALSTATEDIR}/cache',
201 'FHS-PATH': '${LOCALSTATEDIR}/cache/samba',
202 'OPTION': '--with-cachedir',
203 'HELPTEXT': 'Where to put temporary cache files',
205 'LOGFILEBASE' : {
206 'STD-PATH': '${LOCALSTATEDIR}',
207 'FHS-PATH': '${LOCALSTATEDIR}/log/samba',
208 'OPTION': '--with-logfilebase',
209 'HELPTEXT': 'Where to put log files',
211 'SOCKET_DIR' : {
212 'STD-PATH': '${LOCALSTATEDIR}/run',
213 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
214 'OPTION': '--with-sockets-dir',
215 'HELPTEXT': 'socket directory',
217 'PRIVILEGED_SOCKET_DIR' : {
218 'STD-PATH': '${LOCALSTATEDIR}/lib',
219 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
220 'OPTION': '--with-privileged-socket-dir',
221 'HELPTEXT': 'privileged socket directory',
223 'WINBINDD_SOCKET_DIR' : {
224 'STD-PATH': '${SOCKET_DIR}/winbindd',
225 'FHS-PATH': '${SOCKET_DIR}/winbindd',
226 'DELAY': True,
228 'WINBINDD_PRIVILEGED_SOCKET_DIR' : {
229 'STD-PATH': '${PRIVILEGED_SOCKET_DIR}/winbindd_privileged',
230 'FHS-PATH': '${PRIVILEGED_SOCKET_DIR}/winbindd_privileged',
231 'DELAY': True,
233 'NMBDSOCKETDIR' : {
234 'STD-PATH': '${SOCKET_DIR}/nmbd',
235 'FHS-PATH': '${SOCKET_DIR}/nmbd',
236 'DELAY': True,
238 'NTP_SIGND_SOCKET_DIR' : {
239 'STD-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
240 'FHS-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
241 'DELAY': True,
243 'NCALRPCDIR' : {
244 'STD-PATH': '${SOCKET_DIR}/ncalrpc',
245 'FHS-PATH': '${SOCKET_DIR}/ncalrpc',
246 'DELAY': True,
248 'CONFIGFILE' : {
249 'STD-PATH': '${CONFIGDIR}/smb.conf',
250 'FHS-PATH': '${CONFIGDIR}/smb.conf',
251 'DELAY': True,
253 'LMHOSTSFILE' : {
254 'STD-PATH': '${CONFIGDIR}/lmhosts',
255 'FHS-PATH': '${CONFIGDIR}/lmhosts',
256 'DELAY': True,
258 'SMB_PASSWD_FILE' : {
259 'STD-PATH': '${PRIVATE_DIR}/smbpasswd',
260 'FHS-PATH': '${PRIVATE_DIR}/smbpasswd',
261 'DELAY': True,
265 def set_options(opt):
266 opt.parser.formatter = SambaIndentedHelpFormatter()
267 opt.parser.formatter.width=Utils.get_term_cols()
269 for k in ('--with-privatelibdir', '--with-modulesdir'):
270 option = opt.parser.get_option(k)
271 if option:
272 opt.parser.remove_option(k)
273 del opt.parser.defaults['PRIVATELIBDIR']
274 del opt.parser.defaults['MODULESDIR']
276 # get all the basic GNU options from the gnu_dirs tool
278 opt_group=opt.add_option_group('Samba-specific directory layout','')
280 fhs_help = "Use FHS-compliant paths (default no)\n"
281 fhs_help += "You should consider using this together with:\n"
282 fhs_help += "--prefix=/usr --sysconfdir=/etc --localstatedir=/var"
283 opt_group.add_option('--enable-fhs', help=fhs_help,
284 action="store_true", dest='ENABLE_FHS', default=False)
286 for varname in dynconfig.keys():
287 if 'OPTION' not in dynconfig[varname]:
288 continue
289 opt = dynconfig[varname]['OPTION']
290 if 'HELPTEXT' in dynconfig[varname]:
291 txt = dynconfig[varname]['HELPTEXT']
292 else:
293 txt = "dynconfig path %s" % (varname)
294 def_std = dynconfig[varname]['STD-PATH']
295 def_fhs = dynconfig[varname]['FHS-PATH']
297 help = "%s\n[STD-Default: %s]\n[FHS-Default: %s]" % (txt, def_std, def_fhs)
298 opt_group.add_option(opt, help=help, dest=varname, action="store")
300 def configure(conf):
301 # get all the basic GNU options from the gnu_dirs tool
303 if Options.options.ENABLE_FHS:
304 flavor = 'FHS-PATH'
305 else:
306 flavor = 'STD-PATH'
307 if conf.env.PREFIX == '/usr' or conf.env.PREFIX == '/usr/local':
308 Logs.error("Don't install directly under /usr or /usr/local without using the FHS option (--enable-fhs)")
309 raise Utils.WafError("ERROR: invalid --prefix=%s value" % (conf.env.PREFIX))
311 explicit_set ={}
313 dyn_vars = {}
314 for varname in dynconfig.keys():
315 dyn_vars[varname] = dynconfig[varname][flavor]
316 if 'OVERWRITE' in dynconfig[varname] and dynconfig[varname]['OVERWRITE']:
317 # we may overwrite this option
318 continue
319 conf.ASSERT(varname not in conf.env, "Variable %s already defined" % varname)
321 # the explicit block
322 for varname in dynconfig.keys():
323 if 'OPTION' not in dynconfig[varname]:
324 continue
325 value = getattr(Options.options, varname, None)
326 if value is None:
327 continue
328 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
329 conf.env[varname] = value
330 # mark it as explicit from the command line
331 explicit_set[varname] = value
333 # defaults stage 1 after the explicit block
334 for varname in dynconfig.keys():
335 if 'DELAY' in dynconfig[varname] and dynconfig[varname]['DELAY']:
336 # this option referrs to other options,
337 # so it needs to wait for stage 2.
338 continue
339 value = EXPAND_VARIABLES(conf, dyn_vars[varname])
340 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
341 if varname not in explicit_set:
342 # only overwrite if not specified explicitly on the command line
343 conf.env[varname] = value
345 # defaults stage 2 after the explicit block
346 for varname in dynconfig.keys():
347 if 'DELAY' not in dynconfig[varname] or not dynconfig[varname]['DELAY']:
348 # this option was already handled in stage 1.
349 continue
350 value = EXPAND_VARIABLES(conf, dyn_vars[varname])
351 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
352 if varname not in explicit_set:
353 # only overwrite if not specified explicitly on the command line
354 conf.env[varname] = value
356 # display the expanded pathes for the user
357 for varname in dynconfig.keys():
358 value = conf.env[varname]
359 conf.start_msg("Dynconfig[%s]: " % (varname))
360 conf.end_msg("'%s'" % (value), 'GREEN')
362 def get_override(bld):
363 override = { 'MODULESDIR' : 'bin/modules',
364 'PYTHONDIR' : 'bin/python',
365 'PYTHONARCHDIR' : 'bin/python',
366 'BINDIR' : 'bin',
367 'SBINDIR' : 'bin',
368 'CODEPAGEDIR' : 'codepages',
369 'SCRIPTSBINDIR' : 'source4/scripting/bin',
370 'SETUPDIR' : 'source4/setup'
372 return override
374 def dynconfig_cflags(bld, list=None):
375 '''work out the extra CFLAGS for dynconfig.c'''
376 cflags = []
377 for varname in dynconfig.keys():
378 if list and not varname in list:
379 continue
380 value = bld.env[varname]
381 if not Options.is_install:
382 override = get_override(bld)
383 if varname in override:
384 value = os.path.join(bld.env.srcdir, override[varname])
385 cflags.append('-D%s="%s"' % (varname, value))
386 return cflags
387 Build.BuildContext.dynconfig_cflags = dynconfig_cflags
389 def dynconfig_varnames(bld, list=None):
390 '''work out the dynconfig variables'''
391 varnames = []
392 for varname in dynconfig.keys():
393 if list and not varname in list:
394 continue
395 varnames.append(varname)
396 return varnames
397 Build.BuildContext.dynconfig_varnames = dynconfig_varnames
399 def pathconfig_entities(bld, list=None):
400 '''work out the extra entities for the docs'''
401 entities = []
402 for varname in dynconfig.keys():
403 if list and not varname in list:
404 continue
405 value = bld.env[varname]
406 if not Options.is_install:
407 override = get_override(bld)
408 if varname in override:
409 value = os.path.join(bld.env.srcdir, override[varname])
410 entities.append("<!ENTITY pathconfig.%s '%s'>" % (varname, value))
411 return entities
412 Build.BuildContext.pathconfig_entities = pathconfig_entities
414 def build(bld):
415 cflags = bld.dynconfig_cflags()
416 version_header = 'version.h'
417 bld.SAMBA_SUBSYSTEM('DYNCONFIG',
418 'dynconfig.c',
419 deps='replace talloc',
420 public_headers=os_path_relpath(os.path.join(Options.launch_dir, version_header), bld.curdir),
421 header_path='samba',
422 cflags=cflags)
424 # install some extra empty directories
425 bld.INSTALL_DIRS("", "${CONFIGDIR} ${PRIVATE_DIR} ${LOGFILEBASE}");
426 bld.INSTALL_DIRS("", "${PRIVATE_DIR} ${PRIVILEGED_SOCKET_DIR}")
427 bld.INSTALL_DIRS("", "${STATEDIR} ${CACHEDIR}");
429 # these might be on non persistent storage
430 bld.INSTALL_DIRS("", "${LOCKDIR} ${PIDDIR} ${SOCKET_DIR}")