wafsamba: display the default value in help for SAMBA3_ADD_OPTION
[Samba.git] / buildtools / wafsamba / samba3.py
blobfd063ad8c472a09d44835a0f1ee241aff28d388b
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 Options, Build, os
5 from optparse import SUPPRESS_HELP
6 from samba_utils import os_path_relpath, TO_LIST
7 from samba_autoconf import library_flags
9 def SAMBA3_ADD_OPTION(opt, option, help=(), dest=None, default=True,
10 with_name="with", without_name="without"):
11 if default is None:
12 default_str="auto"
13 elif default == True:
14 default_str="yes"
15 elif default == False:
16 default_str="no"
17 else:
18 default_str=str(default)
20 if help == ():
21 help = ("Build with %s support (default=%s)" % (option, default_str))
22 if dest is None:
23 dest = "with_%s" % option.replace('-', '_')
25 with_val = "--%s-%s" % (with_name, option)
26 without_val = "--%s-%s" % (without_name, option)
28 #FIXME: This is broken and will always default to "default" no matter if
29 # --with or --without is chosen.
30 opt.add_option(with_val, help=help, action="store_true", dest=dest,
31 default=default)
32 opt.add_option(without_val, help=SUPPRESS_HELP, action="store_false",
33 dest=dest)
34 Options.Handler.SAMBA3_ADD_OPTION = SAMBA3_ADD_OPTION
36 def SAMBA3_IS_STATIC_MODULE(bld, module):
37 '''Check whether module is in static list'''
38 if module in bld.env['static_modules']:
39 return True
40 return False
41 Build.BuildContext.SAMBA3_IS_STATIC_MODULE = SAMBA3_IS_STATIC_MODULE
43 def SAMBA3_IS_SHARED_MODULE(bld, module):
44 '''Check whether module is in shared list'''
45 if module in bld.env['shared_modules']:
46 return True
47 return False
48 Build.BuildContext.SAMBA3_IS_SHARED_MODULE = SAMBA3_IS_SHARED_MODULE
50 def SAMBA3_IS_ENABLED_MODULE(bld, module):
51 '''Check whether module is in either shared or static list '''
52 return SAMBA3_IS_STATIC_MODULE(bld, module) or SAMBA3_IS_SHARED_MODULE(bld, module)
53 Build.BuildContext.SAMBA3_IS_ENABLED_MODULE = SAMBA3_IS_ENABLED_MODULE
57 def s3_fix_kwargs(bld, kwargs):
58 '''fix the build arguments for s3 build rules to include the
59 necessary includes, subdir and cflags options '''
60 s3dir = os.path.join(bld.env.srcdir, 'source3')
61 s3reldir = os_path_relpath(s3dir, bld.curdir)
63 # the extra_includes list is relative to the source3 directory
64 extra_includes = [ '.', 'include', 'lib', '../lib/tdb_compat' ]
65 # local heimdal paths only included when USING_SYSTEM_KRB5 is not set
66 if not bld.CONFIG_SET("USING_SYSTEM_KRB5"):
67 extra_includes += [ '../source4/heimdal/lib/com_err',
68 '../source4/heimdal/lib/krb5',
69 '../source4/heimdal/lib/gssapi',
70 '../source4/heimdal_build',
71 '../bin/default/source4/heimdal/lib/asn1' ]
73 if bld.CONFIG_SET('USING_SYSTEM_TDB'):
74 (tdb_includes, tdb_ldflags, tdb_cpppath) = library_flags(bld, 'tdb')
75 extra_includes += tdb_cpppath
76 else:
77 extra_includes += [ '../lib/tdb/include' ]
79 if bld.CONFIG_SET('USING_SYSTEM_TEVENT'):
80 (tevent_includes, tevent_ldflags, tevent_cpppath) = library_flags(bld, 'tevent')
81 extra_includes += tevent_cpppath
82 else:
83 extra_includes += [ '../lib/tevent' ]
85 if bld.CONFIG_SET('USING_SYSTEM_TALLOC'):
86 (talloc_includes, talloc_ldflags, talloc_cpppath) = library_flags(bld, 'talloc')
87 extra_includes += talloc_cpppath
88 else:
89 extra_includes += [ '../lib/talloc' ]
91 if bld.CONFIG_SET('USING_SYSTEM_POPT'):
92 (popt_includes, popt_ldflags, popt_cpppath) = library_flags(bld, 'popt')
93 extra_includes += popt_cpppath
94 else:
95 extra_includes += [ '../lib/popt' ]
97 if bld.CONFIG_SET('USING_SYSTEM_INIPARSER'):
98 (iniparser_includes, iniparser_ldflags, iniparser_cpppath) = library_flags(bld, 'iniparser')
99 extra_includes += iniparser_cpppath
100 else:
101 extra_includes += [ '../lib/iniparser' ]
103 # s3 builds assume that they will have a bunch of extra include paths
104 includes = []
105 for d in extra_includes:
106 includes += [ os.path.join(s3reldir, d) ]
108 # the rule may already have some includes listed
109 if 'includes' in kwargs:
110 includes += TO_LIST(kwargs['includes'])
111 kwargs['includes'] = includes
113 # these wrappers allow for mixing of S3 and S4 build rules in the one build
115 def SAMBA3_LIBRARY(bld, name, *args, **kwargs):
116 s3_fix_kwargs(bld, kwargs)
117 return bld.SAMBA_LIBRARY(name, *args, **kwargs)
118 Build.BuildContext.SAMBA3_LIBRARY = SAMBA3_LIBRARY
120 def SAMBA3_MODULE(bld, name, *args, **kwargs):
121 s3_fix_kwargs(bld, kwargs)
122 return bld.SAMBA_MODULE(name, *args, **kwargs)
123 Build.BuildContext.SAMBA3_MODULE = SAMBA3_MODULE
125 def SAMBA3_SUBSYSTEM(bld, name, *args, **kwargs):
126 s3_fix_kwargs(bld, kwargs)
127 return bld.SAMBA_SUBSYSTEM(name, *args, **kwargs)
128 Build.BuildContext.SAMBA3_SUBSYSTEM = SAMBA3_SUBSYSTEM
130 def SAMBA3_BINARY(bld, name, *args, **kwargs):
131 s3_fix_kwargs(bld, kwargs)
132 return bld.SAMBA_BINARY(name, *args, **kwargs)
133 Build.BuildContext.SAMBA3_BINARY = SAMBA3_BINARY
135 def SAMBA3_PYTHON(bld, name, *args, **kwargs):
136 s3_fix_kwargs(bld, kwargs)
137 return bld.SAMBA_PYTHON(name, *args, **kwargs)
138 Build.BuildContext.SAMBA3_PYTHON = SAMBA3_PYTHON