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.
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}',
120 'STD-PATH': '${INCLUDEDIR}',
121 'FHS-PATH': '${INCLUDEDIR}/samba-4.0',
125 'STD-PATH': '${SBINDIR}',
126 'FHS-PATH': '${SBINDIR}',
129 'STD-PATH': '${DATADIR}/setup',
130 'FHS-PATH': '${DATADIR}/samba/setup',
133 'STD-PATH': '${LIBDIR}/pkgconfig',
134 'FHS-PATH': '${LIBDIR}/pkgconfig',
137 'STD-PATH': '${DATADIR}/codepages',
138 'FHS-PATH': '${DATADIR}/samba/codepages',
141 'STD-PATH': '${LIBDIR}/private',
142 'FHS-PATH': '${LIBDIR}/samba',
143 'OPTION': '--with-privatelibdir',
144 'HELPTEXT': 'Which directory to use for private Samba libraries',
148 'STD-PATH': '${LIBDIR}',
149 'FHS-PATH': '${LIBDIR}/samba',
150 'OPTION': '--with-modulesdir',
151 'HELPTEXT': 'Which directory to use for Samba modules',
155 'STD-PATH': '${LIBDIR}/security',
156 'FHS-PATH': '${LIBDIR}/security',
157 'OPTION': '--with-pammodulesdir',
158 'HELPTEXT': 'Which directory to use for PAM modules',
161 'STD-PATH': '${SYSCONFDIR}',
162 'FHS-PATH': '${SYSCONFDIR}/samba',
163 'OPTION': '--with-configdir',
164 'HELPTEXT': 'Where to put configuration files',
167 'STD-PATH': '${PREFIX}/private',
168 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba/private',
169 'OPTION': '--with-privatedir',
170 'HELPTEXT': 'Where to put sam.ldb and other private files',
173 'STD-PATH': '${LOCALSTATEDIR}/lock',
174 'FHS-PATH': '${LOCALSTATEDIR}/lock/samba',
175 'OPTION': '--with-lockdir',
176 'HELPTEXT': 'Where to put short term disposable state files',
179 'STD-PATH': '${LOCALSTATEDIR}/run',
180 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
181 'OPTION': '--with-piddir',
182 'HELPTEXT': 'Where to put pid files',
185 'STD-PATH': '${LOCALSTATEDIR}/locks',
186 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
187 'OPTION': '--with-statedir',
188 'HELPTEXT': 'Where to put persistent state files',
191 'STD-PATH': '${LOCALSTATEDIR}/cache',
192 'FHS-PATH': '${LOCALSTATEDIR}/cache/samba',
193 'OPTION': '--with-cachedir',
194 'HELPTEXT': 'Where to put temporary cache files',
197 'STD-PATH': '${LOCALSTATEDIR}',
198 'FHS-PATH': '${LOCALSTATEDIR}/log/samba',
199 'OPTION': '--with-logfilebase',
200 'HELPTEXT': 'Where to put log files',
203 'STD-PATH': '${LOCALSTATEDIR}/run',
204 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
205 'OPTION': '--with-sockets-dir',
206 'HELPTEXT': 'socket directory',
208 'PRIVILEGED_SOCKET_DIR' : {
209 'STD-PATH': '${LOCALSTATEDIR}/lib',
210 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
211 'OPTION': '--with-privileged-socket-dir',
212 'HELPTEXT': 'privileged socket directory',
214 'WINBINDD_SOCKET_DIR' : {
215 'STD-PATH': '${SOCKET_DIR}/winbindd',
216 'FHS-PATH': '${SOCKET_DIR}/winbindd',
219 'WINBINDD_PRIVILEGED_SOCKET_DIR' : {
220 'STD-PATH': '${PRIVILEGED_SOCKET_DIR}/winbindd_privileged',
221 'FHS-PATH': '${PRIVILEGED_SOCKET_DIR}/winbindd_privileged',
225 'STD-PATH': '${SOCKET_DIR}/nmbd',
226 'FHS-PATH': '${SOCKET_DIR}/nmbd',
229 'NTP_SIGND_SOCKET_DIR' : {
230 'STD-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
231 'FHS-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
235 'STD-PATH': '${SOCKET_DIR}/ncalrpc',
236 'FHS-PATH': '${SOCKET_DIR}/ncalrpc',
240 'STD-PATH': '${CONFIGDIR}/smb.conf',
241 'FHS-PATH': '${CONFIGDIR}/smb.conf',
245 'STD-PATH': '${CONFIGDIR}/lmhosts',
246 'FHS-PATH': '${CONFIGDIR}/lmhosts',
249 'SMB_PASSWD_FILE' : {
250 'STD-PATH': '${PRIVATE_DIR}/smbpasswd',
251 'FHS-PATH': '${PRIVATE_DIR}/smbpasswd',
256 def set_options(opt
):
257 opt
.parser
.formatter
= SambaIndentedHelpFormatter()
258 opt
.parser
.formatter
.width
=Utils
.get_term_cols()
260 for k
in ('--with-privatelibdir', '--with-modulesdir'):
261 option
= opt
.parser
.get_option(k
)
263 opt
.parser
.remove_option(k
)
264 del opt
.parser
.defaults
['PRIVATELIBDIR']
265 del opt
.parser
.defaults
['MODULESDIR']
267 # get all the basic GNU options from the gnu_dirs tool
269 opt_group
=opt
.add_option_group('Samba-specific directory layout','')
271 fhs_help
= "Use FHS-compliant paths (default no)\n"
272 fhs_help
+= "You should consider using this together with:\n"
273 fhs_help
+= "--prefix=/usr --sysconfdir=/etc --localstatedir=/var"
274 opt_group
.add_option('--enable-fhs', help=fhs_help
,
275 action
="store_true", dest
='ENABLE_FHS', default
=False)
277 for varname
in dynconfig
.keys():
278 if 'OPTION' not in dynconfig
[varname
]:
280 opt
= dynconfig
[varname
]['OPTION']
281 if 'HELPTEXT' in dynconfig
[varname
]:
282 txt
= dynconfig
[varname
]['HELPTEXT']
284 txt
= "dynconfig path %s" % (varname
)
285 def_std
= dynconfig
[varname
]['STD-PATH']
286 def_fhs
= dynconfig
[varname
]['FHS-PATH']
288 help = "%s\n[STD-Default: %s]\n[FHS-Default: %s]" % (txt
, def_std
, def_fhs
)
289 opt_group
.add_option(opt
, help=help, dest
=varname
, action
="store")
292 # get all the basic GNU options from the gnu_dirs tool
294 if Options
.options
.ENABLE_FHS
:
298 if conf
.env
.PREFIX
== '/usr' or conf
.env
.PREFIX
== '/usr/local':
299 Logs
.error("Don't install directly under /usr or /usr/local without using the FHS option (--enable-fhs)")
300 raise Utils
.WafError("ERROR: invalid --prefix=%s value" % (conf
.env
.PREFIX
))
305 for varname
in dynconfig
.keys():
306 dyn_vars
[varname
] = dynconfig
[varname
][flavor
]
307 if 'OVERWRITE' in dynconfig
[varname
] and dynconfig
[varname
]['OVERWRITE']:
308 # we may overwrite this option
310 conf
.ASSERT(varname
not in conf
.env
, "Variable %s already defined" % varname
)
313 for varname
in dynconfig
.keys():
314 if 'OPTION' not in dynconfig
[varname
]:
316 value
= getattr(Options
.options
, varname
, None)
319 conf
.ASSERT(value
!= '', "Empty dynconfig value for %s" % varname
)
320 conf
.env
[varname
] = value
321 # mark it as explicit from the command line
322 explicit_set
[varname
] = value
324 # defaults stage 1 after the explicit block
325 for varname
in dynconfig
.keys():
326 if 'DELAY' in dynconfig
[varname
] and dynconfig
[varname
]['DELAY']:
327 # this option referrs to other options,
328 # so it needs to wait for stage 2.
330 value
= EXPAND_VARIABLES(conf
, dyn_vars
[varname
])
331 conf
.ASSERT(value
!= '', "Empty dynconfig value for %s" % varname
)
332 if varname
not in explicit_set
:
333 # only overwrite if not specified explicitly on the command line
334 conf
.env
[varname
] = value
336 # defaults stage 2 after the explicit block
337 for varname
in dynconfig
.keys():
338 if 'DELAY' not in dynconfig
[varname
] or not dynconfig
[varname
]['DELAY']:
339 # this option was already handled in stage 1.
341 value
= EXPAND_VARIABLES(conf
, dyn_vars
[varname
])
342 conf
.ASSERT(value
!= '', "Empty dynconfig value for %s" % varname
)
343 if varname
not in explicit_set
:
344 # only overwrite if not specified explicitly on the command line
345 conf
.env
[varname
] = value
347 # display the expanded pathes for the user
348 for varname
in dynconfig
.keys():
349 value
= conf
.env
[varname
]
350 conf
.start_msg("Dynconfig[%s]: " % (varname
))
351 conf
.end_msg("'%s'" % (value
), 'GREEN')
353 def get_override(bld
):
354 override
= { 'MODULESDIR' : 'bin/modules',
355 'PYTHONDIR' : 'bin/python',
356 'PYTHONARCHDIR' : 'bin/python',
359 'CODEPAGEDIR' : 'codepages',
360 'SCRIPTSBINDIR' : 'source4/scripting/bin',
361 'SETUPDIR' : 'source4/setup'
365 def dynconfig_cflags(bld
, list=None):
366 '''work out the extra CFLAGS for dynconfig.c'''
368 for varname
in dynconfig
.keys():
369 if list and not varname
in list:
371 value
= bld
.env
[varname
]
372 if not Options
.is_install
:
373 override
= get_override(bld
)
374 if varname
in override
:
375 value
= os
.path
.join(bld
.env
.srcdir
, override
[varname
])
376 cflags
.append('-D%s="%s"' % (varname
, value
))
378 Build
.BuildContext
.dynconfig_cflags
= dynconfig_cflags
380 def dynconfig_varnames(bld
, list=None):
381 '''work out the dynconfig variables'''
383 for varname
in dynconfig
.keys():
384 if list and not varname
in list:
386 varnames
.append(varname
)
388 Build
.BuildContext
.dynconfig_varnames
= dynconfig_varnames
390 def pathconfig_entities(bld
, list=None):
391 '''work out the extra entities for the docs'''
393 for varname
in dynconfig
.keys():
394 if list and not varname
in list:
396 value
= bld
.env
[varname
]
397 if not Options
.is_install
:
398 override
= get_override(bld
)
399 if varname
in override
:
400 value
= os
.path
.join(bld
.env
.srcdir
, override
[varname
])
401 entities
.append("<!ENTITY pathconfig.%s '%s'>" % (varname
, value
))
403 Build
.BuildContext
.pathconfig_entities
= pathconfig_entities
406 cflags
= bld
.dynconfig_cflags()
407 version_header
= 'version.h'
408 bld
.SAMBA_SUBSYSTEM('DYNCONFIG',
410 deps
='replace talloc',
411 public_headers
=os_path_relpath(os
.path
.join(Options
.launch_dir
, version_header
), bld
.curdir
),
415 # install some extra empty directories
416 bld
.INSTALL_DIRS("", "${CONFIGDIR} ${PRIVATE_DIR} ${LOGFILEBASE}");
417 bld
.INSTALL_DIRS("", "${PRIVATE_DIR} ${PRIVILEGED_SOCKET_DIR}")
418 bld
.INSTALL_DIRS("", "${STATEDIR} ${CACHEDIR}");
420 # these might be on non persistent storage
421 bld
.INSTALL_DIRS("", "${LOCKDIR} ${PIDDIR} ${SOCKET_DIR}")