build: Reduce build systems to just top level waf and autoconf
[amitay/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     # the extra_includes list is relative to the source3 directory
54     extra_includes = [ '.', 'include', 'lib', '../lib/tdb_compat' ]
55     if not bld.CONFIG_SET("USING_SYSTEM_KRB5"):
56         extra_includes += [ '../source4/heimdal/lib/com_err',
57                             '../source4/heimdal/lib/gssapi',
58                             '../source4/heimdal_build' ]
59
60     if bld.CONFIG_SET('BUILD_TDB2'):
61         if not bld.CONFIG_SET('USING_SYSTEM_TDB2'):
62             extra_includes += [ '../lib/tdb2' ]
63     else:
64         if not bld.CONFIG_SET('USING_SYSTEM_TDB'):
65             extra_includes += [ '../lib/tdb/include' ]
66
67     if not bld.CONFIG_SET('USING_SYSTEM_TEVENT'):
68         extra_includes += [ '../lib/tevent' ]
69
70     if not bld.CONFIG_SET('USING_SYSTEM_TALLOC'):
71         extra_includes += [ '../lib/talloc' ]
72
73     if not bld.CONFIG_SET('USING_SYSTEM_POPT'):
74         extra_includes += [ '../lib/popt' ]
75
76     # s3 builds assume that they will have a bunch of extra include paths
77     includes = []
78     for d in extra_includes:
79         includes += [ os.path.join(s3reldir, d) ]
80
81     # the rule may already have some includes listed
82     if 'includes' in kwargs:
83         includes += TO_LIST(kwargs['includes'])
84     kwargs['includes'] = includes
85
86     # some S3 code assumes that CONFIGFILE is set
87     cflags = ['-DCONFIGFILE="%s"' % bld.env['CONFIGFILE']]
88     if 'cflags' in kwargs:
89         cflags += TO_LIST(kwargs['cflags'])
90     kwargs['cflags'] = cflags
91
92 # these wrappers allow for mixing of S3 and S4 build rules in the one build
93
94 def SAMBA3_LIBRARY(bld, name, *args, **kwargs):
95         s3_fix_kwargs(bld, kwargs)
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         return bld.SAMBA_MODULE(name, *args, **kwargs)
102 Build.BuildContext.SAMBA3_MODULE = SAMBA3_MODULE
103
104 def SAMBA3_SUBSYSTEM(bld, name, *args, **kwargs):
105         s3_fix_kwargs(bld, kwargs)
106         return bld.SAMBA_SUBSYSTEM(name, *args, **kwargs)
107 Build.BuildContext.SAMBA3_SUBSYSTEM = SAMBA3_SUBSYSTEM
108
109 def SAMBA3_BINARY(bld, name, *args, **kwargs):
110         s3_fix_kwargs(bld, kwargs)
111         return bld.SAMBA_BINARY(name, *args, **kwargs)
112 Build.BuildContext.SAMBA3_BINARY = SAMBA3_BINARY
113
114 def SAMBA3_PYTHON(bld, name, *args, **kwargs):
115     s3_fix_kwargs(bld, kwargs)
116     return bld.SAMBA_PYTHON(name, *args, **kwargs)
117 Build.BuildContext.SAMBA3_PYTHON = SAMBA3_PYTHON