talloc: use the system pytalloc-util for python3 as well
[sfrench/samba-autobuild/.git] / lib / talloc / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'talloc'
4 VERSION = '2.1.9'
5
6
7 blddir = 'bin'
8
9 import Logs
10 import os, sys
11
12 # find the buildtools directory
13 srcdir = '.'
14 while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
15     srcdir = srcdir + '/..'
16 sys.path.insert(0, srcdir + '/buildtools/wafsamba')
17
18 import sys
19 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
20 import wafsamba, samba_dist, Options
21
22 # setup what directories to put in a tarball
23 samba_dist.DIST_DIRS("""lib/talloc:. lib/replace:lib/replace
24 buildtools:buildtools third_party/waf:third_party/waf""")
25
26
27 def set_options(opt):
28     opt.BUILTIN_DEFAULT('replace')
29     opt.PRIVATE_EXTENSION_DEFAULT('talloc', noextension='talloc')
30     opt.RECURSE('lib/replace')
31     if opt.IN_LAUNCH_DIR():
32         opt.add_option('--enable-talloc-compat1',
33                        help=("Build talloc 1.x.x compat library [False]"),
34                        action="store_true", dest='TALLOC_COMPAT1', default=False)
35         opt.add_option('--disable-python',
36                        help=("disable the pytalloc module"),
37                        action="store_true", dest='disable_python', default=False)
38
39
40 def configure(conf):
41     conf.RECURSE('lib/replace')
42
43     conf.env.standalone_talloc = conf.IN_LAUNCH_DIR()
44
45     conf.define('TALLOC_BUILD_VERSION_MAJOR', int(VERSION.split('.')[0]))
46     conf.define('TALLOC_BUILD_VERSION_MINOR', int(VERSION.split('.')[1]))
47     conf.define('TALLOC_BUILD_VERSION_RELEASE', int(VERSION.split('.')[2]))
48
49     conf.env.disable_python = getattr(Options.options, 'disable_python', False)
50
51     conf.env.TALLOC_COMPAT1 = False
52     if conf.env.standalone_talloc:
53         conf.env.TALLOC_COMPAT1 = Options.options.TALLOC_COMPAT1
54         conf.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
55         conf.env.TALLOC_VERSION = VERSION
56
57     conf.CHECK_XSLTPROC_MANPAGES()
58
59     conf.CHECK_HEADERS('sys/auxv.h')
60     conf.CHECK_FUNCS('getauxval')
61
62     conf.SAMBA_CONFIG_H()
63
64     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
65
66     # We need to set everything non-python up before here, because
67     # SAMBA_CHECK_PYTHON makes a copy of conf and we need it set up correctly
68
69     if not conf.env.disable_python:
70         # also disable if we don't have the python libs installed
71         conf.SAMBA_CHECK_PYTHON(mandatory=False, version=(2,4,2))
72         conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
73         if not conf.env.HAVE_PYTHON_H:
74             Logs.warn('Disabling pytalloc-util as python devel libs not found')
75             conf.env.disable_python = True
76
77     if not conf.env.standalone_talloc:
78         if conf.CHECK_BUNDLED_SYSTEM_PKG('talloc', minversion=VERSION,
79                                      implied_deps='replace'):
80             conf.define('USING_SYSTEM_TALLOC', 1)
81
82         using_system_pytalloc_util = True
83         if not conf.CHECK_BUNDLED_SYSTEM_PKG('pytalloc-util', minversion=VERSION,
84                                              implied_deps='talloc replace'):
85             using_system_pytalloc_util = False
86
87         # We need to get a pytalloc-util for all the python versions
88         # we are building for
89         if conf.env['EXTRA_PYTHON']:
90             name = 'pytalloc-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
91             if not conf.CHECK_BUNDLED_SYSTEM_PKG(name, minversion=VERSION,
92                                                  implied_deps='talloc replace'):
93                 using_system_pytalloc_util = False
94
95         if using_system_pytalloc_util:
96             conf.define('USING_SYSTEM_PYTALLOC_UTIL', 1)
97
98
99 def build(bld):
100     bld.RECURSE('lib/replace')
101
102     if bld.env.standalone_talloc:
103         private_library = False
104
105         # should we also install the symlink to libtalloc1.so here?
106         bld.SAMBA_LIBRARY('talloc-compat1-%s' % (VERSION),
107                           'compat/talloc_compat1.c',
108                           public_deps='talloc',
109                           soname='libtalloc.so.1',
110                           pc_files=[],
111                           public_headers=[],
112                           enabled=bld.env.TALLOC_COMPAT1)
113
114         testsuite_deps = 'talloc'
115         if bld.CONFIG_SET('HAVE_PTHREAD'):
116             testsuite_deps += ' pthread'
117
118         bld.SAMBA_BINARY('talloc_testsuite',
119                          'testsuite_main.c testsuite.c',
120                          testsuite_deps,
121                          install=False)
122
123         bld.SAMBA_BINARY('talloc_test_magic_differs_helper',
124                          'test_magic_differs_helper.c',
125                          'talloc', install=False)
126
127     else:
128         private_library = True
129
130     if not bld.CONFIG_SET('USING_SYSTEM_TALLOC'):
131
132         bld.SAMBA_LIBRARY('talloc',
133                           'talloc.c',
134                           deps='replace',
135                           abi_directory='ABI',
136                           abi_match='talloc* _talloc*',
137                           hide_symbols=True,
138                           vnum=VERSION,
139                           public_headers=('' if private_library else 'talloc.h'),
140                           pc_files='talloc.pc',
141                           public_headers_install=not private_library,
142                           private_library=private_library,
143                           manpages='man/talloc.3')
144
145     if not bld.CONFIG_SET('USING_SYSTEM_PYTALLOC_UTIL') and not bld.env.disable_python:
146         for env in bld.gen_python_environments(['PKGCONFIGDIR']):
147             name = bld.pyembed_libname('pytalloc-util')
148
149             bld.SAMBA_LIBRARY(name,
150                 source='pytalloc_util.c',
151                 public_deps='talloc',
152                 pyembed=True,
153                 vnum=VERSION,
154                 hide_symbols=True,
155                 abi_directory='ABI',
156                 abi_match='pytalloc_* _pytalloc_*',
157                 private_library=private_library,
158                 public_headers=('' if private_library else 'pytalloc.h'),
159                 pc_files='pytalloc-util.pc'
160                 )
161             bld.SAMBA_PYTHON('pytalloc',
162                             'pytalloc.c',
163                             deps='talloc ' + name,
164                             realname='talloc.so')
165
166             bld.SAMBA_PYTHON('test_pytalloc',
167                             'test_pytalloc.c',
168                             deps='pytalloc',
169                             realname='_test_pytalloc.so',
170                             install=False)
171
172
173 def test(ctx):
174     '''run talloc testsuite'''
175     import Utils, samba_utils
176     cmd = os.path.join(Utils.g_module.blddir, 'talloc_testsuite')
177     ret = samba_utils.RUN_COMMAND(cmd)
178     print("testsuite returned %d" % ret)
179     magic_helper_cmd = os.path.join(Utils.g_module.blddir, 'talloc_test_magic_differs_helper')
180     magic_cmd = os.path.join(srcdir, 'lib', 'talloc',
181                              'test_magic_differs.sh')
182
183     magic_ret = samba_utils.RUN_COMMAND(magic_cmd + " " +  magic_helper_cmd)
184     print("magic differs test returned %d" % magic_ret)
185     pyret = samba_utils.RUN_PYTHON_TESTS(['test_pytalloc.py'])
186     print("python testsuite returned %d" % pyret)
187     sys.exit(ret or magic_ret or pyret)
188
189 def dist():
190     '''makes a tarball for distribution'''
191     samba_dist.dist()
192
193 def reconfigure(ctx):
194     '''reconfigure if config scripts have changed'''
195     import samba_utils
196     samba_utils.reconfigure(ctx)
197
198
199 def pydoctor(ctx):
200     '''build python apidocs'''
201     cmd='PYTHONPATH=bin/python pydoctor --project-name=talloc --project-url=http://talloc.samba.org/ --make-html --docformat=restructuredtext --introspect-c-modules --add-module bin/python/talloc.*'
202     print("Running: %s" % cmd)
203     os.system(cmd)