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