6759450f60533ad1bd69740a49ea89198a911a9f
[samba.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
8 def SAMBA3_ADD_OPTION(opt, option, help=(), dest=None, default=True,
9                       with_name="with", without_name="without"):
10     if help == ():
11         help = ("Build with %s support" % option)
12     if dest is None:
13         dest = "with_%s" % option.replace('-', '_')
14
15     with_val = "--%s-%s" % (with_name, option)
16     without_val = "--%s-%s" % (without_name, option)
17
18     #FIXME: This is broken and will always default to "default" no matter if
19     # --with or --without is chosen.
20     opt.add_option(with_val, help=help, action="store_true", dest=dest,
21                    default=default)
22     opt.add_option(without_val, help=SUPPRESS_HELP, action="store_false",
23                    dest=dest)
24 Options.Handler.SAMBA3_ADD_OPTION = SAMBA3_ADD_OPTION
25
26 def SAMBA3_IS_STATIC_MODULE(bld, module):
27     '''Check whether module is in static list'''
28     if module in bld.env['static_modules']:
29         return True
30     return False
31 Build.BuildContext.SAMBA3_IS_STATIC_MODULE = SAMBA3_IS_STATIC_MODULE
32
33 def SAMBA3_IS_SHARED_MODULE(bld, module):
34     '''Check whether module is in shared list'''
35     if module in bld.env['shared_modules']:
36         return True
37     return False
38 Build.BuildContext.SAMBA3_IS_SHARED_MODULE = SAMBA3_IS_SHARED_MODULE
39
40 def SAMBA3_IS_ENABLED_MODULE(bld, module):
41     '''Check whether module is in either shared or static list '''
42     return SAMBA3_IS_STATIC_MODULE(bld, module) or SAMBA3_IS_SHARED_MODULE(bld, module)
43 Build.BuildContext.SAMBA3_IS_ENABLED_MODULE = SAMBA3_IS_ENABLED_MODULE
44
45
46
47 def s3_fix_kwargs(bld, kwargs):
48     '''fix the build arguments for s3 build rules to include the
49         necessary includes, subdir and cflags options '''
50     s3dir = os.path.join(bld.env.srcdir, 'source3')
51     s3reldir = os_path_relpath(s3dir, bld.curdir)
52
53     # cope with the fact that the s3 waf rules were originally written
54     # assuming relative paths to source3/. This only triggers when using the
55     # wscript rules in s3build/
56     if bld.curdir.endswith("/s3build") and not 'subdir' in kwargs:
57         kwargs['subdir'] = s3reldir
58
59     # the extra_includes list is relative to the source3 directory
60     extra_includes = [ '.', 'include', 'lib' ]
61     if bld.env.use_intree_heimdal:
62         extra_includes += [ '../source4/heimdal/lib/com_err',
63                             '../source4/heimdal/lib/gssapi',
64                             '../source4/heimdal_build' ]
65
66     if not bld.CONFIG_SET('USING_SYSTEM_TDB'):
67         extra_includes += [ '../lib/tdb/include' ]
68
69     if not bld.CONFIG_SET('USING_SYSTEM_TEVENT'):
70         extra_includes += [ '../lib/tevent' ]
71
72     if not bld.CONFIG_SET('USING_SYSTEM_TALLOC'):
73         extra_includes += [ '../lib/talloc' ]
74
75     # s3 builds assume that they will have a bunch of extra include paths
76     includes = []
77     for d in extra_includes:
78         includes += [ os.path.join(s3reldir, d) ]
79
80     # the rule may already have some includes listed
81     if 'includes' in kwargs:
82         includes += TO_LIST(kwargs['includes'])
83     kwargs['includes'] = includes
84
85     # some S3 code assumes that CONFIGFILE is set
86     cflags = ['-DCONFIGFILE="%s"' % bld.env['CONFIGFILE']]
87     if 'cflags' in kwargs:
88         cflags += TO_LIST(kwargs['cflags'])
89     kwargs['cflags'] = cflags
90
91 # these wrappers allow for mixing of S3 and S4 build rules in the one build
92
93 def SAMBA3_LIBRARY(bld, name, *args, **kwargs):
94         s3_fix_kwargs(bld, kwargs)
95         kwargs['allow_undefined_symbols'] = True
96         return bld.SAMBA_LIBRARY(name, *args, **kwargs)
97 Build.BuildContext.SAMBA3_LIBRARY = SAMBA3_LIBRARY
98
99 def SAMBA3_MODULE(bld, name, *args, **kwargs):
100         s3_fix_kwargs(bld, kwargs)
101         kwargs['allow_undefined_symbols'] = True
102         return bld.SAMBA_MODULE(name, *args, **kwargs)
103 Build.BuildContext.SAMBA3_MODULE = SAMBA3_MODULE
104
105 def SAMBA3_SUBSYSTEM(bld, name, *args, **kwargs):
106         s3_fix_kwargs(bld, kwargs)
107         return bld.SAMBA_SUBSYSTEM(name, *args, **kwargs)
108 Build.BuildContext.SAMBA3_SUBSYSTEM = SAMBA3_SUBSYSTEM
109
110 def SAMBA3_BINARY(bld, name, *args, **kwargs):
111         s3_fix_kwargs(bld, kwargs)
112         return bld.SAMBA_BINARY(name, *args, **kwargs)
113 Build.BuildContext.SAMBA3_BINARY = SAMBA3_BINARY