1 # a set of config tests that use the samba_autoconf functions
2 # to test for commonly needed configuration options
4 import os
, Build
, shutil
, Utils
, re
5 from Configure
import conf
6 from samba_utils
import *
9 def CHECK_ICONV(conf
, define
='HAVE_NATIVE_ICONV'):
10 '''check if the iconv library is installed
11 optionally pass a define'''
12 if conf
.CHECK_FUNCS_IN('iconv_open', 'iconv', checklibc
=True, headers
='iconv.h'):
13 conf
.DEFINE(define
, 1)
19 def CHECK_LARGEFILE(conf
, define
='HAVE_LARGEFILE'):
20 '''see what we need for largefile support'''
21 getconf_cflags
= conf
.CHECK_COMMAND(['getconf', 'LFS_CFLAGS']);
22 if getconf_cflags
is not False:
23 if (conf
.CHECK_CODE('return !(sizeof(off_t) >= 8)',
24 define
='WORKING_GETCONF_LFS_CFLAGS',
26 cflags
=getconf_cflags
,
27 msg
='Checking getconf large file support flags work')):
28 conf
.ADD_CFLAGS(getconf_cflags
)
29 getconf_cflags_list
=TO_LIST(getconf_cflags
)
30 for flag
in getconf_cflags_list
:
32 flag_split
= flag
[2:].split('=')
33 if len(flag_split
) == 1:
34 conf
.DEFINE(flag_split
[0], '1')
36 conf
.DEFINE(flag_split
[0], flag_split
[1])
38 if conf
.CHECK_CODE('return !(sizeof(off_t) >= 8)',
41 msg
='Checking for large file support without additional flags'):
44 if conf
.CHECK_CODE('return !(sizeof(off_t) >= 8)',
47 cflags
='-D_FILE_OFFSET_BITS=64',
48 msg
='Checking for -D_FILE_OFFSET_BITS=64'):
49 conf
.DEFINE('_FILE_OFFSET_BITS', 64)
55 def CHECK_C_PROTOTYPE(conf
, function
, prototype
, define
, headers
=None, msg
=None):
56 '''verify that a C prototype matches the one on the current system'''
57 if not conf
.CHECK_DECLS(function
, headers
=headers
):
60 msg
= 'Checking C prototype for %s' % function
61 return conf
.CHECK_CODE('%s; void *_x = (void *)%s' % (prototype
, function
),
71 def CHECK_CHARSET_EXISTS(conf
, charset
, outcharset
='UCS-2LE', headers
=None, define
=None):
72 '''check that a named charset is able to be used with iconv_open() for conversion
75 msg
= 'Checking if can we convert from %s to %s' % (charset
, outcharset
)
77 define
= 'HAVE_CHARSET_%s' % charset
.upper().replace('-','_')
78 return conf
.CHECK_CODE('''
79 iconv_t cd = iconv_open("%s", "%s");
80 if (cd == 0 || cd == (iconv_t)-1) return -1;
81 ''' % (charset
, outcharset
),
88 def find_config_dir(conf
):
89 '''find a directory to run tests in'''
92 dir = os
.path
.join(conf
.blddir
, '.conf_check_%d' % k
)
106 conf
.fatal('cannot create a configuration test folder %r' % dir)
111 conf
.fatal('cannot use the configuration test folder %r' % dir)
115 def CHECK_SHLIB_INTRASINC_NAME_FLAGS(conf
, msg
):
117 check if the waf default flags for setting the name of lib
126 return conf
.check(features
='cc cshlib',vnum
="1",fragment
=snip
,msg
=msg
)
129 def CHECK_NEED_LC(conf
, msg
):
130 '''check if we need -lc'''
132 dir = find_config_dir(conf
)
136 bdir
= os
.path
.join(dir, 'testbuild2')
137 if not os
.path
.exists(bdir
):
141 subdir
= os
.path
.join(dir, "liblctest")
145 dest
= open(os
.path
.join(subdir
, 'liblc1.c'), 'w')
146 dest
.write('#include <stdio.h>\nint lib_func(void) { FILE *f = fopen("foo", "r");}\n')
149 bld
= Build
.BuildContext()
151 bld
.all_envs
.update(conf
.all_envs
)
152 bld
.all_envs
['default'] = env
153 bld
.lst_variants
= bld
.all_envs
.keys()
154 bld
.load_dirs(dir, bdir
)
156 bld
.rescan(bld
.srcnode
)
158 bld(features
='cc cshlib',
159 source
='liblctest/liblc1.c',
160 ldflags
=conf
.env
['EXTRA_LDFLAGS'],
166 conf
.check_message(msg
, '', True)
169 conf
.check_message(msg
, '', False)
174 def CHECK_SHLIB_W_PYTHON(conf
, msg
):
175 '''check if we need -undefined dynamic_lookup'''
177 dir = find_config_dir(conf
)
183 #include <crt_externs.h>
184 #define environ (*_NSGetEnviron())
186 static PyObject *ldb_module = NULL;
188 extern char **environ;
190 ldb_module = PyImport_ImportModule("ldb");
193 return conf
.check(features
='cc cshlib',uselib
='PYEMBED',fragment
=snip
,msg
=msg
)
195 # this one is quite complex, and should probably be broken up
196 # into several parts. I'd quite like to create a set of CHECK_COMPOUND()
197 # functions that make writing complex compound tests like this much easier
199 def CHECK_LIBRARY_SUPPORT(conf
, rpath
=False, version_script
=False, msg
=None):
200 '''see if the platform supports building libraries'''
204 msg
= "rpath library support"
206 msg
= "building library support"
208 dir = find_config_dir(conf
)
210 bdir
= os
.path
.join(dir, 'testbuild')
211 if not os
.path
.exists(bdir
):
216 subdir
= os
.path
.join(dir, "libdir")
220 dest
= open(os
.path
.join(subdir
, 'lib1.c'), 'w')
221 dest
.write('int lib_func(void) { return 42; }\n')
224 dest
= open(os
.path
.join(dir, 'main.c'), 'w')
225 dest
.write('int main(void) {return !(lib_func() == 42);}\n')
228 bld
= Build
.BuildContext()
230 bld
.all_envs
.update(conf
.all_envs
)
231 bld
.all_envs
['default'] = env
232 bld
.lst_variants
= bld
.all_envs
.keys()
233 bld
.load_dirs(dir, bdir
)
235 bld
.rescan(bld
.srcnode
)
239 ldflags
.append("-Wl,--version-script=%s/vscript" % bld
.path
.abspath())
240 dest
= open(os
.path
.join(dir,'vscript'), 'w')
241 dest
.write('TEST_1.0A2 { global: *; };\n')
244 bld(features
='cc cshlib',
245 source
='libdir/lib1.c',
246 target
='libdir/lib1',
250 o
= bld(features
='cc cprogram',
256 o
.rpath
=os
.path
.join(bdir
, 'default/libdir')
258 # compile the program
262 conf
.check_message(msg
, '', False)
266 lastprog
= o
.link_task
.outputs
[0].abspath(env
)
269 if 'LD_LIBRARY_PATH' in os
.environ
:
270 old_ld_library_path
= os
.environ
['LD_LIBRARY_PATH']
272 old_ld_library_path
= None
273 ADD_LD_LIBRARY_PATH(os
.path
.join(bdir
, 'default/libdir'))
275 # we need to run the program, try to get its result
276 args
= conf
.SAMBA_CROSS_ARGS(msg
=msg
)
277 proc
= Utils
.pproc
.Popen([lastprog
] + args
, stdout
=Utils
.pproc
.PIPE
, stderr
=Utils
.pproc
.PIPE
)
278 (out
, err
) = proc
.communicate()
283 w('\nreturncode %r\n' % proc
.returncode
)
284 ret
= (proc
.returncode
== 0)
287 os
.environ
['LD_LIBRARY_PATH'] = old_ld_library_path
or ''
289 conf
.check_message(msg
, '', ret
)
295 def CHECK_PERL_MANPAGE(conf
, msg
=None, section
=None):
296 '''work out what extension perl uses for manpages'''
300 msg
= "perl man%s extension" % section
302 msg
= "perl manpage generation"
304 conf
.check_message_1(msg
)
306 dir = find_config_dir(conf
)
308 bdir
= os
.path
.join(dir, 'testbuild')
309 if not os
.path
.exists(bdir
):
312 dest
= open(os
.path
.join(bdir
, 'Makefile.PL'), 'w')
314 use ExtUtils::MakeMaker;
317 'EXE_FILES' => [ 'WafTest' ]
321 back
= os
.path
.abspath('.')
323 proc
= Utils
.pproc
.Popen(['perl', 'Makefile.PL'],
324 stdout
=Utils
.pproc
.PIPE
,
325 stderr
=Utils
.pproc
.PIPE
)
326 (out
, err
) = proc
.communicate()
329 ret
= (proc
.returncode
== 0)
331 conf
.check_message_2('not found', color
='YELLOW')
335 f
= open(os
.path
.join(bdir
,'Makefile'), 'r')
338 m
= re
.search('MAN%sEXT\s+=\s+(\w+)' % section
, man
)
340 conf
.check_message_2('not found', color
='YELLOW')
343 conf
.check_message_2(ext
)
346 conf
.check_message_2('ok')
351 def CHECK_COMMAND(conf
, cmd
, msg
=None, define
=None, on_target
=True, boolean
=False):
352 '''run a command and return result'''
354 msg
= 'Checking %s' % ' '.join(cmd
)
355 conf
.COMPOUND_START(msg
)
358 cmd
.extend(conf
.SAMBA_CROSS_ARGS(msg
=msg
))
360 ret
= Utils
.cmd_output(cmd
)
362 conf
.COMPOUND_END(False)
365 conf
.COMPOUND_END('ok')
367 conf
.DEFINE(define
, '1')
370 conf
.COMPOUND_END(ret
)
372 conf
.DEFINE(define
, ret
, quote
=True)
377 def CHECK_UNAME(conf
):
378 '''setup SYSTEM_UNAME_* defines'''
380 for v
in "sysname machine release version".split():
381 if not conf
.CHECK_CODE('''
383 if (uname(&n) == -1) return -1;
386 define
='SYSTEM_UNAME_%s' % v
.upper(),
390 headers
='sys/utsname.h',
392 msg
="Checking uname %s type" % v
):
397 def CHECK_INLINE(conf
):
398 '''check for the right value for inline'''
399 conf
.COMPOUND_START('Checking for inline')
400 for i
in ['inline', '__inline__', '__inline']:
401 ret
= conf
.CHECK_CODE('''
403 static %s foo_t static_foo () {return 0; }
404 %s foo_t foo () {return 0; }''' % (i
, i
),
405 define
='INLINE_MACRO',
410 conf
.DEFINE('inline', i
, quote
=False)
413 conf
.COMPOUND_END(ret
)
419 def CHECK_XSLTPROC_MANPAGES(conf
):
420 '''check if xsltproc can run with the given stylesheets'''
423 if not conf
.CONFIG_SET('XSLTPROC'):
424 conf
.find_program('xsltproc', var
='XSLTPROC')
425 if not conf
.CONFIG_SET('XSLTPROC'):
428 s
='http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
429 conf
.CHECK_COMMAND('%s --nonet %s 2> /dev/null' % (conf
.env
.XSLTPROC
, s
),
430 msg
='Checking for stylesheet %s' % s
,
431 define
='XSLTPROC_MANPAGES', on_target
=False,