pytalloc: Build for two Python versions at once
[sfrench/samba-autobuild/.git] / lib / talloc / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'talloc'
4 VERSION = '2.1.2'
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.env.disable_python = getattr(Options.options, 'disable_python', False)
46
47     if not conf.env.standalone_talloc:
48         if conf.CHECK_BUNDLED_SYSTEM_PKG('talloc', minversion=VERSION,
49                                      implied_deps='replace'):
50             conf.define('USING_SYSTEM_TALLOC', 1)
51         if conf.CHECK_BUNDLED_SYSTEM_PKG('pytalloc-util', minversion=VERSION,
52                                      implied_deps='talloc replace'):
53             conf.define('USING_SYSTEM_PYTALLOC_UTIL', 1)
54
55     conf.env.TALLOC_COMPAT1 = False
56     if conf.env.standalone_talloc:
57         conf.env.TALLOC_COMPAT1 = Options.options.TALLOC_COMPAT1
58
59     conf.CHECK_XSLTPROC_MANPAGES()
60
61     if not conf.env.disable_python:
62         # also disable if we don't have the python libs installed
63         conf.SAMBA_CHECK_PYTHON(mandatory=False, version=(2,4,2))
64         conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
65         if not conf.env.HAVE_PYTHON_H:
66             Logs.warn('Disabling pytalloc-util as python devel libs not found')
67             conf.env.disable_python = True
68
69     conf.SAMBA_CONFIG_H()
70
71     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
72
73
74 def build(bld):
75     bld.RECURSE('lib/replace')
76
77     if bld.env.standalone_talloc:
78         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
79         bld.env.TALLOC_VERSION = VERSION
80         private_library = False
81
82         # should we also install the symlink to libtalloc1.so here?
83         bld.SAMBA_LIBRARY('talloc-compat1-%s' % (VERSION),
84                           'compat/talloc_compat1.c',
85                           public_deps='talloc',
86                           soname='libtalloc.so.1',
87                           pc_files=[],
88                           public_headers=[],
89                           enabled=bld.env.TALLOC_COMPAT1)
90
91         testsuite_deps = 'talloc'
92         if bld.CONFIG_SET('HAVE_PTHREAD'):
93             testsuite_deps += ' pthread'
94
95         bld.SAMBA_BINARY('talloc_testsuite',
96                          'testsuite_main.c testsuite.c',
97                          testsuite_deps,
98                          install=False)
99
100     else:
101         private_library = True
102
103     if not bld.CONFIG_SET('USING_SYSTEM_TALLOC'):
104
105         bld.SAMBA_LIBRARY('talloc',
106                           'talloc.c',
107                           deps='replace',
108                           abi_directory='ABI',
109                           abi_match='talloc* _talloc*',
110                           hide_symbols=True,
111                           vnum=VERSION,
112                           public_headers='talloc.h',
113                           pc_files='talloc.pc',
114                           public_headers_install=not private_library,
115                           private_library=private_library,
116                           manpages='man/talloc.3')
117
118     if not bld.CONFIG_SET('USING_SYSTEM_PYTALLOC_UTIL') and not bld.env.disable_python:
119         name = bld.pyembed_libname('pytalloc-util')
120
121         bld.SAMBA_LIBRARY(name,
122             source='pytalloc_util.c',
123             public_deps='talloc',
124             pyembed=True,
125             vnum=VERSION,
126             hide_symbols=True,
127             abi_directory='ABI',
128             abi_match='pytalloc_*',
129             private_library=private_library,
130             public_headers='pytalloc.h',
131             pc_files='pytalloc-util.pc'
132             )
133         bld.SAMBA_PYTHON('pytalloc',
134                          'pytalloc.c',
135                          deps='talloc ' + name,
136                          enabled=True,
137                          realname='talloc.so')
138
139         bld.SAMBA_PYTHON('test_pytalloc',
140                          'test_pytalloc.c',
141                          deps='pytalloc',
142                          enabled=True,
143                          realname='_test_pytalloc.so',
144                          install=False)
145
146     if bld.env['EXTRA_PYTHON']:
147         for var_name in ('GLOBAL_DEPENDENCIES', 'TARGET_TYPE', 'PKGCONFIGDIR'):
148             bld.all_envs['extrapython'][var_name] = bld.all_envs['default'][var_name]
149         bak = bld.all_envs['default']
150         bld.all_envs['default'] = bld.all_envs['extrapython']
151
152         name = bld.pyembed_libname('pytalloc-util')
153
154         bld.SAMBA_LIBRARY(name,
155             source='pytalloc_util.c',
156             public_deps='talloc',
157             pyembed=True,
158             vnum=VERSION,
159             hide_symbols=True,
160             abi_directory='ABI',
161             abi_match='pytalloc_*',
162             private_library=private_library,
163             #public_headers='pytalloc.h',
164             #pc_files='pytalloc-util.pc'
165             )
166
167         bld.SAMBA_PYTHON('extra-pytalloc',
168                          'pytalloc.c',
169                          deps='talloc ' + name,
170                          enabled=True,
171                          realname='talloc.so')
172
173         bld.SAMBA_PYTHON('extra-test_pytalloc',
174                          'test_pytalloc.c',
175                          deps='pytalloc',
176                          enabled=True,
177                          realname='_test_pytalloc.so',
178                          install=False)
179
180         bld.all_envs['default'] = bak
181
182
183 def test(ctx):
184     '''run talloc testsuite'''
185     import Utils, samba_utils
186     env = samba_utils.LOAD_ENVIRONMENT()
187     cmd = os.path.join(Utils.g_module.blddir, 'talloc_testsuite')
188     ret = samba_utils.RUN_COMMAND(cmd)
189     print("testsuite returned %d" % ret)
190     if 'USING_SYSTEM_PYTALLOC_UTIL' not in env.defines and not env.disable_python:
191         cmd = "PYTHONPATH=%s %s test_pytalloc.py" % (
192             os.path.join(Utils.g_module.blddir, 'python'),
193             env['PYTHON'],
194         )
195         pyret = samba_utils.RUN_COMMAND(cmd)
196     else:
197         pyret = 0
198     print("python testsuite returned %d" % pyret)
199     sys.exit(ret or pyret)
200
201 def dist():
202     '''makes a tarball for distribution'''
203     samba_dist.dist()
204
205 def reconfigure(ctx):
206     '''reconfigure if config scripts have changed'''
207     import samba_utils
208     samba_utils.reconfigure(ctx)
209
210
211 def pydoctor(ctx):
212     '''build python apidocs'''
213     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.*'
214     print("Running: %s" % cmd)
215     os.system(cmd)