3 import string
, Logs
, Utils
, Options
, Build
, os
, optparse
, textwrap
4 from samba_utils
import EXPAND_VARIABLES
, os_path_relpath
6 class SambaIndentedHelpFormatter (optparse
.IndentedHelpFormatter
):
7 """Format help with indented section bodies.
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
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
)
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
)
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":
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)
75 'STD-PATH': '${BINDIR}',
76 'FHS-PATH': '${BINDIR}',
80 'STD-PATH': '${SBINDIR}',
81 'FHS-PATH': '${SBINDIR}',
85 'STD-PATH': '${LIBDIR}',
86 'FHS-PATH': '${LIBDIR}',
90 'STD-PATH': '${LIBEXECDIR}',
91 'FHS-PATH': '${LIBEXECDIR}',
95 'STD-PATH': '${DATADIR}',
96 'FHS-PATH': '${DATADIR}',
100 'STD-PATH': '${LOCALEDIR}',
101 'FHS-PATH': '${LOCALEDIR}',
105 'STD-PATH': '${PYTHONDIR}',
106 'FHS-PATH': '${PYTHONDIR}',
110 'STD-PATH': '${PYTHONARCHDIR}',
111 'FHS-PATH': '${PYTHONARCHDIR}',
114 'PERL_LIB_INSTALL_DIR' : {
115 'STD-PATH': '${PERL_LIB_INSTALL_DIR}',
116 'FHS-PATH': '${PERL_LIB_INSTALL_DIR}',
119 'PERL_ARCH_INSTALL_DIR' : {
120 'STD-PATH': '${PERL_ARCH_INSTALL_DIR}',
121 'FHS-PATH': '${PERL_ARCH_INSTALL_DIR}',
125 'STD-PATH': '${INCLUDEDIR}',
126 'FHS-PATH': '${INCLUDEDIR}/samba-4.0',
130 'STD-PATH': '${SBINDIR}',
131 'FHS-PATH': '${SBINDIR}',
134 'STD-PATH': '${DATADIR}/setup',
135 'FHS-PATH': '${DATADIR}/samba/setup',
138 'STD-PATH': '${LIBDIR}/pkgconfig',
139 'FHS-PATH': '${LIBDIR}/pkgconfig',
142 'STD-PATH': '${DATADIR}/codepages',
143 'FHS-PATH': '${DATADIR}/samba/codepages',
146 'STD-PATH': '${LIBDIR}/private',
147 'FHS-PATH': '${LIBDIR}/samba',
148 'OPTION': '--with-privatelibdir',
149 'HELPTEXT': 'Which directory to use for private Samba libraries',
153 'STD-PATH': '${LIBDIR}',
154 'FHS-PATH': '${LIBDIR}/samba',
155 'OPTION': '--with-modulesdir',
156 'HELPTEXT': 'Which directory to use for Samba modules',
160 'STD-PATH': '${LIBDIR}/security',
161 'FHS-PATH': '${LIBDIR}/security',
162 'OPTION': '--with-pammodulesdir',
163 'HELPTEXT': 'Which directory to use for PAM modules',
166 'STD-PATH': '${SYSCONFDIR}',
167 'FHS-PATH': '${SYSCONFDIR}/samba',
168 'OPTION': '--with-configdir',
169 'HELPTEXT': 'Where to put configuration files',
172 'STD-PATH': '${PREFIX}/private',
173 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/private',
174 'OPTION': '--with-privatedir',
175 'HELPTEXT': 'Where to put sam.ldb and other private files',
178 'STD-PATH': '${PREFIX}/bind-dns',
179 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/bind-dns',
180 'OPTION': '--with-bind-dns-dir',
181 'HELPTEXT': 'bind-dns config directory',
184 'STD-PATH': '${LOCALSTATEDIR}/lock',
185 'FHS-PATH': '${LOCALSTATEDIR}/lock/samba',
186 'OPTION': '--with-lockdir',
187 'HELPTEXT': 'Where to put short term disposable state files',
190 'STD-PATH': '${LOCALSTATEDIR}/run',
191 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
192 'OPTION': '--with-piddir',
193 'HELPTEXT': 'Where to put pid files',
196 'STD-PATH': '${LOCALSTATEDIR}/locks',
197 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
198 'OPTION': '--with-statedir',
199 'HELPTEXT': 'Where to put persistent state files',
202 'STD-PATH': '${LOCALSTATEDIR}/cache',
203 'FHS-PATH': '${LOCALSTATEDIR}/cache/samba',
204 'OPTION': '--with-cachedir',
205 'HELPTEXT': 'Where to put temporary cache files',
208 'STD-PATH': '${LOCALSTATEDIR}',
209 'FHS-PATH': '${LOCALSTATEDIR}/log/samba',
210 'OPTION': '--with-logfilebase',
211 'HELPTEXT': 'Where to put log files',
214 'STD-PATH': '${LOCALSTATEDIR}/run',
215 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
216 'OPTION': '--with-sockets-dir',
217 'HELPTEXT': 'socket directory',
219 'PRIVILEGED_SOCKET_DIR' : {
220 'STD-PATH': '${LOCALSTATEDIR}/lib',
221 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
222 'OPTION': '--with-privileged-socket-dir',
223 'HELPTEXT': 'privileged socket directory',
225 'WINBINDD_SOCKET_DIR' : {
226 'STD-PATH': '${SOCKET_DIR}/winbindd',
227 'FHS-PATH': '${SOCKET_DIR}/winbindd',
231 'STD-PATH': '${SOCKET_DIR}/nmbd',
232 'FHS-PATH': '${SOCKET_DIR}/nmbd',
235 'NTP_SIGND_SOCKET_DIR' : {
236 'STD-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
237 'FHS-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
241 'STD-PATH': '${SOCKET_DIR}/ncalrpc',
242 'FHS-PATH': '${SOCKET_DIR}/ncalrpc',
246 'STD-PATH': '${CONFIGDIR}/smb.conf',
247 'FHS-PATH': '${CONFIGDIR}/smb.conf',
251 'STD-PATH': '${CONFIGDIR}/lmhosts',
252 'FHS-PATH': '${CONFIGDIR}/lmhosts',
255 'SMB_PASSWD_FILE' : {
256 'STD-PATH': '${PRIVATE_DIR}/smbpasswd',
257 'FHS-PATH': '${PRIVATE_DIR}/smbpasswd',
258 'OPTION': '--with-smbpasswd-file',
259 'HELPTEXT': 'Where to put the smbpasswd file',
264 def set_options(opt
):
265 opt
.parser
.formatter
= SambaIndentedHelpFormatter()
266 opt
.parser
.formatter
.width
=Utils
.get_term_cols()
268 for k
in ('--with-privatelibdir', '--with-modulesdir'):
269 option
= opt
.parser
.get_option(k
)
271 opt
.parser
.remove_option(k
)
272 del opt
.parser
.defaults
['PRIVATELIBDIR']
273 del opt
.parser
.defaults
['MODULESDIR']
275 # get all the basic GNU options from the gnu_dirs tool
277 opt_group
=opt
.add_option_group('Samba-specific directory layout','')
279 fhs_help
= "Use FHS-compliant paths (default no)\n"
280 fhs_help
+= "You should consider using this together with:\n"
281 fhs_help
+= "--prefix=/usr --sysconfdir=/etc --localstatedir=/var"
282 opt_group
.add_option('--enable-fhs', help=fhs_help
,
283 action
="store_true", dest
='ENABLE_FHS', default
=False)
285 for varname
in dynconfig
.keys():
286 if 'OPTION' not in dynconfig
[varname
]:
288 opt
= dynconfig
[varname
]['OPTION']
289 if 'HELPTEXT' in dynconfig
[varname
]:
290 txt
= dynconfig
[varname
]['HELPTEXT']
292 txt
= "dynconfig path %s" % (varname
)
293 def_std
= dynconfig
[varname
]['STD-PATH']
294 def_fhs
= dynconfig
[varname
]['FHS-PATH']
296 help = "%s\n[STD-Default: %s]\n[FHS-Default: %s]" % (txt
, def_std
, def_fhs
)
297 opt_group
.add_option(opt
, help=help, dest
=varname
, action
="store")
300 # get all the basic GNU options from the gnu_dirs tool
302 if Options
.options
.ENABLE_FHS
:
306 if conf
.env
.PREFIX
== '/usr' or conf
.env
.PREFIX
== '/usr/local':
307 Logs
.error("Don't install directly under /usr or /usr/local without using the FHS option (--enable-fhs)")
308 raise Utils
.WafError("ERROR: invalid --prefix=%s value" % (conf
.env
.PREFIX
))
313 for varname
in dynconfig
.keys():
314 dyn_vars
[varname
] = dynconfig
[varname
][flavor
]
315 if 'OVERWRITE' in dynconfig
[varname
] and dynconfig
[varname
]['OVERWRITE']:
316 # we may overwrite this option
318 conf
.ASSERT(varname
not in conf
.env
, "Variable %s already defined" % varname
)
321 for varname
in dynconfig
.keys():
322 if 'OPTION' not in dynconfig
[varname
]:
324 value
= getattr(Options
.options
, varname
, None)
327 conf
.ASSERT(value
!= '', "Empty dynconfig value for %s" % varname
)
328 conf
.env
[varname
] = value
329 # mark it as explicit from the command line
330 explicit_set
[varname
] = value
332 # defaults stage 1 after the explicit block
333 for varname
in dynconfig
.keys():
334 if 'DELAY' in dynconfig
[varname
] and dynconfig
[varname
]['DELAY']:
335 # this option referrs to other options,
336 # so it needs to wait for stage 2.
338 value
= EXPAND_VARIABLES(conf
, dyn_vars
[varname
])
339 conf
.ASSERT(value
!= '', "Empty dynconfig value for %s" % varname
)
340 if varname
not in explicit_set
:
341 # only overwrite if not specified explicitly on the command line
342 conf
.env
[varname
] = value
344 # defaults stage 2 after the explicit block
345 for varname
in dynconfig
.keys():
346 if 'DELAY' not in dynconfig
[varname
] or not dynconfig
[varname
]['DELAY']:
347 # this option was already handled in stage 1.
349 value
= EXPAND_VARIABLES(conf
, dyn_vars
[varname
])
350 conf
.ASSERT(value
!= '', "Empty dynconfig value for %s" % varname
)
351 if varname
not in explicit_set
:
352 # only overwrite if not specified explicitly on the command line
353 conf
.env
[varname
] = value
355 # display the expanded pathes for the user
356 for varname
in dynconfig
.keys():
357 value
= conf
.env
[varname
]
358 conf
.start_msg("Dynconfig[%s]: " % (varname
))
359 conf
.end_msg("'%s'" % (value
), 'GREEN')
361 def get_override(bld
):
362 override
= { 'MODULESDIR' : 'bin/modules',
363 'PYTHONDIR' : 'bin/python',
364 'PYTHONARCHDIR' : 'bin/python',
367 'CODEPAGEDIR' : 'codepages',
368 'SCRIPTSBINDIR' : 'source4/scripting/bin',
369 'SETUPDIR' : 'source4/setup'
373 def dynconfig_cflags(bld
, list=None):
374 '''work out the extra CFLAGS for dynconfig.c'''
376 for varname
in dynconfig
.keys():
377 if list and not varname
in list:
379 value
= bld
.env
[varname
]
380 if not bld
.is_install
:
381 override
= get_override(bld
)
382 if varname
in override
:
383 value
= os
.path
.join(bld
.env
.srcdir
, override
[varname
])
384 cflags
.append('-D%s="%s"' % (varname
, value
))
386 Build
.BuildContext
.dynconfig_cflags
= dynconfig_cflags
388 def dynconfig_varnames(bld
, list=None):
389 '''work out the dynconfig variables'''
391 for varname
in dynconfig
.keys():
392 if list and not varname
in list:
394 varnames
.append(varname
)
396 Build
.BuildContext
.dynconfig_varnames
= dynconfig_varnames
398 def pathconfig_entities(bld
, list=None):
399 '''work out the extra entities for the docs'''
401 for varname
in dynconfig
.keys():
402 if list and not varname
in list:
404 value
= bld
.env
[varname
]
405 if not bld
.is_install
:
406 override
= get_override(bld
)
407 if varname
in override
:
408 value
= os
.path
.join(bld
.env
.srcdir
, override
[varname
])
409 entities
.append("<!ENTITY pathconfig.%s '%s'>" % (varname
, value
))
411 Build
.BuildContext
.pathconfig_entities
= pathconfig_entities
414 cflags
= bld
.dynconfig_cflags()
415 version_header
= 'version.h'
416 bld
.SAMBA_SUBSYSTEM('DYNCONFIG',
419 public_headers
=os_path_relpath(os
.path
.join(Options
.launch_dir
, version_header
), bld
.curdir
),
423 # install some extra empty directories
424 bld
.INSTALL_DIR("${CONFIGDIR}")
425 bld
.INSTALL_DIR("${LOGFILEBASE}")
426 bld
.INSTALL_DIR("${PRIVILEGED_SOCKET_DIR}")
427 bld
.INSTALL_DIR("${PRIVATE_DIR}", 0o700)
428 bld
.INSTALL_DIR("${BINDDNS_DIR}", 0o770)
429 bld
.INSTALL_DIR("${STATEDIR}")
430 bld
.INSTALL_DIR("${CACHEDIR}")
432 # these might be on non persistent storage
433 bld
.INSTALL_DIRS("", "${LOCKDIR} ${PIDDIR} ${SOCKET_DIR}")