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.
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
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
)
48 help_text
= self
.expand_default(option
)
49 if help_text
.find('\n') == -1:
50 help_lines
= textwrap
.wrap(help_text
, self
.help_width
)
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":
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)
79 'STD-PATH': '${BINDIR}',
80 'FHS-PATH': '${BINDIR}',
84 'STD-PATH': '${SBINDIR}',
85 'FHS-PATH': '${SBINDIR}',
89 'STD-PATH': '${LIBDIR}',
90 'FHS-PATH': '${LIBDIR}',
94 'STD-PATH': '${LIBEXECDIR}',
95 'FHS-PATH': '${LIBEXECDIR}',
98 'SAMBA_LIBEXECDIR' : {
99 'STD-PATH': '${LIBEXECDIR}/samba',
100 'FHS-PATH': '${LIBEXECDIR}/samba',
104 'STD-PATH': '${DATADIR}',
105 'FHS-PATH': '${DATADIR}',
109 'STD-PATH': '${DATADIR}/ctdb',
110 'FHS-PATH': '${DATADIR}/ctdb',
114 'STD-PATH': '${DATADIR}/samba',
115 'FHS-PATH': '${DATADIR}/samba',
119 'STD-PATH': '${LOCALEDIR}',
120 'FHS-PATH': '${LOCALEDIR}',
124 'STD-PATH': '${PYTHONDIR}',
125 'FHS-PATH': '${PYTHONDIR}',
129 'STD-PATH': '${PYTHONARCHDIR}',
130 'FHS-PATH': '${PYTHONARCHDIR}',
133 'PERL_LIB_INSTALL_DIR' : {
134 'STD-PATH': '${PERL_LIB_INSTALL_DIR}',
135 'FHS-PATH': '${PERL_LIB_INSTALL_DIR}',
138 'PERL_ARCH_INSTALL_DIR' : {
139 'STD-PATH': '${PERL_ARCH_INSTALL_DIR}',
140 'FHS-PATH': '${PERL_ARCH_INSTALL_DIR}',
144 'STD-PATH': '${INCLUDEDIR}',
145 'FHS-PATH': '${INCLUDEDIR}/samba-4.0',
149 'STD-PATH': '${SBINDIR}',
150 'FHS-PATH': '${SBINDIR}',
153 'STD-PATH': '${DATADIR}/setup',
154 'FHS-PATH': '${DATADIR}/samba/setup',
157 'STD-PATH': '${LIBDIR}/pkgconfig',
158 'FHS-PATH': '${LIBDIR}/pkgconfig',
161 'STD-PATH': '${DATADIR}/codepages',
162 'FHS-PATH': '${DATADIR}/samba/codepages',
165 'STD-PATH': '${LIBDIR}/private',
166 'FHS-PATH': '${LIBDIR}/samba',
167 'OPTION': '--with-privatelibdir',
168 'HELPTEXT': 'Which directory to use for private Samba libraries',
172 'STD-PATH': '${LIBDIR}',
173 'FHS-PATH': '${LIBDIR}/samba',
174 'OPTION': '--with-modulesdir',
175 'HELPTEXT': 'Which directory to use for Samba modules',
179 'STD-PATH': '${MODULESDIR}/ldb',
180 'FHS-PATH': '${MODULESDIR}/ldb',
181 'OPTION': '--with-ldbmodulesdir',
182 'HELPTEXT': 'Which directory to use for LDB modules',
186 'STD-PATH': '${LIBDIR}/security',
187 'FHS-PATH': '${LIBDIR}/security',
188 'OPTION': '--with-pammodulesdir',
189 'HELPTEXT': 'Which directory to use for PAM modules',
192 'STD-PATH': '${SYSCONFDIR}',
193 'FHS-PATH': '${SYSCONFDIR}/samba',
194 'OPTION': '--with-configdir',
195 'HELPTEXT': 'Where to put configuration files',
198 'STD-PATH': '${PREFIX}/private',
199 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/private',
200 'OPTION': '--with-privatedir',
201 'HELPTEXT': 'Where to put sam.ldb and other private files',
204 'STD-PATH': '${PREFIX}/bind-dns',
205 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/bind-dns',
206 'OPTION': '--with-bind-dns-dir',
207 'HELPTEXT': 'bind-dns config directory',
210 'STD-PATH': '${LOCALSTATEDIR}/lock',
211 'FHS-PATH': '${LOCALSTATEDIR}/lock/samba',
212 'OPTION': '--with-lockdir',
213 'HELPTEXT': 'Where to put short term disposable state files',
216 'STD-PATH': '${LOCALSTATEDIR}/run',
217 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
218 'OPTION': '--with-piddir',
219 'HELPTEXT': 'Where to put pid files',
222 'STD-PATH': '${LOCALSTATEDIR}/locks',
223 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
224 'OPTION': '--with-statedir',
225 'HELPTEXT': 'Where to put persistent state files',
228 'STD-PATH': '${LOCALSTATEDIR}/cache',
229 'FHS-PATH': '${LOCALSTATEDIR}/cache/samba',
230 'OPTION': '--with-cachedir',
231 'HELPTEXT': 'Where to put temporary cache files',
234 'STD-PATH': '${LOCALSTATEDIR}',
235 'FHS-PATH': '${LOCALSTATEDIR}/log/samba',
236 'OPTION': '--with-logfilebase',
237 'HELPTEXT': 'Where to put log files',
240 'STD-PATH': '${LOCALSTATEDIR}/run',
241 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
242 'OPTION': '--with-sockets-dir',
243 'HELPTEXT': 'socket directory',
245 'PRIVILEGED_SOCKET_DIR' : {
246 'STD-PATH': '${LOCALSTATEDIR}/lib',
247 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
248 'OPTION': '--with-privileged-socket-dir',
249 'HELPTEXT': 'privileged socket directory',
251 'WINBINDD_SOCKET_DIR' : {
252 'STD-PATH': '${SOCKET_DIR}/winbindd',
253 'FHS-PATH': '${SOCKET_DIR}/winbindd',
257 'STD-PATH': '${SOCKET_DIR}/nmbd',
258 'FHS-PATH': '${SOCKET_DIR}/nmbd',
261 'NTP_SIGND_SOCKET_DIR' : {
262 'STD-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
263 'FHS-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
267 'STD-PATH': '${SOCKET_DIR}/ncalrpc',
268 'FHS-PATH': '${SOCKET_DIR}/ncalrpc',
272 'STD-PATH': '${CONFIGDIR}/smb.conf',
273 'FHS-PATH': '${CONFIGDIR}/smb.conf',
277 'STD-PATH': '${CONFIGDIR}/lmhosts',
278 'FHS-PATH': '${CONFIGDIR}/lmhosts',
281 'SMB_PASSWD_FILE' : {
282 'STD-PATH': '${PRIVATE_DIR}/smbpasswd',
283 'FHS-PATH': '${PRIVATE_DIR}/smbpasswd',
284 'OPTION': '--with-smbpasswd-file',
285 'HELPTEXT': 'Where to put the smbpasswd file',
288 'HIMMELBLAUD_HSM_PIN_PATH': {
289 'STD-PATH': '${LOCALSTATEDIR}/lib/himmelblaud/hsm-pin',
290 'FHS-PATH': '${LOCALSTATEDIR}/lib/himmelblaud/hsm-pin',
291 'OPTION': '--with-himmelblaud-hsm-pin-path',
292 'HELPTEXT': 'Where to store the hsm pin',
298 opt
.parser
.formatter
= SambaIndentedHelpFormatter()
299 opt
.parser
.formatter
.width
=Logs
.get_term_cols()
301 for k
in ('--with-privatelibdir', '--with-modulesdir'):
302 option
= opt
.parser
.get_option(k
)
304 opt
.parser
.remove_option(k
)
305 del opt
.parser
.defaults
['PRIVATELIBDIR']
306 del opt
.parser
.defaults
['MODULESDIR']
308 # get all the basic GNU options from the gnu_dirs tool
310 opt_group
=opt
.add_option_group('Samba-specific directory layout','')
312 fhs_help
= "Use FHS-compliant paths (default no)\n"
313 fhs_help
+= "You should consider using this together with:\n"
314 fhs_help
+= "--prefix=/usr --sysconfdir=/etc --localstatedir=/var"
315 opt_group
.add_option('--enable-fhs', help=fhs_help
,
316 action
="store_true", dest
='ENABLE_FHS', default
=False)
318 for varname
in dynconfig
.keys():
319 if 'OPTION' not in dynconfig
[varname
]:
321 opt
= dynconfig
[varname
]['OPTION']
322 if 'HELPTEXT' in dynconfig
[varname
]:
323 txt
= dynconfig
[varname
]['HELPTEXT']
325 txt
= "dynconfig path %s" % (varname
)
326 def_std
= dynconfig
[varname
]['STD-PATH']
327 def_fhs
= dynconfig
[varname
]['FHS-PATH']
329 help = "%s\n[STD-Default: %s]\n[FHS-Default: %s]" % (txt
, def_std
, def_fhs
)
330 opt_group
.add_option(opt
, help=help, dest
=varname
, action
="store")
333 # get all the basic GNU options from the gnu_dirs tool
335 if Options
.options
.ENABLE_FHS
:
339 if conf
.env
.PREFIX
== '/usr' or conf
.env
.PREFIX
== '/usr/local':
340 Logs
.error("Don't install directly under /usr or /usr/local without using the FHS option (--enable-fhs)")
341 raise Errors
.WafError("ERROR: invalid --prefix=%s value" % (conf
.env
.PREFIX
))
346 for varname
in dynconfig
.keys():
347 dyn_vars
[varname
] = dynconfig
[varname
][flavor
]
348 if 'OVERWRITE' in dynconfig
[varname
] and dynconfig
[varname
]['OVERWRITE']:
349 # we may overwrite this option
351 conf
.ASSERT(varname
not in conf
.env
, "Variable %s already defined" % varname
)
354 for varname
in dynconfig
.keys():
355 if 'OPTION' not in dynconfig
[varname
]:
357 value
= getattr(Options
.options
, varname
, None)
360 conf
.ASSERT(value
!= '', "Empty dynconfig value for %s" % varname
)
361 conf
.env
[varname
] = value
362 # mark it as explicit from the command line
363 explicit_set
[varname
] = value
365 # defaults stage 1 after the explicit block
366 for varname
in dynconfig
.keys():
367 if 'DELAY' in dynconfig
[varname
] and dynconfig
[varname
]['DELAY']:
368 # this option refers to other options,
369 # so it needs to wait for stage 2.
371 value
= EXPAND_VARIABLES(conf
, dyn_vars
[varname
])
372 conf
.ASSERT(value
!= '', "Empty dynconfig value for %s" % varname
)
373 if varname
not in explicit_set
:
374 # only overwrite if not specified explicitly on the command line
375 conf
.env
[varname
] = value
377 # defaults stage 2 after the explicit block
378 for varname
in dynconfig
.keys():
379 if 'DELAY' not in dynconfig
[varname
] or not dynconfig
[varname
]['DELAY']:
380 # this option was already handled in stage 1.
382 value
= EXPAND_VARIABLES(conf
, dyn_vars
[varname
])
383 conf
.ASSERT(value
!= '', "Empty dynconfig value for %s" % varname
)
384 if varname
not in explicit_set
:
385 # only overwrite if not specified explicitly on the command line
386 conf
.env
[varname
] = value
388 # display the expanded paths for the user
389 for varname
in dynconfig
.keys():
390 value
= conf
.env
[varname
]
391 conf
.start_msg("Dynconfig[%s]: " % (varname
))
392 conf
.end_msg("'%s'" % (value
), 'GREEN')
394 def get_override(bld
):
395 override
= { 'MODULESDIR' : 'bin/modules',
396 'PYTHONDIR' : 'bin/python',
397 'PYTHONARCHDIR' : 'bin/python',
400 'LIBEXECDIR' : 'bin',
401 'SAMBA_LIBEXECDIR' : 'bin',
402 'CODEPAGEDIR' : 'codepages',
403 'SCRIPTSBINDIR' : 'source4/scripting/bin',
404 'SETUPDIR' : 'source4/setup'
408 def dynconfig_cflags(bld
, list=None):
409 '''work out the extra CFLAGS for dynconfig.c'''
411 for varname
in dynconfig
.keys():
412 if list and not varname
in list:
414 value
= bld
.env
[varname
]
415 if not bld
.is_install
:
416 override
= get_override(bld
)
417 if varname
in override
:
418 value
= os
.path
.join(bld
.env
.srcdir
, override
[varname
])
419 cflags
.append('-D%s="%s"' % (varname
, value
))
421 Build
.BuildContext
.dynconfig_cflags
= dynconfig_cflags
423 def dynconfig_varnames(bld
, list=None):
424 '''work out the dynconfig variables'''
426 for varname
in dynconfig
.keys():
427 if list and not varname
in list:
429 varnames
.append(varname
)
431 Build
.BuildContext
.dynconfig_varnames
= dynconfig_varnames
433 def pathconfig_entities(bld
, list=None):
434 '''work out the extra entities for the docs'''
436 for varname
in dynconfig
.keys():
437 if list and not varname
in list:
439 value
= bld
.env
[varname
]
440 if not bld
.is_install
:
441 override
= get_override(bld
)
442 if varname
in override
:
443 value
= os
.path
.join(bld
.env
.srcdir
, override
[varname
])
444 entities
.append("<!ENTITY pathconfig.%s '%s'>" % (varname
, value
))
446 Build
.BuildContext
.pathconfig_entities
= pathconfig_entities
449 cflags
= bld
.dynconfig_cflags()
450 version_header
= 'version.h'
451 bld
.SAMBA_SUBSYSTEM('DYNCONFIG',
454 public_headers
=os
.path
.relpath(os
.path
.join(Context
.launch_dir
, version_header
), bld
.path
.abspath()),
458 # install some extra empty directories
459 bld
.INSTALL_DIR("${CONFIGDIR}")
460 bld
.INSTALL_DIR("${LOGFILEBASE}")
461 bld
.INSTALL_DIR("${PRIVILEGED_SOCKET_DIR}")
462 bld
.INSTALL_DIR("${PRIVATE_DIR}", 0o700)
463 bld
.INSTALL_DIR("${BINDDNS_DIR}", 0o770)
464 bld
.INSTALL_DIR("${STATEDIR}")
465 bld
.INSTALL_DIR("${CACHEDIR}")
467 # these might be on non persistent storage
468 bld
.INSTALL_DIRS("", "${LOCKDIR} ${PIDDIR} ${SOCKET_DIR}")