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