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