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