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