smbd: Remove "st" from struct open_symlink_err
[Samba.git] / dynconfig / wscript
blob2041d881546f291a0431aa75711e97c1a1d009ea
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 '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 'LDBMODULESDIR' : {
174 'STD-PATH': '${MODULESDIR}/ldb',
175 'FHS-PATH': '${MODULESDIR}/ldb',
176 'OPTION': '--with-ldbmodulesdir',
177 'HELPTEXT': 'Which directory to use for LDB modules',
178 'DELAY': True,
180 'PAMMODULESDIR' : {
181 'STD-PATH': '${LIBDIR}/security',
182 'FHS-PATH': '${LIBDIR}/security',
183 'OPTION': '--with-pammodulesdir',
184 'HELPTEXT': 'Which directory to use for PAM modules',
186 'CONFIGDIR' : {
187 'STD-PATH': '${SYSCONFDIR}',
188 'FHS-PATH': '${SYSCONFDIR}/samba',
189 'OPTION': '--with-configdir',
190 'HELPTEXT': 'Where to put configuration files',
192 'PRIVATE_DIR' : {
193 'STD-PATH': '${PREFIX}/private',
194 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/private',
195 'OPTION': '--with-privatedir',
196 'HELPTEXT': 'Where to put sam.ldb and other private files',
198 'BINDDNS_DIR' : {
199 'STD-PATH': '${PREFIX}/bind-dns',
200 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/bind-dns',
201 'OPTION': '--with-bind-dns-dir',
202 'HELPTEXT': 'bind-dns config directory',
204 'LOCKDIR' : {
205 'STD-PATH': '${LOCALSTATEDIR}/lock',
206 'FHS-PATH': '${LOCALSTATEDIR}/lock/samba',
207 'OPTION': '--with-lockdir',
208 'HELPTEXT': 'Where to put short term disposable state files',
210 'PIDDIR' : {
211 'STD-PATH': '${LOCALSTATEDIR}/run',
212 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
213 'OPTION': '--with-piddir',
214 'HELPTEXT': 'Where to put pid files',
216 'STATEDIR' : {
217 'STD-PATH': '${LOCALSTATEDIR}/locks',
218 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
219 'OPTION': '--with-statedir',
220 'HELPTEXT': 'Where to put persistent state files',
222 'CACHEDIR' : {
223 'STD-PATH': '${LOCALSTATEDIR}/cache',
224 'FHS-PATH': '${LOCALSTATEDIR}/cache/samba',
225 'OPTION': '--with-cachedir',
226 'HELPTEXT': 'Where to put temporary cache files',
228 'LOGFILEBASE' : {
229 'STD-PATH': '${LOCALSTATEDIR}',
230 'FHS-PATH': '${LOCALSTATEDIR}/log/samba',
231 'OPTION': '--with-logfilebase',
232 'HELPTEXT': 'Where to put log files',
234 'SOCKET_DIR' : {
235 'STD-PATH': '${LOCALSTATEDIR}/run',
236 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
237 'OPTION': '--with-sockets-dir',
238 'HELPTEXT': 'socket directory',
240 'PRIVILEGED_SOCKET_DIR' : {
241 'STD-PATH': '${LOCALSTATEDIR}/lib',
242 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
243 'OPTION': '--with-privileged-socket-dir',
244 'HELPTEXT': 'privileged socket directory',
246 'WINBINDD_SOCKET_DIR' : {
247 'STD-PATH': '${SOCKET_DIR}/winbindd',
248 'FHS-PATH': '${SOCKET_DIR}/winbindd',
249 'DELAY': True,
251 'NMBDSOCKETDIR' : {
252 'STD-PATH': '${SOCKET_DIR}/nmbd',
253 'FHS-PATH': '${SOCKET_DIR}/nmbd',
254 'DELAY': True,
256 'NTP_SIGND_SOCKET_DIR' : {
257 'STD-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
258 'FHS-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
259 'DELAY': True,
261 'NCALRPCDIR' : {
262 'STD-PATH': '${SOCKET_DIR}/ncalrpc',
263 'FHS-PATH': '${SOCKET_DIR}/ncalrpc',
264 'DELAY': True,
266 'CONFIGFILE' : {
267 'STD-PATH': '${CONFIGDIR}/smb.conf',
268 'FHS-PATH': '${CONFIGDIR}/smb.conf',
269 'DELAY': True,
271 'LMHOSTSFILE' : {
272 'STD-PATH': '${CONFIGDIR}/lmhosts',
273 'FHS-PATH': '${CONFIGDIR}/lmhosts',
274 'DELAY': True,
276 'SMB_PASSWD_FILE' : {
277 'STD-PATH': '${PRIVATE_DIR}/smbpasswd',
278 'FHS-PATH': '${PRIVATE_DIR}/smbpasswd',
279 'OPTION': '--with-smbpasswd-file',
280 'HELPTEXT': 'Where to put the smbpasswd file',
281 'DELAY': True,
285 def options(opt):
286 opt.parser.formatter = SambaIndentedHelpFormatter()
287 opt.parser.formatter.width=Logs.get_term_cols()
289 for k in ('--with-privatelibdir', '--with-modulesdir'):
290 option = opt.parser.get_option(k)
291 if option:
292 opt.parser.remove_option(k)
293 del opt.parser.defaults['PRIVATELIBDIR']
294 del opt.parser.defaults['MODULESDIR']
296 # get all the basic GNU options from the gnu_dirs tool
298 opt_group=opt.add_option_group('Samba-specific directory layout','')
300 fhs_help = "Use FHS-compliant paths (default no)\n"
301 fhs_help += "You should consider using this together with:\n"
302 fhs_help += "--prefix=/usr --sysconfdir=/etc --localstatedir=/var"
303 opt_group.add_option('--enable-fhs', help=fhs_help,
304 action="store_true", dest='ENABLE_FHS', default=False)
306 for varname in dynconfig.keys():
307 if 'OPTION' not in dynconfig[varname]:
308 continue
309 opt = dynconfig[varname]['OPTION']
310 if 'HELPTEXT' in dynconfig[varname]:
311 txt = dynconfig[varname]['HELPTEXT']
312 else:
313 txt = "dynconfig path %s" % (varname)
314 def_std = dynconfig[varname]['STD-PATH']
315 def_fhs = dynconfig[varname]['FHS-PATH']
317 help = "%s\n[STD-Default: %s]\n[FHS-Default: %s]" % (txt, def_std, def_fhs)
318 opt_group.add_option(opt, help=help, dest=varname, action="store")
320 def configure(conf):
321 # get all the basic GNU options from the gnu_dirs tool
323 if Options.options.ENABLE_FHS:
324 flavor = 'FHS-PATH'
325 else:
326 flavor = 'STD-PATH'
327 if conf.env.PREFIX == '/usr' or conf.env.PREFIX == '/usr/local':
328 Logs.error("Don't install directly under /usr or /usr/local without using the FHS option (--enable-fhs)")
329 raise Errors.WafError("ERROR: invalid --prefix=%s value" % (conf.env.PREFIX))
331 explicit_set ={}
333 dyn_vars = {}
334 for varname in dynconfig.keys():
335 dyn_vars[varname] = dynconfig[varname][flavor]
336 if 'OVERWRITE' in dynconfig[varname] and dynconfig[varname]['OVERWRITE']:
337 # we may overwrite this option
338 continue
339 conf.ASSERT(varname not in conf.env, "Variable %s already defined" % varname)
341 # the explicit block
342 for varname in dynconfig.keys():
343 if 'OPTION' not in dynconfig[varname]:
344 continue
345 value = getattr(Options.options, varname, None)
346 if value is None:
347 continue
348 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
349 conf.env[varname] = value
350 # mark it as explicit from the command line
351 explicit_set[varname] = value
353 # defaults stage 1 after the explicit block
354 for varname in dynconfig.keys():
355 if 'DELAY' in dynconfig[varname] and dynconfig[varname]['DELAY']:
356 # this option refers to other options,
357 # so it needs to wait for stage 2.
358 continue
359 value = EXPAND_VARIABLES(conf, dyn_vars[varname])
360 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
361 if varname not in explicit_set:
362 # only overwrite if not specified explicitly on the command line
363 conf.env[varname] = value
365 # defaults stage 2 after the explicit block
366 for varname in dynconfig.keys():
367 if 'DELAY' not in dynconfig[varname] or not dynconfig[varname]['DELAY']:
368 # this option was already handled in stage 1.
369 continue
370 value = EXPAND_VARIABLES(conf, dyn_vars[varname])
371 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
372 if varname not in explicit_set:
373 # only overwrite if not specified explicitly on the command line
374 conf.env[varname] = value
376 # display the expanded paths for the user
377 for varname in dynconfig.keys():
378 value = conf.env[varname]
379 conf.start_msg("Dynconfig[%s]: " % (varname))
380 conf.end_msg("'%s'" % (value), 'GREEN')
382 def get_override(bld):
383 override = { 'MODULESDIR' : 'bin/modules',
384 'PYTHONDIR' : 'bin/python',
385 'PYTHONARCHDIR' : 'bin/python',
386 'BINDIR' : 'bin',
387 'SBINDIR' : 'bin',
388 'LIBEXECDIR' : 'bin',
389 'SAMBA_LIBEXECDIR' : 'bin',
390 'CODEPAGEDIR' : 'codepages',
391 'SCRIPTSBINDIR' : 'source4/scripting/bin',
392 'SETUPDIR' : 'source4/setup'
394 return override
396 def dynconfig_cflags(bld, list=None):
397 '''work out the extra CFLAGS for dynconfig.c'''
398 cflags = []
399 for varname in dynconfig.keys():
400 if list and not varname in list:
401 continue
402 value = bld.env[varname]
403 if not bld.is_install:
404 override = get_override(bld)
405 if varname in override:
406 value = os.path.join(bld.env.srcdir, override[varname])
407 cflags.append('-D%s="%s"' % (varname, value))
408 return cflags
409 Build.BuildContext.dynconfig_cflags = dynconfig_cflags
411 def dynconfig_varnames(bld, list=None):
412 '''work out the dynconfig variables'''
413 varnames = []
414 for varname in dynconfig.keys():
415 if list and not varname in list:
416 continue
417 varnames.append(varname)
418 return varnames
419 Build.BuildContext.dynconfig_varnames = dynconfig_varnames
421 def pathconfig_entities(bld, list=None):
422 '''work out the extra entities for the docs'''
423 entities = []
424 for varname in dynconfig.keys():
425 if list and not varname in list:
426 continue
427 value = bld.env[varname]
428 if not bld.is_install:
429 override = get_override(bld)
430 if varname in override:
431 value = os.path.join(bld.env.srcdir, override[varname])
432 entities.append("<!ENTITY pathconfig.%s '%s'>" % (varname, value))
433 return entities
434 Build.BuildContext.pathconfig_entities = pathconfig_entities
436 def build(bld):
437 cflags = bld.dynconfig_cflags()
438 version_header = 'version.h'
439 bld.SAMBA_SUBSYSTEM('DYNCONFIG',
440 'dynconfig.c',
441 deps='replace',
442 public_headers=os.path.relpath(os.path.join(Context.launch_dir, version_header), bld.path.abspath()),
443 header_path='samba',
444 cflags=cflags)
446 # install some extra empty directories
447 bld.INSTALL_DIR("${CONFIGDIR}")
448 bld.INSTALL_DIR("${LOGFILEBASE}")
449 bld.INSTALL_DIR("${PRIVILEGED_SOCKET_DIR}")
450 bld.INSTALL_DIR("${PRIVATE_DIR}", 0o700)
451 bld.INSTALL_DIR("${BINDDNS_DIR}", 0o770)
452 bld.INSTALL_DIR("${STATEDIR}")
453 bld.INSTALL_DIR("${CACHEDIR}")
455 # these might be on non persistent storage
456 bld.INSTALL_DIRS("", "${LOCKDIR} ${PIDDIR} ${SOCKET_DIR}")