1 # a set of config tests that use the samba_autoconf functions
2 # to test for commonly needed configuration options
5 import Build, Configure, Utils, Options, Logs
6 from Configure import conf
7 from samba_utils import TO_LIST, ADD_LD_LIBRARY_PATH
10 def add_option(self, *k, **kw):
11 '''syntax help: provide the "match" attribute to opt.add_option() so that folders can be added to specific config tests'''
12 match = kw.get('match', [])
15 opt = self.parser.add_option(*k, **kw)
18 Options.Handler.add_option = add_option
21 def check(self, *k, **kw):
22 '''Override the waf defaults to inject --with-directory options'''
25 kw['env'] = self.env.copy()
27 # match the configuration test with specific options, for example:
28 # --with-libiconv -> Options.options.iconv_open -> "Checking for library iconv"
32 for x in Options.Handler.parser.parser.option_list:
33 if getattr(x, 'match', None) and msg in x.match:
34 d = getattr(Options.options, x.dest, '')
36 additional_dirs.append(d)
38 # we add the additional dirs twice: once for the test data, and again if the compilation test suceeds below
39 def add_options_dir(dirs, env):
41 if not x in env.CPPPATH:
42 env.CPPPATH = [os.path.join(x, 'include')] + env.CPPPATH
43 if not x in env.LIBPATH:
44 env.LIBPATH = [os.path.join(x, 'lib')] + env.LIBPATH
46 add_options_dir(additional_dirs, kw['env'])
49 self.check_message_1(kw['msg'])
52 ret = self.run_c_code(*k, **kw)
53 except Configure.ConfigurationError, e:
54 self.check_message_2(kw['errmsg'], 'YELLOW')
55 if 'mandatory' in kw and kw['mandatory']:
59 self.fatal('the configuration failed (see %r)' % self.log.name)
62 self.check_message_2(self.ret_msg(kw['okmsg'], kw))
64 # success! keep the CPPPATH/LIBPATH
65 add_options_dir(additional_dirs, self.env)
67 self.post_check(*k, **kw)
68 if not kw.get('execute', False):
74 def CHECK_ICONV(conf, define='HAVE_NATIVE_ICONV'):
75 '''check if the iconv library is installed
76 optionally pass a define'''
77 if conf.CHECK_FUNCS_IN('iconv_open', 'iconv', checklibc=True, headers='iconv.h'):
78 conf.DEFINE(define, 1)
84 def CHECK_LARGEFILE(conf, define='HAVE_LARGEFILE'):
85 '''see what we need for largefile support'''
86 getconf_cflags = conf.CHECK_COMMAND(['getconf', 'LFS_CFLAGS']);
87 if getconf_cflags is not False:
88 if (conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
89 define='WORKING_GETCONF_LFS_CFLAGS',
91 cflags=getconf_cflags,
92 msg='Checking getconf large file support flags work')):
93 conf.ADD_CFLAGS(getconf_cflags)
94 getconf_cflags_list=TO_LIST(getconf_cflags)
95 for flag in getconf_cflags_list:
97 flag_split = flag[2:].split('=')
98 if len(flag_split) == 1:
99 conf.DEFINE(flag_split[0], '1')
101 conf.DEFINE(flag_split[0], flag_split[1])
103 if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
106 msg='Checking for large file support without additional flags'):
109 if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
112 cflags='-D_FILE_OFFSET_BITS=64',
113 msg='Checking for -D_FILE_OFFSET_BITS=64'):
114 conf.DEFINE('_FILE_OFFSET_BITS', 64)
117 if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
120 cflags='-D_LARGE_FILES',
121 msg='Checking for -D_LARGE_FILES'):
122 conf.DEFINE('_LARGE_FILES', 1)
128 def CHECK_C_PROTOTYPE(conf, function, prototype, define, headers=None, msg=None):
129 '''verify that a C prototype matches the one on the current system'''
130 if not conf.CHECK_DECLS(function, headers=headers):
133 msg = 'Checking C prototype for %s' % function
134 return conf.CHECK_CODE('%s; void *_x = (void *)%s' % (prototype, function),
144 def CHECK_CHARSET_EXISTS(conf, charset, outcharset='UCS-2LE', headers=None, define=None):
145 '''check that a named charset is able to be used with iconv_open() for conversion
148 msg = 'Checking if can we convert from %s to %s' % (charset, outcharset)
150 define = 'HAVE_CHARSET_%s' % charset.upper().replace('-','_')
151 return conf.CHECK_CODE('''
152 iconv_t cd = iconv_open("%s", "%s");
153 if (cd == 0 || cd == (iconv_t)-1) return -1;
154 ''' % (charset, outcharset),
161 def find_config_dir(conf):
162 '''find a directory to run tests in'''
165 dir = os.path.join(conf.blddir, '.conf_check_%d' % k)
179 conf.fatal('cannot create a configuration test folder %r' % dir)
184 conf.fatal('cannot use the configuration test folder %r' % dir)
188 def CHECK_SHLIB_INTRASINC_NAME_FLAGS(conf, msg):
190 check if the waf default flags for setting the name of lib
199 return conf.check(features='c cshlib',vnum="1",fragment=snip,msg=msg, mandatory=False)
202 def CHECK_NEED_LC(conf, msg):
203 '''check if we need -lc'''
205 dir = find_config_dir(conf)
209 bdir = os.path.join(dir, 'testbuild2')
210 if not os.path.exists(bdir):
214 subdir = os.path.join(dir, "liblctest")
218 Utils.writef(os.path.join(subdir, 'liblc1.c'), '#include <stdio.h>\nint lib_func(void) { FILE *f = fopen("foo", "r");}\n')
220 bld = Build.BuildContext()
222 bld.all_envs.update(conf.all_envs)
223 bld.all_envs['default'] = env
224 bld.lst_variants = bld.all_envs.keys()
225 bld.load_dirs(dir, bdir)
227 bld.rescan(bld.srcnode)
229 bld(features='c cshlib',
230 source='liblctest/liblc1.c',
231 ldflags=conf.env['EXTRA_LDFLAGS'],
237 conf.check_message(msg, '', True)
240 conf.check_message(msg, '', False)
245 def CHECK_SHLIB_W_PYTHON(conf, msg):
246 '''check if we need -undefined dynamic_lookup'''
248 dir = find_config_dir(conf)
251 #include <crt_externs.h>
252 #define environ (*_NSGetEnviron())
254 static PyObject *ldb_module = NULL;
256 extern char **environ;
258 ldb_module = PyImport_ImportModule("ldb");
261 return conf.check(features='c cshlib',uselib='PYEMBED',fragment=snip,msg=msg, mandatory=False)
263 # this one is quite complex, and should probably be broken up
264 # into several parts. I'd quite like to create a set of CHECK_COMPOUND()
265 # functions that make writing complex compound tests like this much easier
267 def CHECK_LIBRARY_SUPPORT(conf, rpath=False, version_script=False, msg=None):
268 '''see if the platform supports building libraries'''
272 msg = "rpath library support"
274 msg = "building library support"
276 dir = find_config_dir(conf)
278 bdir = os.path.join(dir, 'testbuild')
279 if not os.path.exists(bdir):
284 subdir = os.path.join(dir, "libdir")
288 Utils.writef(os.path.join(subdir, 'lib1.c'), 'int lib_func(void) { return 42; }\n')
289 Utils.writef(os.path.join(dir, 'main.c'),
290 'int lib_func(void);\n'
291 'int main(void) {return !(lib_func() == 42);}\n')
293 bld = Build.BuildContext()
295 bld.all_envs.update(conf.all_envs)
296 bld.all_envs['default'] = env
297 bld.lst_variants = bld.all_envs.keys()
298 bld.load_dirs(dir, bdir)
300 bld.rescan(bld.srcnode)
304 ldflags.append("-Wl,--version-script=%s/vscript" % bld.path.abspath())
305 Utils.writef(os.path.join(dir,'vscript'), 'TEST_1.0A2 { global: *; };\n')
307 bld(features='c cshlib',
308 source='libdir/lib1.c',
309 target='libdir/lib1',
313 o = bld(features='c cprogram',
319 o.rpath=os.path.join(bdir, 'default/libdir')
321 # compile the program
325 conf.check_message(msg, '', False)
329 lastprog = o.link_task.outputs[0].abspath(env)
332 if 'LD_LIBRARY_PATH' in os.environ:
333 old_ld_library_path = os.environ['LD_LIBRARY_PATH']
335 old_ld_library_path = None
336 ADD_LD_LIBRARY_PATH(os.path.join(bdir, 'default/libdir'))
338 # we need to run the program, try to get its result
339 args = conf.SAMBA_CROSS_ARGS(msg=msg)
340 proc = Utils.pproc.Popen([lastprog] + args, stdout=Utils.pproc.PIPE, stderr=Utils.pproc.PIPE)
341 (out, err) = proc.communicate()
346 w('\nreturncode %r\n' % proc.returncode)
347 ret = (proc.returncode == 0)
350 os.environ['LD_LIBRARY_PATH'] = old_ld_library_path or ''
352 conf.check_message(msg, '', ret)
358 def CHECK_PERL_MANPAGE(conf, msg=None, section=None):
359 '''work out what extension perl uses for manpages'''
363 msg = "perl man%s extension" % section
365 msg = "perl manpage generation"
367 conf.check_message_1(msg)
369 dir = find_config_dir(conf)
371 bdir = os.path.join(dir, 'testbuild')
372 if not os.path.exists(bdir):
375 Utils.writef(os.path.join(bdir, 'Makefile.PL'), """
376 use ExtUtils::MakeMaker;
379 'EXE_FILES' => [ 'WafTest' ]
382 back = os.path.abspath('.')
384 proc = Utils.pproc.Popen(['perl', 'Makefile.PL'],
385 stdout=Utils.pproc.PIPE,
386 stderr=Utils.pproc.PIPE)
387 (out, err) = proc.communicate()
390 ret = (proc.returncode == 0)
392 conf.check_message_2('not found', color='YELLOW')
396 man = Utils.readf(os.path.join(bdir,'Makefile'))
397 m = re.search('MAN%sEXT\s+=\s+(\w+)' % section, man)
399 conf.check_message_2('not found', color='YELLOW')
402 conf.check_message_2(ext)
405 conf.check_message_2('ok')
410 def CHECK_COMMAND(conf, cmd, msg=None, define=None, on_target=True, boolean=False):
411 '''run a command and return result'''
413 msg = 'Checking %s' % ' '.join(cmd)
414 conf.COMPOUND_START(msg)
417 cmd.extend(conf.SAMBA_CROSS_ARGS(msg=msg))
419 ret = Utils.cmd_output(cmd)
421 conf.COMPOUND_END(False)
424 conf.COMPOUND_END('ok')
426 conf.DEFINE(define, '1')
429 conf.COMPOUND_END(ret)
431 conf.DEFINE(define, ret, quote=True)
436 def CHECK_UNAME(conf):
437 '''setup SYSTEM_UNAME_* defines'''
439 for v in "sysname machine release version".split():
440 if not conf.CHECK_CODE('''
441 int printf(const char *format, ...);
443 if (uname(&n) == -1) return -1;
446 define='SYSTEM_UNAME_%s' % v.upper(),
450 headers='sys/utsname.h',
452 msg="Checking uname %s type" % v):
457 def CHECK_INLINE(conf):
458 '''check for the right value for inline'''
459 conf.COMPOUND_START('Checking for inline')
460 for i in ['inline', '__inline__', '__inline']:
461 ret = conf.CHECK_CODE('''
463 static %s foo_t static_foo () {return 0; }
464 %s foo_t foo () {return 0; }''' % (i, i),
465 define='INLINE_MACRO',
470 conf.DEFINE('inline', i, quote=False)
473 conf.COMPOUND_END(ret)
479 def CHECK_XSLTPROC_MANPAGES(conf):
480 '''check if xsltproc can run with the given stylesheets'''
483 if not conf.CONFIG_SET('XSLTPROC'):
484 conf.find_program('xsltproc', var='XSLTPROC')
485 if not conf.CONFIG_SET('XSLTPROC'):
488 s='http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
489 conf.CHECK_COMMAND('%s --nonet %s 2> /dev/null' % (conf.env.XSLTPROC, s),
490 msg='Checking for stylesheet %s' % s,
491 define='XSLTPROC_MANPAGES', on_target=False,
493 if not conf.CONFIG_SET('XSLTPROC_MANPAGES'):
494 print "A local copy of the docbook.xsl wasn't found on your system" \
495 " consider installing package like docbook-xsl"
498 # Determine the standard libpath for the used compiler,
499 # so we can later use that to filter out these standard
500 # library paths when some tools like cups-config or
501 # python-config report standard lib paths with their
505 def CHECK_STANDARD_LIBPATH(conf):
506 # at least gcc and clang support this:
508 cmd = conf.env.CC + ['-print-search-dirs']
509 out = Utils.cmd_output(cmd).split('\n')
511 # option not supported by compiler - use a standard list of directories
512 dirlist = [ '/usr/lib', '/usr/lib64' ]
514 raise Utils.WafError('Unexpected error running "%s"' % (cmd))
519 if line.startswith("libraries: ="):
520 dirliststr = line[len("libraries: ="):]
521 dirlist = [ os.path.normpath(x) for x in dirliststr.split(':') ]
524 conf.env.STANDARD_LIBPATH = dirlist