HACK compile kqueue backend
[metze/samba/wip.git] / lib / tevent / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'tevent'
4 VERSION = '0.9.30'
5
6 blddir = 'bin'
7
8 import sys, os
9
10 # find the buildtools directory
11 srcdir = '.'
12 while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
13     srcdir = srcdir + '/..'
14 sys.path.insert(0, srcdir + '/buildtools/wafsamba')
15
16 import wafsamba, samba_dist, samba_utils, Options, Logs
17
18 samba_dist.DIST_DIRS('lib/tevent:. lib/replace:lib/replace lib/talloc:lib/talloc buildtools:buildtools third_party/waf:third_party/waf')
19
20 def set_options(opt):
21     opt.BUILTIN_DEFAULT('replace')
22     opt.PRIVATE_EXTENSION_DEFAULT('tevent', noextension='tevent')
23     opt.RECURSE('lib/replace')
24     opt.RECURSE('lib/talloc')
25     if opt.IN_LAUNCH_DIR():
26         opt.add_option('--disable-python',
27                        help=("disable the pytevent module"),
28                        action="store_true", dest='disable_python', default=False)
29
30
31 def configure(conf):
32     conf.RECURSE('lib/replace')
33     conf.RECURSE('lib/talloc')
34
35     conf.env.standalone_tevent = conf.IN_LAUNCH_DIR()
36
37     if not conf.env.standalone_tevent:
38         if conf.CHECK_BUNDLED_SYSTEM_PKG('tevent', minversion=VERSION,
39                                      onlyif='talloc', implied_deps='replace talloc'):
40             conf.define('USING_SYSTEM_TEVENT', 1)
41             if conf.CHECK_BUNDLED_SYSTEM_PYTHON('pytevent', 'tevent', minversion=VERSION):
42                 conf.define('USING_SYSTEM_PYTEVENT', 1)
43
44     if conf.CHECK_FUNCS('epoll_create', headers='sys/epoll.h'):
45         conf.DEFINE('HAVE_EPOLL', 1)
46
47     if conf.CHECK_FUNCS('kqueue', headers='sys/types.h sys/event.h sys/time.h'):
48         conf.DEFINE('HAVE_KQUEUE', 1)
49     conf.DEFINE('HAVE_KQUEUE', 1) # HACK
50
51     tevent_num_signals = 64
52     v = conf.CHECK_VALUEOF('NSIG', headers='signal.h')
53     if v is not None:
54         tevent_num_signals = max(tevent_num_signals, v)
55     v = conf.CHECK_VALUEOF('_NSIG', headers='signal.h')
56     if v is not None:
57         tevent_num_signals = max(tevent_num_signals, v)
58     v = conf.CHECK_VALUEOF('SIGRTMAX', headers='signal.h')
59     if v is not None:
60         tevent_num_signals = max(tevent_num_signals, v)
61     v = conf.CHECK_VALUEOF('SIGRTMIN', headers='signal.h')
62     if v is not None:
63         tevent_num_signals = max(tevent_num_signals, v*2)
64
65     if not conf.CONFIG_SET('USING_SYSTEM_TEVENT'):
66         conf.DEFINE('TEVENT_NUM_SIGNALS', tevent_num_signals)
67
68     conf.env.disable_python = getattr(Options.options, 'disable_python', False)
69
70     if not conf.env.disable_python:
71         # also disable if we don't have the python libs installed
72         conf.find_program('python', var='PYTHON')
73         conf.check_tool('python')
74         conf.check_python_version((2,4,2))
75         conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
76         if not conf.env.HAVE_PYTHON_H:
77             Logs.warn('Disabling pytevent as python devel libs not found')
78             conf.env.disable_python = True
79
80     conf.SAMBA_CONFIG_H()
81
82     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
83
84 def build(bld):
85     bld.RECURSE('lib/replace')
86     bld.RECURSE('lib/talloc')
87
88     SRC = '''tevent.c tevent_debug.c tevent_fd.c tevent_immediate.c
89              tevent_queue.c tevent_req.c tevent_select.c
90              tevent_poll.c tevent_threads.c
91              tevent_signal.c tevent_standard.c tevent_timed.c tevent_util.c tevent_wakeup.c'''
92
93     if bld.CONFIG_SET('HAVE_EPOLL'):
94         SRC += ' tevent_epoll.c'
95
96     if bld.CONFIG_SET('HAVE_SOLARIS_PORTS'):
97         SRC += ' tevent_port.c'
98     if bld.CONFIG_SET('HAVE_KQUEUE'):
99         SRC += ' tevent_kqueue.c'
100
101     if bld.env.standalone_tevent:
102         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
103         private_library = False
104     else:
105         private_library = True
106
107     if not bld.CONFIG_SET('USING_SYSTEM_TEVENT'):
108         tevent_deps = 'replace talloc'
109         if bld.CONFIG_SET('HAVE_PTHREAD'):
110             tevent_deps += ' pthread'
111
112         bld.SAMBA_LIBRARY('tevent',
113                           SRC,
114                           deps=tevent_deps,
115                           enabled= not bld.CONFIG_SET('USING_SYSTEM_TEVENT'),
116                           includes='.',
117                           abi_directory='ABI',
118                           abi_match='tevent_* _tevent_*',
119                           vnum=VERSION,
120                           public_headers=('' if private_library else 'tevent.h'),
121                           public_headers_install=not private_library,
122                           pc_files='tevent.pc',
123                           private_library=private_library)
124
125     if not bld.CONFIG_SET('USING_SYSTEM_PYTEVENT') and not bld.env.disable_python:
126         for env in bld.gen_python_environments(['PKGCONFIGDIR']):
127             bld.SAMBA_PYTHON('_tevent',
128                             'pytevent.c',
129                             deps='tevent',
130                             realname='_tevent.so',
131                             cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
132
133
134             bld.INSTALL_WILDCARD('${PYTHONARCHDIR}', 'tevent.py', flat=False)
135
136         # install out various python scripts for use by make test
137         bld.SAMBA_SCRIPT('tevent_python',
138                          pattern='tevent.py',
139                          installdir='python')
140
141
142 def test(ctx):
143     '''test tevent'''
144     print("The tevent testsuite is part of smbtorture in samba4")
145
146     samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
147     samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
148
149     pyret = samba_utils.RUN_PYTHON_TESTS(['bindings.py'])
150     sys.exit(pyret)
151
152
153 def dist():
154     '''makes a tarball for distribution'''
155     samba_dist.dist()
156
157 def reconfigure(ctx):
158     '''reconfigure if config scripts have changed'''
159     import samba_utils
160     samba_utils.reconfigure(ctx)