talloc: version 2.1.9
[samba.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     if not conf.env.standalone_talloc:
52         if conf.CHECK_BUNDLED_SYSTEM_PKG('talloc', minversion=VERSION,
53                                      implied_deps='replace'):
54             conf.define('USING_SYSTEM_TALLOC', 1)
55         if conf.CHECK_BUNDLED_SYSTEM_PKG('pytalloc-util', minversion=VERSION,
56                                      implied_deps='talloc replace'):
57             conf.define('USING_SYSTEM_PYTALLOC_UTIL', 1)
58
59     conf.env.TALLOC_COMPAT1 = False
60     if conf.env.standalone_talloc:
61         conf.env.TALLOC_COMPAT1 = Options.options.TALLOC_COMPAT1
62
63     conf.CHECK_XSLTPROC_MANPAGES()
64
65     if not conf.env.disable_python:
66         # also disable if we don't have the python libs installed
67         conf.SAMBA_CHECK_PYTHON(mandatory=False, version=(2,4,2))
68         conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
69         if not conf.env.HAVE_PYTHON_H:
70             Logs.warn('Disabling pytalloc-util as python devel libs not found')
71             conf.env.disable_python = True
72
73     conf.CHECK_HEADERS('sys/auxv.h')
74     conf.CHECK_FUNCS('getauxval')
75
76     conf.SAMBA_CONFIG_H()
77
78     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
79
80
81 def build(bld):
82     bld.RECURSE('lib/replace')
83
84     if bld.env.standalone_talloc:
85         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
86         bld.env.TALLOC_VERSION = VERSION
87         private_library = False
88
89         # should we also install the symlink to libtalloc1.so here?
90         bld.SAMBA_LIBRARY('talloc-compat1-%s' % (VERSION),
91                           'compat/talloc_compat1.c',
92                           public_deps='talloc',
93                           soname='libtalloc.so.1',
94                           pc_files=[],
95                           public_headers=[],
96                           enabled=bld.env.TALLOC_COMPAT1)
97
98         testsuite_deps = 'talloc'
99         if bld.CONFIG_SET('HAVE_PTHREAD'):
100             testsuite_deps += ' pthread'
101
102         bld.SAMBA_BINARY('talloc_testsuite',
103                          'testsuite_main.c testsuite.c',
104                          testsuite_deps,
105                          install=False)
106
107         bld.SAMBA_BINARY('talloc_test_magic_differs_helper',
108                          'test_magic_differs_helper.c',
109                          'talloc', install=False)
110
111     else:
112         private_library = True
113
114     if not bld.CONFIG_SET('USING_SYSTEM_TALLOC'):
115
116         bld.SAMBA_LIBRARY('talloc',
117                           'talloc.c',
118                           deps='replace',
119                           abi_directory='ABI',
120                           abi_match='talloc* _talloc*',
121                           hide_symbols=True,
122                           vnum=VERSION,
123                           public_headers=('' if private_library else 'talloc.h'),
124                           pc_files='talloc.pc',
125                           public_headers_install=not private_library,
126                           private_library=private_library,
127                           manpages='man/talloc.3')
128
129     if not bld.CONFIG_SET('USING_SYSTEM_PYTALLOC_UTIL') and not bld.env.disable_python:
130         for env in bld.gen_python_environments(['PKGCONFIGDIR']):
131             name = bld.pyembed_libname('pytalloc-util')
132
133             bld.SAMBA_LIBRARY(name,
134                 source='pytalloc_util.c',
135                 public_deps='talloc',
136                 pyembed=True,
137                 vnum=VERSION,
138                 hide_symbols=True,
139                 abi_directory='ABI',
140                 abi_match='pytalloc_* _pytalloc_*',
141                 private_library=private_library,
142                 public_headers=('' if private_library else 'pytalloc.h'),
143                 pc_files='pytalloc-util.pc'
144                 )
145             bld.SAMBA_PYTHON('pytalloc',
146                             'pytalloc.c',
147                             deps='talloc ' + name,
148                             realname='talloc.so')
149
150             bld.SAMBA_PYTHON('test_pytalloc',
151                             'test_pytalloc.c',
152                             deps='pytalloc',
153                             realname='_test_pytalloc.so',
154                             install=False)
155
156
157 def test(ctx):
158     '''run talloc testsuite'''
159     import Utils, samba_utils
160     cmd = os.path.join(Utils.g_module.blddir, 'talloc_testsuite')
161     ret = samba_utils.RUN_COMMAND(cmd)
162     print("testsuite returned %d" % ret)
163     magic_helper_cmd = os.path.join(Utils.g_module.blddir, 'talloc_test_magic_differs_helper')
164     magic_cmd = os.path.join(srcdir, 'lib', 'talloc',
165                              'test_magic_differs.sh')
166
167     magic_ret = samba_utils.RUN_COMMAND(magic_cmd + " " +  magic_helper_cmd)
168     print("magic differs test returned %d" % magic_ret)
169     pyret = samba_utils.RUN_PYTHON_TESTS(['test_pytalloc.py'])
170     print("python testsuite returned %d" % pyret)
171     sys.exit(ret or magic_ret or pyret)
172
173 def dist():
174     '''makes a tarball for distribution'''
175     samba_dist.dist()
176
177 def reconfigure(ctx):
178     '''reconfigure if config scripts have changed'''
179     import samba_utils
180     samba_utils.reconfigure(ctx)
181
182
183 def pydoctor(ctx):
184     '''build python apidocs'''
185     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.*'
186     print("Running: %s" % cmd)
187     os.system(cmd)