dynconfig: implement PERL_LIB_INSTALL_DIR.
[Samba.git] / dynconfig / wscript
blob1304bd3faa54eaaa3dd72ad256f367670b2db071
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 'PERL_LIB_INSTALL_DIR' : {
115 'STD-PATH': '${PERL_LIB_INSTALL_DIR}',
116 'FHS-PATH': '${PERL_LIB_INSTALL_DIR}',
117 'OVERWRITE': True,
119 'INCLUDEDIR' : {
120 'STD-PATH': '${INCLUDEDIR}',
121 'FHS-PATH': '${INCLUDEDIR}/samba-4.0',
122 'OVERWRITE': True,
124 'SCRIPTSBINDIR' : {
125 'STD-PATH': '${SBINDIR}',
126 'FHS-PATH': '${SBINDIR}',
128 'SETUPDIR' : {
129 'STD-PATH': '${DATADIR}/setup',
130 'FHS-PATH': '${DATADIR}/samba/setup',
132 'PKGCONFIGDIR' : {
133 'STD-PATH': '${LIBDIR}/pkgconfig',
134 'FHS-PATH': '${LIBDIR}/pkgconfig',
136 'CODEPAGEDIR' : {
137 'STD-PATH': '${DATADIR}/codepages',
138 'FHS-PATH': '${DATADIR}/samba/codepages',
140 'PRIVATELIBDIR' : {
141 'STD-PATH': '${LIBDIR}/private',
142 'FHS-PATH': '${LIBDIR}/samba',
143 'OPTION': '--with-privatelibdir',
144 'HELPTEXT': 'Which directory to use for private Samba libraries',
145 'OVERWRITE': True,
147 'MODULESDIR' : {
148 'STD-PATH': '${LIBDIR}',
149 'FHS-PATH': '${LIBDIR}/samba',
150 'OPTION': '--with-modulesdir',
151 'HELPTEXT': 'Which directory to use for Samba modules',
152 'OVERWRITE': True,
154 'PAMMODULESDIR' : {
155 'STD-PATH': '${LIBDIR}/security',
156 'FHS-PATH': '${LIBDIR}/security',
157 'OPTION': '--with-pammodulesdir',
158 'HELPTEXT': 'Which directory to use for PAM modules',
160 'CONFIGDIR' : {
161 'STD-PATH': '${SYSCONFDIR}',
162 'FHS-PATH': '${SYSCONFDIR}/samba',
163 'OPTION': '--with-configdir',
164 'HELPTEXT': 'Where to put configuration files',
166 'PRIVATE_DIR' : {
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',
172 'LOCKDIR' : {
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',
178 'PIDDIR' : {
179 'STD-PATH': '${LOCALSTATEDIR}/run',
180 'FHS-PATH': '${LOCALSTATEDIR}/run/samba',
181 'OPTION': '--with-piddir',
182 'HELPTEXT': 'Where to put pid files',
184 'STATEDIR' : {
185 'STD-PATH': '${LOCALSTATEDIR}/locks',
186 'FHS-PATH': '${LOCALSTATEDIR}/lib/samba',
187 'OPTION': '--with-statedir',
188 'HELPTEXT': 'Where to put persistent state files',
190 'CACHEDIR' : {
191 'STD-PATH': '${LOCALSTATEDIR}/cache',
192 'FHS-PATH': '${LOCALSTATEDIR}/cache/samba',
193 'OPTION': '--with-cachedir',
194 'HELPTEXT': 'Where to put temporary cache files',
196 'LOGFILEBASE' : {
197 'STD-PATH': '${LOCALSTATEDIR}',
198 'FHS-PATH': '${LOCALSTATEDIR}/log/samba',
199 'OPTION': '--with-logfilebase',
200 'HELPTEXT': 'Where to put log files',
202 'SOCKET_DIR' : {
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',
217 'DELAY': True,
219 'WINBINDD_PRIVILEGED_SOCKET_DIR' : {
220 'STD-PATH': '${PRIVILEGED_SOCKET_DIR}/winbindd_privileged',
221 'FHS-PATH': '${PRIVILEGED_SOCKET_DIR}/winbindd_privileged',
222 'DELAY': True,
224 'NMBDSOCKETDIR' : {
225 'STD-PATH': '${SOCKET_DIR}/nmbd',
226 'FHS-PATH': '${SOCKET_DIR}/nmbd',
227 'DELAY': True,
229 'NTP_SIGND_SOCKET_DIR' : {
230 'STD-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
231 'FHS-PATH': '${PRIVILEGED_SOCKET_DIR}/ntp_signd',
232 'DELAY': True,
234 'NCALRPCDIR' : {
235 'STD-PATH': '${SOCKET_DIR}/ncalrpc',
236 'FHS-PATH': '${SOCKET_DIR}/ncalrpc',
237 'DELAY': True,
239 'CONFIGFILE' : {
240 'STD-PATH': '${CONFIGDIR}/smb.conf',
241 'FHS-PATH': '${CONFIGDIR}/smb.conf',
242 'DELAY': True,
244 'LMHOSTSFILE' : {
245 'STD-PATH': '${CONFIGDIR}/lmhosts',
246 'FHS-PATH': '${CONFIGDIR}/lmhosts',
247 'DELAY': True,
249 'SMB_PASSWD_FILE' : {
250 'STD-PATH': '${PRIVATE_DIR}/smbpasswd',
251 'FHS-PATH': '${PRIVATE_DIR}/smbpasswd',
252 'DELAY': True,
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)
262 if option:
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]:
279 continue
280 opt = dynconfig[varname]['OPTION']
281 if 'HELPTEXT' in dynconfig[varname]:
282 txt = dynconfig[varname]['HELPTEXT']
283 else:
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")
291 def configure(conf):
292 # get all the basic GNU options from the gnu_dirs tool
294 if Options.options.ENABLE_FHS:
295 flavor = 'FHS-PATH'
296 else:
297 flavor = 'STD-PATH'
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))
302 explicit_set ={}
304 dyn_vars = {}
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
309 continue
310 conf.ASSERT(varname not in conf.env, "Variable %s already defined" % varname)
312 # the explicit block
313 for varname in dynconfig.keys():
314 if 'OPTION' not in dynconfig[varname]:
315 continue
316 value = getattr(Options.options, varname, None)
317 if value is None:
318 continue
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.
329 continue
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.
340 continue
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',
357 'BINDIR' : 'bin',
358 'SBINDIR' : 'bin',
359 'CODEPAGEDIR' : 'codepages',
360 'SCRIPTSBINDIR' : 'source4/scripting/bin',
361 'SETUPDIR' : 'source4/setup'
363 return override
365 def dynconfig_cflags(bld, list=None):
366 '''work out the extra CFLAGS for dynconfig.c'''
367 cflags = []
368 for varname in dynconfig.keys():
369 if list and not varname in list:
370 continue
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))
377 return cflags
378 Build.BuildContext.dynconfig_cflags = dynconfig_cflags
380 def dynconfig_varnames(bld, list=None):
381 '''work out the dynconfig variables'''
382 varnames = []
383 for varname in dynconfig.keys():
384 if list and not varname in list:
385 continue
386 varnames.append(varname)
387 return varnames
388 Build.BuildContext.dynconfig_varnames = dynconfig_varnames
390 def pathconfig_entities(bld, list=None):
391 '''work out the extra entities for the docs'''
392 entities = []
393 for varname in dynconfig.keys():
394 if list and not varname in list:
395 continue
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))
402 return entities
403 Build.BuildContext.pathconfig_entities = pathconfig_entities
405 def build(bld):
406 cflags = bld.dynconfig_cflags()
407 version_header = 'version.h'
408 bld.SAMBA_SUBSYSTEM('DYNCONFIG',
409 'dynconfig.c',
410 deps='replace talloc',
411 public_headers=os_path_relpath(os.path.join(Options.launch_dir, version_header), bld.curdir),
412 header_path='samba',
413 cflags=cflags)
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}")