build:wafsamba: Build on waf 1.9
[sfrench/samba-autobuild/.git] / buildtools / wafsamba / samba_utils.py
1 # a waf tool to add autoconf-like macros to the configure section
2 # and for SAMBA_ macros for building libraries, binaries etc
3
4 import os, sys, re, fnmatch, shlex, inspect
5 from optparse import SUPPRESS_HELP
6 from waflib import Build, Options, Utils, Task, Logs, Configure, Errors
7 from TaskGen import feature, before, after
8 from Configure import ConfigurationContext
9 from Logs import debug
10
11 # TODO: make this a --option
12 LIB_PATH="shared"
13
14
15 # sigh, python octal constants are a mess
16 MODE_644 = int('644', 8)
17 MODE_755 = int('755', 8)
18
19 def conf(f):
20     # override in order to propagate the argument "mandatory"
21     def fun(*k, **kw):
22         mandatory = True
23         if 'mandatory' in kw:
24             mandatory = kw['mandatory']
25             del kw['mandatory']
26
27         try:
28             return f(*k, **kw)
29         except Errors.ConfigurationError:
30             if mandatory:
31                 raise
32
33     fun.__name__ = f.__name__
34     if 'mandatory' in inspect.getsource(f):
35         fun = f
36
37     setattr(Configure.ConfigurationContext, f.__name__, fun)
38     setattr(Build.BuildContext, f.__name__, fun)
39     return f
40 Configure.conf = conf
41 Configure.conftest = conf
42
43 @conf
44 def SET_TARGET_TYPE(ctx, target, value):
45     '''set the target type of a target'''
46     cache = LOCAL_CACHE(ctx, 'TARGET_TYPE')
47     if target in cache and cache[target] != 'EMPTY':
48         Logs.error("ERROR: Target '%s' in directory %s re-defined as %s - was %s" % (target, ctx.curdir, value, cache[target]))
49         sys.exit(1)
50     LOCAL_CACHE_SET(ctx, 'TARGET_TYPE', target, value)
51     debug("task_gen: Target '%s' created of type '%s' in %s" % (target, value, ctx.curdir))
52     return True
53
54
55 def GET_TARGET_TYPE(ctx, target):
56     '''get target type from cache'''
57     cache = LOCAL_CACHE(ctx, 'TARGET_TYPE')
58     if not target in cache:
59         return None
60     return cache[target]
61
62
63 def ADD_LD_LIBRARY_PATH(path):
64     '''add something to LD_LIBRARY_PATH'''
65     if 'LD_LIBRARY_PATH' in os.environ:
66         oldpath = os.environ['LD_LIBRARY_PATH']
67     else:
68         oldpath = ''
69     newpath = oldpath.split(':')
70     if not path in newpath:
71         newpath.append(path)
72         os.environ['LD_LIBRARY_PATH'] = ':'.join(newpath)
73
74
75 def needs_private_lib(bld, target):
76     '''return True if a target links to a private library'''
77     for lib in getattr(target, "final_libs", []):
78         t = bld.get_tgen_by_name(lib)
79         if t and getattr(t, 'private_library', False):
80             return True
81     return False
82
83
84 def install_rpath(target):
85     '''the rpath value for installation'''
86     bld = target.bld
87     bld.env['RPATH'] = []
88     ret = set()
89     if bld.env.RPATH_ON_INSTALL:
90         ret.add(bld.EXPAND_VARIABLES(bld.env.LIBDIR))
91     if bld.env.RPATH_ON_INSTALL_PRIVATE and needs_private_lib(bld, target):
92         ret.add(bld.EXPAND_VARIABLES(bld.env.PRIVATELIBDIR))
93     return list(ret)
94
95
96 def build_rpath(bld):
97     '''the rpath value for build'''
98     rpaths = [os.path.normpath('%s/%s' % (bld.env.BUILD_DIRECTORY, d)) for d in ("shared", "shared/private")]
99     bld.env['RPATH'] = []
100     if bld.env.RPATH_ON_BUILD:
101         return rpaths
102     for rpath in rpaths:
103         ADD_LD_LIBRARY_PATH(rpath)
104     return []
105
106
107 @conf
108 def LOCAL_CACHE(ctx, name):
109     '''return a named build cache dictionary, used to store
110        state inside other functions'''
111     if name in ctx.env:
112         return ctx.env[name]
113     ctx.env[name] = {}
114     return ctx.env[name]
115
116
117 @conf
118 def LOCAL_CACHE_SET(ctx, cachename, key, value):
119     '''set a value in a local cache'''
120     cache = LOCAL_CACHE(ctx, cachename)
121     cache[key] = value
122
123
124 @conf
125 def ASSERT(ctx, expression, msg):
126     '''a build assert call'''
127     if not expression:
128         raise Utils.WafError("ERROR: %s\n" % msg)
129 Build.BuildContext.ASSERT = ASSERT
130
131
132 def SUBDIR(bld, subdir, list):
133     '''create a list of files by pre-pending each with a subdir name'''
134     ret = ''
135     for l in TO_LIST(list):
136         ret = ret + os.path.normpath(os.path.join(subdir, l)) + ' '
137     return ret
138 Build.BuildContext.SUBDIR = SUBDIR
139
140
141 def dict_concat(d1, d2):
142     '''concatenate two dictionaries d1 += d2'''
143     for t in d2:
144         if t not in d1:
145             d1[t] = d2[t]
146
147 def ADD_COMMAND(opt, name, function):
148     '''add a new top level command to waf'''
149     Utils.g_module.__dict__[name] = function
150     opt.name = function
151 Options.Handler.ADD_COMMAND = ADD_COMMAND
152
153
154 @feature('c', 'cc', 'cshlib', 'cprogram')
155 @before('apply_core','exec_rule')
156 def process_depends_on(self):
157     '''The new depends_on attribute for build rules
158        allow us to specify a dependency on output from
159        a source generation rule'''
160     if getattr(self , 'depends_on', None):
161         lst = self.to_list(self.depends_on)
162         for x in lst:
163             y = self.bld.get_tgen_by_name(x)
164             self.bld.ASSERT(y is not None, "Failed to find dependency %s of %s" % (x, self.name))
165             y.post()
166             if getattr(y, 'more_includes', None):
167                   self.includes += " " + y.more_includes
168
169
170 os_path_relpath = getattr(os.path, 'relpath', None)
171 if os_path_relpath is None:
172     # Python < 2.6 does not have os.path.relpath, provide a replacement
173     # (imported from Python2.6.5~rc2)
174     def os_path_relpath(path, start):
175         """Return a relative version of a path"""
176         start_list = os.path.abspath(start).split("/")
177         path_list = os.path.abspath(path).split("/")
178
179         # Work out how much of the filepath is shared by start and path.
180         i = len(os.path.commonprefix([start_list, path_list]))
181
182         rel_list = ['..'] * (len(start_list)-i) + path_list[i:]
183         if not rel_list:
184             return start
185         return os.path.join(*rel_list)
186
187
188 def unique_list(seq):
189     '''return a uniquified list in the same order as the existing list'''
190     seen = {}
191     result = []
192     for item in seq:
193         if item in seen: continue
194         seen[item] = True
195         result.append(item)
196     return result
197
198
199 def TO_LIST(str, delimiter=None):
200     '''Split a list, preserving quoted strings and existing lists'''
201     if str is None:
202         return []
203     if isinstance(str, list):
204         # we need to return a new independent list...
205         return list(str)
206     if len(str) == 0:
207         return []
208     lst = str.split(delimiter)
209     # the string may have had quotes in it, now we
210     # check if we did have quotes, and use the slower shlex
211     # if we need to
212     for e in lst:
213         if e[0] == '"':
214             return shlex.split(str)
215     return lst
216
217
218 def subst_vars_error(string, env):
219     '''substitute vars, throw an error if a variable is not defined'''
220     lst = re.split('(\$\{\w+\})', string)
221     out = []
222     for v in lst:
223         if re.match('\$\{\w+\}', v):
224             vname = v[2:-1]
225             if not vname in env:
226                 raise KeyError("Failed to find variable %s in %s" % (vname, string))
227             v = env[vname]
228             if isinstance(v, list):
229                 v = ' '.join(v)
230         out.append(v)
231     return ''.join(out)
232
233
234 @conf
235 def SUBST_ENV_VAR(ctx, varname):
236     '''Substitute an environment variable for any embedded variables'''
237     return subst_vars_error(ctx.env[varname], ctx.env)
238 Build.BuildContext.SUBST_ENV_VAR = SUBST_ENV_VAR
239
240
241 def ENFORCE_GROUP_ORDERING(bld):
242     '''enforce group ordering for the project. This
243        makes the group ordering apply only when you specify
244        a target with --target'''
245     if Options.options.compile_targets:
246         @feature('*')
247         @before('exec_rule', 'apply_core', 'collect')
248         def force_previous_groups(self):
249             if getattr(self.bld, 'enforced_group_ordering', False):
250                 return
251             self.bld.enforced_group_ordering = True
252
253             def group_name(g):
254                 tm = self.bld.task_manager
255                 return [x for x in tm.groups_names if id(tm.groups_names[x]) == id(g)][0]
256
257             my_id = id(self)
258             bld = self.bld
259             stop = None
260             for g in bld.task_manager.groups:
261                 for t in g.tasks_gen:
262                     if id(t) == my_id:
263                         stop = id(g)
264                         debug('group: Forcing up to group %s for target %s',
265                               group_name(g), self.name or self.target)
266                         break
267                 if stop is not None:
268                     break
269             if stop is None:
270                 return
271
272             for i in xrange(len(bld.task_manager.groups)):
273                 g = bld.task_manager.groups[i]
274                 bld.task_manager.current_group = i
275                 if id(g) == stop:
276                     break
277                 debug('group: Forcing group %s', group_name(g))
278                 for t in g.tasks_gen:
279                     if not getattr(t, 'forced_groups', False):
280                         debug('group: Posting %s', t.name or t.target)
281                         t.forced_groups = True
282                         t.post()
283 Build.BuildContext.ENFORCE_GROUP_ORDERING = ENFORCE_GROUP_ORDERING
284
285
286 def recursive_dirlist(dir, relbase, pattern=None):
287     '''recursive directory list'''
288     ret = []
289     for f in os.listdir(dir):
290         f2 = dir + '/' + f
291         if os.path.isdir(f2):
292             ret.extend(recursive_dirlist(f2, relbase))
293         else:
294             if pattern and not fnmatch.fnmatch(f, pattern):
295                 continue
296             ret.append(os_path_relpath(f2, relbase))
297     return ret
298
299
300 def mkdir_p(dir):
301     '''like mkdir -p'''
302     if not dir:
303         return
304     if dir.endswith("/"):
305         mkdir_p(dir[:-1])
306         return
307     if os.path.isdir(dir):
308         return
309     mkdir_p(os.path.dirname(dir))
310     os.mkdir(dir)
311
312
313 def SUBST_VARS_RECURSIVE(string, env):
314     '''recursively expand variables'''
315     if string is None:
316         return string
317     limit=100
318     while (string.find('${') != -1 and limit > 0):
319         string = subst_vars_error(string, env)
320         limit -= 1
321     return string
322
323
324 @conf
325 def EXPAND_VARIABLES(ctx, varstr, vars=None):
326     '''expand variables from a user supplied dictionary
327
328     This is most useful when you pass vars=locals() to expand
329     all your local variables in strings
330     '''
331
332     if isinstance(varstr, list):
333         ret = []
334         for s in varstr:
335             ret.append(EXPAND_VARIABLES(ctx, s, vars=vars))
336         return ret
337
338     if not isinstance(varstr, str):
339         return varstr
340
341     import Environment
342     env = Environment.Environment()
343     ret = varstr
344     # substitute on user supplied dict if avaiilable
345     if vars is not None:
346         for v in vars.keys():
347             env[v] = vars[v]
348         ret = SUBST_VARS_RECURSIVE(ret, env)
349
350     # if anything left, subst on the environment as well
351     if ret.find('${') != -1:
352         ret = SUBST_VARS_RECURSIVE(ret, ctx.env)
353     # make sure there is nothing left. Also check for the common
354     # typo of $( instead of ${
355     if ret.find('${') != -1 or ret.find('$(') != -1:
356         Logs.error('Failed to substitute all variables in varstr=%s' % ret)
357         sys.exit(1)
358     return ret
359 Build.BuildContext.EXPAND_VARIABLES = EXPAND_VARIABLES
360
361
362 def RUN_COMMAND(cmd,
363                 env=None,
364                 shell=False):
365     '''run a external command, return exit code or signal'''
366     if env:
367         cmd = SUBST_VARS_RECURSIVE(cmd, env)
368
369     status = os.system(cmd)
370     if os.WIFEXITED(status):
371         return os.WEXITSTATUS(status)
372     if os.WIFSIGNALED(status):
373         return - os.WTERMSIG(status)
374     Logs.error("Unknown exit reason %d for command: %s" (status, cmd))
375     return -1
376
377
378 def RUN_PYTHON_TESTS(testfiles, pythonpath=None, extra_env=None):
379     env = LOAD_ENVIRONMENT()
380     if pythonpath is None:
381         pythonpath = os.path.join(Utils.g_module.blddir, 'python')
382     result = 0
383     for interp in env.python_interpreters:
384         if not isinstance(interp, str):
385             interp = ' '.join(interp)
386         for testfile in testfiles:
387             cmd = "PYTHONPATH=%s %s %s" % (pythonpath, interp, testfile)
388             if extra_env:
389                 for key, value in extra_env.items():
390                     cmd = "%s=%s %s" % (key, value, cmd)
391             print('Running Python test with %s: %s' % (interp, testfile))
392             ret = RUN_COMMAND(cmd)
393             if ret:
394                 print('Python test failed: %s' % cmd)
395                 result = ret
396     return result
397
398
399 # make sure we have md5. some systems don't have it
400 try:
401     from hashlib import md5
402     # Even if hashlib.md5 exists, it may be unusable.
403     # Try to use MD5 function. In FIPS mode this will cause an exception
404     # and we'll get to the replacement code
405     foo = md5('abcd')
406 except:
407     try:
408         import md5
409         # repeat the same check here, mere success of import is not enough.
410         # Try to use MD5 function. In FIPS mode this will cause an exception
411         foo = md5.md5('abcd')
412     except:
413         import Constants
414         Constants.SIG_NIL = hash('abcd')
415         class replace_md5(object):
416             def __init__(self):
417                 self.val = None
418             def update(self, val):
419                 self.val = hash((self.val, val))
420             def digest(self):
421                 return str(self.val)
422             def hexdigest(self):
423                 return self.digest().encode('hex')
424         def replace_h_file(filename):
425             f = open(filename, 'rb')
426             m = replace_md5()
427             while (filename):
428                 filename = f.read(100000)
429                 m.update(filename)
430             f.close()
431             return m.digest()
432         Utils.md5 = replace_md5
433         Task.md5 = replace_md5
434         Utils.h_file = replace_h_file
435
436
437 def LOAD_ENVIRONMENT():
438     '''load the configuration environment, allowing access to env vars
439        from new commands'''
440     import Environment
441     env = Environment.Environment()
442     try:
443         env.load('bin/c4che/default_cache.py')
444     except (OSError, IOError):
445         pass
446     return env
447
448
449 def IS_NEWER(bld, file1, file2):
450     '''return True if file1 is newer than file2'''
451     t1 = os.stat(os.path.join(bld.curdir, file1)).st_mtime
452     t2 = os.stat(os.path.join(bld.curdir, file2)).st_mtime
453     return t1 > t2
454 Build.BuildContext.IS_NEWER = IS_NEWER
455
456
457 @conf
458 def RECURSE(ctx, directory):
459     '''recurse into a directory, relative to the curdir or top level'''
460     try:
461         visited_dirs = ctx.visited_dirs
462     except:
463         visited_dirs = ctx.visited_dirs = set()
464     d = os.path.join(ctx.curdir, directory)
465     if os.path.exists(d):
466         abspath = os.path.abspath(d)
467     else:
468         abspath = os.path.abspath(os.path.join(Utils.g_module.srcdir, directory))
469     ctxclass = ctx.__class__.__name__
470     key = ctxclass + ':' + abspath
471     if key in visited_dirs:
472         # already done it
473         return
474     visited_dirs.add(key)
475     relpath = os_path_relpath(abspath, ctx.curdir)
476     if 'waflib.extras.compat15' in sys.modules:
477         return ctx.recurse(relpath)
478     if ctxclass == 'Handler':
479         return ctx.sub_options(relpath)
480     if ctxclass == 'ConfigurationContext':
481         return ctx.sub_config(relpath)
482     if ctxclass == 'BuildContext':
483         return ctx.add_subdirs(relpath)
484     Logs.error('Unknown RECURSE context class', ctxclass)
485     raise
486 Options.Handler.RECURSE = RECURSE
487 Build.BuildContext.RECURSE = RECURSE
488
489
490 def CHECK_MAKEFLAGS(bld):
491     '''check for MAKEFLAGS environment variable in case we are being
492     called from a Makefile try to honor a few make command line flags'''
493     if not 'WAF_MAKE' in os.environ:
494         return
495     makeflags = os.environ.get('MAKEFLAGS')
496     if makeflags is None:
497         return
498     jobs_set = False
499     # we need to use shlex.split to cope with the escaping of spaces
500     # in makeflags
501     for opt in shlex.split(makeflags):
502         # options can come either as -x or as x
503         if opt[0:2] == 'V=':
504             Options.options.verbose = Logs.verbose = int(opt[2:])
505             if Logs.verbose > 0:
506                 Logs.zones = ['runner']
507             if Logs.verbose > 2:
508                 Logs.zones = ['*']
509         elif opt[0].isupper() and opt.find('=') != -1:
510             # this allows us to set waf options on the make command line
511             # for example, if you do "make FOO=blah", then we set the
512             # option 'FOO' in Options.options, to blah. If you look in wafsamba/wscript
513             # you will see that the command line accessible options have their dest=
514             # set to uppercase, to allow for passing of options from make in this way
515             # this is also how "make test TESTS=testpattern" works, and
516             # "make VERBOSE=1" as well as things like "make SYMBOLCHECK=1"
517             loc = opt.find('=')
518             setattr(Options.options, opt[0:loc], opt[loc+1:])
519         elif opt[0] != '-':
520             for v in opt:
521                 if v == 'j':
522                     jobs_set = True
523                 elif v == 'k':
524                     Options.options.keep = True
525         elif opt == '-j':
526             jobs_set = True
527         elif opt == '-k':
528             Options.options.keep = True
529     if not jobs_set:
530         # default to one job
531         Options.options.jobs = 1
532
533 Build.BuildContext.CHECK_MAKEFLAGS = CHECK_MAKEFLAGS
534
535 option_groups = {}
536
537 def option_group(opt, name):
538     '''find or create an option group'''
539     global option_groups
540     if name in option_groups:
541         return option_groups[name]
542     gr = opt.add_option_group(name)
543     option_groups[name] = gr
544     return gr
545 Options.Handler.option_group = option_group
546
547
548 def save_file(filename, contents, create_dir=False):
549     '''save data to a file'''
550     if create_dir:
551         mkdir_p(os.path.dirname(filename))
552     try:
553         f = open(filename, 'w')
554         f.write(contents)
555         f.close()
556     except:
557         return False
558     return True
559
560
561 def load_file(filename):
562     '''return contents of a file'''
563     try:
564         f = open(filename, 'r')
565         r = f.read()
566         f.close()
567     except:
568         return None
569     return r
570
571
572 def reconfigure(ctx):
573     '''rerun configure if necessary'''
574     import Configure, samba_wildcard, Scripting
575     if not os.path.exists(".lock-wscript"):
576         raise Utils.WafError('configure has not been run')
577     bld = samba_wildcard.fake_build_environment()
578     Configure.autoconfig = True
579     Scripting.check_configured(bld)
580
581
582 def map_shlib_extension(ctx, name, python=False):
583     '''map a filename with a shared library extension of .so to the real shlib name'''
584     if name is None:
585         return None
586     if name[-1:].isdigit():
587         # some libraries have specified versions in the wscript rule
588         return name
589     (root1, ext1) = os.path.splitext(name)
590     if python:
591         return ctx.env.pyext_PATTERN % root1
592     else:
593         (root2, ext2) = os.path.splitext(ctx.env.cshlib_PATTERN)
594     return root1+ext2
595 Build.BuildContext.map_shlib_extension = map_shlib_extension
596
597 def apply_pattern(filename, pattern):
598     '''apply a filename pattern to a filename that may have a directory component'''
599     dirname = os.path.dirname(filename)
600     if not dirname:
601         return pattern % filename
602     basename = os.path.basename(filename)
603     return os.path.join(dirname, pattern % basename)
604
605 def make_libname(ctx, name, nolibprefix=False, version=None, python=False):
606     """make a library filename
607          Options:
608               nolibprefix: don't include the lib prefix
609               version    : add a version number
610               python     : if we should use python module name conventions"""
611
612     if python:
613         libname = apply_pattern(name, ctx.env.pyext_PATTERN)
614     else:
615         libname = apply_pattern(name, ctx.env.cshlib_PATTERN)
616     if nolibprefix and libname[0:3] == 'lib':
617         libname = libname[3:]
618     if version:
619         if version[0] == '.':
620             version = version[1:]
621         (root, ext) = os.path.splitext(libname)
622         if ext == ".dylib":
623             # special case - version goes before the prefix
624             libname = "%s.%s%s" % (root, version, ext)
625         else:
626             libname = "%s%s.%s" % (root, ext, version)
627     return libname
628 Build.BuildContext.make_libname = make_libname
629
630
631 def get_tgt_list(bld):
632     '''return a list of build objects for samba'''
633
634     targets = LOCAL_CACHE(bld, 'TARGET_TYPE')
635
636     # build a list of task generators we are interested in
637     tgt_list = []
638     for tgt in targets:
639         type = targets[tgt]
640         if not type in ['SUBSYSTEM', 'MODULE', 'BINARY', 'LIBRARY', 'ASN1', 'PYTHON']:
641             continue
642         t = bld.get_tgen_by_name(tgt)
643         if t is None:
644             Logs.error("Target %s of type %s has no task generator" % (tgt, type))
645             sys.exit(1)
646         tgt_list.append(t)
647     return tgt_list
648
649 from Constants import WSCRIPT_FILE
650 def PROCESS_SEPARATE_RULE(self, rule):
651     ''' cause waf to process additional script based on `rule'.
652         You should have file named wscript_<stage>_rule in the current directory
653         where stage is either 'configure' or 'build'
654     '''
655     stage = ''
656     if isinstance(self, Configure.ConfigurationContext):
657         stage = 'configure'
658     elif isinstance(self, Build.BuildContext):
659         stage = 'build'
660     file_path = os.path.join(self.curdir, WSCRIPT_FILE+'_'+stage+'_'+rule)
661     txt = load_file(file_path)
662     if txt:
663         dc = {'ctx': self}
664         if getattr(self.__class__, 'pre_recurse', None):
665             dc = self.pre_recurse(txt, file_path, self.curdir)
666         exec(compile(txt, file_path, 'exec'), dc)
667         if getattr(self.__class__, 'post_recurse', None):
668             dc = self.post_recurse(txt, file_path, self.curdir)
669
670 Build.BuildContext.PROCESS_SEPARATE_RULE = PROCESS_SEPARATE_RULE
671 ConfigurationContext.PROCESS_SEPARATE_RULE = PROCESS_SEPARATE_RULE
672
673 def AD_DC_BUILD_IS_ENABLED(self):
674     if self.CONFIG_SET('AD_DC_BUILD_IS_ENABLED'):
675         return True
676     return False
677
678 Build.BuildContext.AD_DC_BUILD_IS_ENABLED = AD_DC_BUILD_IS_ENABLED
679
680 @feature('cprogram', 'cshlib', 'cstaticlib')
681 @after('apply_lib_vars')
682 @before('apply_obj_vars')
683 def samba_before_apply_obj_vars(self):
684     """before apply_obj_vars for uselib, this removes the standard paths"""
685
686     def is_standard_libpath(env, path):
687         for _path in env.STANDARD_LIBPATH:
688             if _path == os.path.normpath(path):
689                 return True
690         return False
691
692     v = self.env
693
694     for i in v['RPATH']:
695         if is_standard_libpath(v, i):
696             v['RPATH'].remove(i)
697
698     for i in v['LIBPATH']:
699         if is_standard_libpath(v, i):
700             v['LIBPATH'].remove(i)
701
702 def samba_add_onoff_option(opt, option, help=(), dest=None, default=True,
703                            with_name="with", without_name="without"):
704     if default is None:
705         default_str = "auto"
706     elif default is True:
707         default_str = "yes"
708     elif default is False:
709         default_str = "no"
710     else:
711         default_str = str(default)
712
713     if help == ():
714         help = ("Build with %s support (default=%s)" % (option, default_str))
715     if dest is None:
716         dest = "with_%s" % option.replace('-', '_')
717
718     with_val = "--%s-%s" % (with_name, option)
719     without_val = "--%s-%s" % (without_name, option)
720
721     opt.add_option(with_val, help=help, action="store_true", dest=dest,
722                    default=default)
723     opt.add_option(without_val, help=SUPPRESS_HELP, action="store_false",
724                    dest=dest)
725 Options.Handler.samba_add_onoff_option = samba_add_onoff_option