1#!/usr/bin/env python 2 3APPNAME = 'talloc' 4VERSION = '2.3.1' 5 6import os 7import sys 8 9# find the buildtools directory 10top = '.' 11while not os.path.exists(top+'/buildtools') and len(top.split('/')) < 5: 12 top = top + '/..' 13sys.path.insert(0, top + '/buildtools/wafsamba') 14 15out = 'bin' 16 17import wafsamba 18from wafsamba import samba_dist, samba_utils 19from waflib import Logs, Options, Context 20 21# setup what directories to put in a tarball 22samba_dist.DIST_DIRS("""lib/talloc:. lib/replace:lib/replace 23buildtools:buildtools third_party/waf:third_party/waf""") 24 25 26def 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 36def 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 conf.SAMBA_CHECK_PYTHON() 61 conf.SAMBA_CHECK_PYTHON_HEADERS() 62 63 if not conf.env.standalone_talloc: 64 if conf.CHECK_BUNDLED_SYSTEM_PKG('talloc', minversion=VERSION, 65 implied_deps='replace'): 66 conf.define('USING_SYSTEM_TALLOC', 1) 67 68 if conf.env.disable_python: 69 using_system_pytalloc_util = False 70 else: 71 using_system_pytalloc_util = True 72 name = 'pytalloc-util' + conf.all_envs['default']['PYTHON_SO_ABI_FLAG'] 73 if not conf.CHECK_BUNDLED_SYSTEM_PKG(name, minversion=VERSION, 74 implied_deps='talloc replace'): 75 using_system_pytalloc_util = False 76 77 if using_system_pytalloc_util: 78 conf.define('USING_SYSTEM_PYTALLOC_UTIL', 1) 79 80 81def build(bld): 82 bld.RECURSE('lib/replace') 83 84 if bld.env.standalone_talloc: 85 private_library = False 86 87 # should we also install the symlink to libtalloc1.so here? 88 bld.SAMBA_LIBRARY('talloc-compat1-%s' % (VERSION), 89 'compat/talloc_compat1.c', 90 public_deps='talloc', 91 soname='libtalloc.so.1', 92 pc_files=[], 93 public_headers=[], 94 enabled=bld.env.TALLOC_COMPAT1) 95 96 testsuite_deps = 'talloc' 97 if bld.CONFIG_SET('HAVE_PTHREAD'): 98 testsuite_deps += ' pthread' 99 100 bld.SAMBA_BINARY('talloc_testsuite', 101 'testsuite_main.c testsuite.c', 102 testsuite_deps, 103 install=False) 104 105 bld.SAMBA_BINARY('talloc_test_magic_differs_helper', 106 'test_magic_differs_helper.c', 107 'talloc', install=False) 108 109 else: 110 private_library = True 111 112 if not bld.CONFIG_SET('USING_SYSTEM_TALLOC'): 113 114 bld.SAMBA_LIBRARY('talloc', 115 'talloc.c', 116 deps='replace', 117 abi_directory='ABI', 118 abi_match='talloc* _talloc*', 119 hide_symbols=True, 120 vnum=VERSION, 121 public_headers=('' if private_library else 'talloc.h'), 122 pc_files='talloc.pc', 123 public_headers_install=not private_library, 124 private_library=private_library, 125 manpages='man/talloc.3') 126 127 if not bld.CONFIG_SET('USING_SYSTEM_PYTALLOC_UTIL'): 128 name = bld.pyembed_libname('pytalloc-util') 129 130 bld.SAMBA_LIBRARY(name, 131 source='pytalloc_util.c', 132 public_deps='talloc', 133 pyembed=True, 134 vnum=VERSION, 135 hide_symbols=True, 136 abi_directory='ABI', 137 abi_match='pytalloc_* _pytalloc_*', 138 private_library=private_library, 139 public_headers=('' if private_library else 'pytalloc.h'), 140 pc_files='pytalloc-util.pc', 141 enabled=bld.PYTHON_BUILD_IS_ENABLED() 142 ) 143 bld.SAMBA_PYTHON('pytalloc', 144 'pytalloc.c', 145 deps='talloc ' + name, 146 enabled=bld.PYTHON_BUILD_IS_ENABLED(), 147 realname='talloc.so') 148 149 bld.SAMBA_PYTHON('test_pytalloc', 150 'test_pytalloc.c', 151 deps=name, 152 enabled=bld.PYTHON_BUILD_IS_ENABLED(), 153 realname='_test_pytalloc.so', 154 install=False) 155 156 157def testonly(ctx): 158 '''run talloc testsuite''' 159 import samba_utils 160 161 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared') 162 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private') 163 164 cmd = os.path.join(Context.g_module.out, 'talloc_testsuite') 165 ret = samba_utils.RUN_COMMAND(cmd) 166 print("testsuite returned %d" % ret) 167 magic_helper_cmd = os.path.join(Context.g_module.out, 'talloc_test_magic_differs_helper') 168 magic_cmd = os.path.join(Context.g_module.top, 'lib', 'talloc', 169 'test_magic_differs.sh') 170 if not os.path.exists(magic_cmd): 171 magic_cmd = os.path.join(Context.g_module.top, 'test_magic_differs.sh') 172 173 magic_ret = samba_utils.RUN_COMMAND(magic_cmd + " " + magic_helper_cmd) 174 print("magic differs test returned %d" % magic_ret) 175 pyret = samba_utils.RUN_PYTHON_TESTS(['test_pytalloc.py']) 176 print("python testsuite returned %d" % pyret) 177 sys.exit(ret or magic_ret or pyret) 178 179# WAF doesn't build the unit tests for this, maybe because they don't link with talloc? 180# This forces it 181def test(ctx): 182 Options.commands.append('build') 183 Options.commands.append('testonly') 184 185def dist(): 186 '''makes a tarball for distribution''' 187 samba_dist.dist() 188 189def reconfigure(ctx): 190 '''reconfigure if config scripts have changed''' 191 samba_utils.reconfigure(ctx) 192 193 194def pydoctor(ctx): 195 '''build python apidocs''' 196 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.*' 197 print("Running: %s" % cmd) 198 os.system(cmd) 199