s4:dns_server: remove wrong and unused dsdb_check_access_on_dn() check
[Samba.git] / dynconfig / wscript
blob44e8f19f73278bc653875cfbef8e2dc8b3da4f47
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 'INCLUDEDIR' : {
115 'STD-PATH': '${INCLUDEDIR}',
116 'FHS-PATH': '${INCLUDEDIR}/samba-4.0',
117 'OVERWRITE': True,
119 'SCRIPTSBINDIR' : {
120 'STD-PATH': '${SBINDIR}',
121 'FHS-PATH': '${SBINDIR}',
123 'SETUPDIR' : {
124 'STD-PATH': '${DATADIR}/setup',
125 'FHS-PATH': '${DATADIR}/samba/setup',
127 'PKGCONFIGDIR' : {
128 'STD-PATH': '${LIBDIR}/pkgconfig',
129 'FHS-PATH': '${LIBDIR}/pkgconfig',
131 'SWATDIR' : {
132 'STD-PATH': '${DATADIR}/swat',
133 'FHS-PATH': '${DATADIR}/samba/swat',
135 'CODEPAGEDIR' : {
136 'STD-PATH': '${DATADIR}/codepages',
137 'FHS-PATH': '${DATADIR}/samba/codepages',
139 'PRIVATELIBDIR' : {
140 'STD-PATH': '${LIBDIR}/private',
141 'FHS-PATH': '${LIBDIR}/samba',
142 'OPTION': '--with-privatelibdir',
143 'HELPTEXT': 'Which directory to use for private Samba libraries',
144 'OVERWRITE': True,
146 'MODULESDIR' : {
147 'STD-PATH': '${LIBDIR}',
148 'FHS-PATH': '${LIBDIR}/samba',
149 'OPTION': '--with-modulesdir',
150 'HELPTEXT': 'Which directory to use for Samba modules',
151 'OVERWRITE': True,
153 'PAMMODULESDIR' : {
154 'STD-PATH': '${LIBDIR}/security',
155 'FHS-PATH': '${LIBDIR}/security',
156 'OPTION': '--with-pammodulesdir',
157 'HELPTEXT': 'Which directory to use for PAM modules',
159 'CONFIGDIR' : {
160 'STD-PATH': '${SYSCONFDIR}',
161 'FHS-PATH': '${SYSCONFDIR}/samba',
162 'OPTION': '--with-configdir',
163 'HELPTEXT': 'Where to put configuration files',
165 'PRIVATE_DIR' : {
166 'STD-PATH': '${PREFIX}/private',
167 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/private',
168 'OPTION': '--with-privatedir',
169 'HELPTEXT': 'Where to put sam.ldb and other private files',
171 'LOCKDIR' : {
172 'STD-PATH': '${LOCALSTATEDIR}/lock',
173 'FHS-PATH': '${LOCALSTATEDIR}/lock/samba',
174 'OPTION': '--with-lockdir',
175 'HELPTEXT': 'Where to put short term disposable state files',
177 'PIDDIR' : {
178 'STD-PATH': '${LOCALSTATEDIR}/run',
179 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
180 'OPTION': '--with-piddir',
181 'HELPTEXT': 'Where to put pid files',
183 'STATEDIR' : {
184 'STD-PATH': '${LOCALSTATEDIR}/locks',
185 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
186 'OPTION': '--with-statedir',
187 'HELPTEXT': 'Where to put persistent state files',
189 'CACHEDIR' : {
190 'STD-PATH': '${LOCALSTATEDIR}/cache',
191 'FHS-PATH': '${LOCALSTATEDIR}/cache/samba',
192 'OPTION': '--with-cachedir',
193 'HELPTEXT': 'Where to put temporary cache files',
195 'LOGFILEBASE' : {
196 'STD-PATH': '${LOCALSTATEDIR}',
197 'FHS-PATH': '${LOCALSTATEDIR}/log/samba',
198 'OPTION': '--with-logfilebase',
199 'HELPTEXT': 'Where to put log files',
201 'SOCKET_DIR' : {
202 'STD-PATH': '${LOCALSTATEDIR}/run',
203 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
204 'OPTION': '--with-sockets-dir',
205 'HELPTEXT': 'socket directory',
207 'PRIVILEGED_SOCKET_DIR' : {
208 'STD-PATH': '${LOCALSTATEDIR}/lib',
209 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
210 'OPTION': '--with-privileged-socket-dir',
211 'HELPTEXT': 'privileged socket directory',
213 'WINBINDD_SOCKET_DIR' : {
214 'STD-PATH': '${SOCKET_DIR}/winbindd',
215 'FHS-PATH': '${SOCKET_DIR}/winbindd',
216 'DELAY': True,
218 'WINBINDD_PRIVILEGED_SOCKET_DIR' : {
219 'STD-PATH': '${PRIVILEGED_SOCKET_DIR}/winbindd_privileged',
220 'FHS-PATH': '${PRIVILEGED_SOCKET_DIR}/winbindd_privileged',
221 'DELAY': True,
223 'NMBDSOCKETDIR' : {
224 'STD-PATH': '${SOCKET_DIR}/nmbd',
225 'FHS-PATH': '${SOCKET_DIR}/nmbd',
226 'DELAY': True,
228 'NTP_SIGND_SOCKET_DIR' : {
229 'STD-PATH': '${SOCKET_DIR}/ntp_signd',
230 'FHS-PATH': '${SOCKET_DIR}/ntp_signd',
231 'DELAY': True,
233 'NCALRPCDIR' : {
234 'STD-PATH': '${SOCKET_DIR}/ncalrpc',
235 'FHS-PATH': '${SOCKET_DIR}/ncalrpc',
236 'DELAY': True,
238 'CONFIGFILE' : {
239 'STD-PATH': '${CONFIGDIR}/smb.conf',
240 'FHS-PATH': '${CONFIGDIR}/smb.conf',
241 'DELAY': True,
243 'LMHOSTSFILE' : {
244 'STD-PATH': '${CONFIGDIR}/lmhosts',
245 'FHS-PATH': '${CONFIGDIR}/lmhosts',
246 'DELAY': True,
248 'SMB_PASSWD_FILE' : {
249 'STD-PATH': '${PRIVATE_DIR}/smbpasswd',
250 'FHS-PATH': '${PRIVATE_DIR}/smbpasswd',
251 'DELAY': True,
255 def set_options(opt):
256 opt.parser.formatter = SambaIndentedHelpFormatter()
257 opt.parser.formatter.width=Utils.get_term_cols()
259 for k in ('--with-privatelibdir', '--with-modulesdir'):
260 option = opt.parser.get_option(k)
261 if option:
262 opt.parser.remove_option(k)
263 del opt.parser.defaults['PRIVATELIBDIR']
264 del opt.parser.defaults['MODULESDIR']
266 # get all the basic GNU options from the gnu_dirs tool
268 opt_group=opt.add_option_group('Samba-specific directory layout','')
270 fhs_help = "Use FHS-compliant paths (default no)\n"
271 fhs_help += "You should consider using this together with:\n"
272 fhs_help += "--prefix=/usr --sysconfdir=/etc --localstatedir=/var"
273 opt_group.add_option('--enable-fhs', help=fhs_help,
274 action="store_true", dest='ENABLE_FHS', default=False)
276 for varname in dynconfig.keys():
277 if 'OPTION' not in dynconfig[varname]:
278 continue
279 opt = dynconfig[varname]['OPTION']
280 if 'HELPTEXT' in dynconfig[varname]:
281 txt = dynconfig[varname]['HELPTEXT']
282 else:
283 txt = "dynconfig path %s" % (varname)
284 def_std = dynconfig[varname]['STD-PATH']
285 def_fhs = dynconfig[varname]['FHS-PATH']
287 help = "%s\n[STD-Default: %s]\n[FHS-Default: %s]" % (txt, def_std, def_fhs)
288 opt_group.add_option(opt, help=help, dest=varname, action="store")
290 def configure(conf):
291 # get all the basic GNU options from the gnu_dirs tool
293 if Options.options.ENABLE_FHS:
294 flavor = 'FHS-PATH'
295 else:
296 flavor = 'STD-PATH'
297 if conf.env.PREFIX == '/usr' or conf.env.PREFIX == '/usr/local':
298 Logs.error("Don't install directly under /usr or /usr/local without using the FHS option (--enable-fhs)")
299 raise Utils.WafError("ERROR: invalid --prefix=%s value" % (conf.env.PREFIX))
301 explicit_set ={}
303 dyn_vars = {}
304 for varname in dynconfig.keys():
305 dyn_vars[varname] = dynconfig[varname][flavor]
306 if 'OVERWRITE' in dynconfig[varname] and dynconfig[varname]['OVERWRITE']:
307 # we may overwrite this option
308 continue
309 conf.ASSERT(varname not in conf.env, "Variable %s already defined" % varname)
311 # the explicit block
312 for varname in dynconfig.keys():
313 if 'OPTION' not in dynconfig[varname]:
314 continue
315 value = getattr(Options.options, varname, None)
316 if value is None:
317 continue
318 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
319 conf.env[varname] = value
320 # mark it as explicit from the command line
321 explicit_set[varname] = value
323 # defaults stage 1 after the explicit block
324 for varname in dynconfig.keys():
325 if 'DELAY' in dynconfig[varname] and dynconfig[varname]['DELAY']:
326 # this option referrs to other options,
327 # so it needs to wait for stage 2.
328 continue
329 value = EXPAND_VARIABLES(conf, dyn_vars[varname])
330 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
331 if varname not in explicit_set:
332 # only overwrite if not specified explicitly on the command line
333 conf.env[varname] = value
335 # defaults stage 2 after the explicit block
336 for varname in dynconfig.keys():
337 if 'DELAY' not in dynconfig[varname] or not dynconfig[varname]['DELAY']:
338 # this option was already handled in stage 1.
339 continue
340 value = EXPAND_VARIABLES(conf, dyn_vars[varname])
341 conf.ASSERT(value != '', "Empty dynconfig value for %s" % varname)
342 if varname not in explicit_set:
343 # only overwrite if not specified explicitly on the command line
344 conf.env[varname] = value
346 # display the expanded pathes for the user
347 for varname in dynconfig.keys():
348 value = conf.env[varname]
349 conf.start_msg("Dynconfig[%s]: " % (varname))
350 conf.end_msg("'%s'" % (value), 'GREEN')
352 def dynconfig_cflags(bld, list=None):
353 '''work out the extra CFLAGS for dynconfig.c'''
354 cflags = []
355 # override some paths when running from the build directory
356 override = { 'MODULESDIR' : 'bin/modules',
357 'PYTHONDIR' : 'bin/python',
358 'PYTHONARCHDIR' : 'bin/python',
359 'BINDIR' : 'bin',
360 'SBINDIR' : 'bin',
361 'CODEPAGEDIR' : os.path.join(bld.env.srcdir, 'codepages'),
362 'SCRIPTSBINDIR' : os.path.join(bld.env.srcdir, 'source4/scripting/bin'),
363 'SETUPDIR' : os.path.join(bld.env.srcdir, 'source4/setup') }
364 for varname in dynconfig.keys():
365 if list and not varname in list:
366 continue
367 value = bld.env[varname]
368 if not Options.is_install:
369 if varname in override:
370 value = os.path.join(os.getcwd(), override[varname])
371 cflags.append('-D%s="%s"' % (varname, value))
372 return cflags
373 Build.BuildContext.dynconfig_cflags = dynconfig_cflags
375 def build(bld):
376 cflags = bld.dynconfig_cflags()
377 version_header = 'version.h'
378 bld.SAMBA_SUBSYSTEM('DYNCONFIG',
379 'dynconfig.c',
380 deps='replace talloc',
381 public_headers=os_path_relpath(os.path.join(Options.launch_dir, version_header), bld.curdir),
382 header_path='samba',
383 cflags=cflags)
385 # install some extra empty directories
386 bld.INSTALL_DIRS("", "${CONFIGDIR} ${PRIVATE_DIR} ${LOGFILEBASE}");
387 bld.INSTALL_DIRS("", "${PRIVATE_DIR} ${PRIVILEGED_SOCKET_DIR}")
388 bld.INSTALL_DIRS("", "${STATEDIR} ${CACHEDIR}");
390 # these might be on non persistent storage
391 bld.INSTALL_DIRS("", "${LOCKDIR} ${PIDDIR} ${SOCKET_DIR}")