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
6 from Configure
import conf
8 from samba_utils
import *
11 def add_option(self
, *k
, **kw
):
12 '''syntax help: provide the "match" attribute to opt.add_option() so that folders can be added to specific config tests'''
13 match
= kw
.get('match', [])
16 opt
= self
.parser
.add_option(*k
, **kw
)
19 Options
.Handler
.add_option
= add_option
22 def check(self
, *k
, **kw
):
23 '''Override the waf defaults to inject --with-directory options'''
26 kw
['env'] = self
.env
.copy()
28 # match the configuration test with speficic options, for example:
29 # --with-libiconv -> Options.options.iconv_open -> "Checking for library iconv"
33 for x
in Options
.Handler
.parser
.parser
.option_list
:
34 if getattr(x
, 'match', None) and msg
in x
.match
:
35 d
= getattr(Options
.options
, x
.dest
, '')
37 additional_dirs
.append(d
)
39 # we add the additional dirs twice: once for the test data, and again if the compilation test suceeds below
40 def add_options_dir(dirs
, env
):
42 if not x
in env
.CPPPATH
:
43 env
.CPPPATH
= [os
.path
.join(x
, 'include')] + env
.CPPPATH
44 if not x
in env
.LIBPATH
:
45 env
.LIBPATH
= [os
.path
.join(x
, 'lib')] + env
.LIBPATH
47 add_options_dir(additional_dirs
, kw
['env'])
50 self
.check_message_1(kw
['msg'])
53 ret
= self
.run_c_code(*k
, **kw
)
54 except Configure
.ConfigurationError
, e
:
55 self
.check_message_2(kw
['errmsg'], 'YELLOW')
56 if 'mandatory' in kw
and kw
['mandatory']:
60 self
.fatal('the configuration failed (see %r)' % self
.log
.name
)
63 self
.check_message_2(self
.ret_msg(kw
['okmsg'], kw
))
65 # success! keep the CPPPATH/LIBPATH
66 add_options_dir(additional_dirs
, self
.env
)
68 self
.post_check(*k
, **kw
)
69 if not kw
.get('execute', False):
75 def CHECK_ICONV(conf
, define
='HAVE_NATIVE_ICONV'):
76 '''check if the iconv library is installed
77 optionally pass a define'''
78 if conf
.CHECK_FUNCS_IN('iconv_open', 'iconv', checklibc
=True, headers
='iconv.h'):
79 conf
.DEFINE(define
, 1)
85 def CHECK_LARGEFILE(conf
, define
='HAVE_LARGEFILE'):
86 '''see what we need for largefile support'''
87 getconf_cflags
= conf
.CHECK_COMMAND(['getconf', 'LFS_CFLAGS']);
88 if getconf_cflags
is not False:
89 if (conf
.CHECK_CODE('return !(sizeof(off_t) >= 8)',
90 define
='WORKING_GETCONF_LFS_CFLAGS',
92 cflags
=getconf_cflags
,
93 msg
='Checking getconf large file support flags work')):
94 conf
.ADD_CFLAGS(getconf_cflags
)
95 getconf_cflags_list
=TO_LIST(getconf_cflags
)
96 for flag
in getconf_cflags_list
:
98 flag_split
= flag
[2:].split('=')
99 if len(flag_split
) == 1:
100 conf
.DEFINE(flag_split
[0], '1')
102 conf
.DEFINE(flag_split
[0], flag_split
[1])
104 if conf
.CHECK_CODE('return !(sizeof(off_t) >= 8)',
107 msg
='Checking for large file support without additional flags'):
110 if conf
.CHECK_CODE('return !(sizeof(off_t) >= 8)',
113 cflags
='-D_FILE_OFFSET_BITS=64',
114 msg
='Checking for -D_FILE_OFFSET_BITS=64'):
115 conf
.DEFINE('_FILE_OFFSET_BITS', 64)
118 if conf
.CHECK_CODE('return !(sizeof(off_t) >= 8)',
121 cflags
='-D_LARGE_FILES',
122 msg
='Checking for -D_LARGE_FILES'):
123 conf
.DEFINE('_LARGE_FILES', 1)
129 def CHECK_C_PROTOTYPE(conf
, function
, prototype
, define
, headers
=None, msg
=None):
130 '''verify that a C prototype matches the one on the current system'''
131 if not conf
.CHECK_DECLS(function
, headers
=headers
):
134 msg
= 'Checking C prototype for %s' % function
135 return conf
.CHECK_CODE('%s; void *_x = (void *)%s' % (prototype
, function
),
145 def CHECK_CHARSET_EXISTS(conf
, charset
, outcharset
='UCS-2LE', headers
=None, define
=None):
146 '''check that a named charset is able to be used with iconv_open() for conversion
149 msg
= 'Checking if can we convert from %s to %s' % (charset
, outcharset
)
151 define
= 'HAVE_CHARSET_%s' % charset
.upper().replace('-','_')
152 return conf
.CHECK_CODE('''
153 iconv_t cd = iconv_open("%s", "%s");
154 if (cd == 0 || cd == (iconv_t)-1) return -1;
155 ''' % (charset
, outcharset
),
162 def find_config_dir(conf
):
163 '''find a directory to run tests in'''
166 dir = os
.path
.join(conf
.blddir
, '.conf_check_%d' % k
)
180 conf
.fatal('cannot create a configuration test folder %r' % dir)
185 conf
.fatal('cannot use the configuration test folder %r' % dir)
189 def CHECK_SHLIB_INTRASINC_NAME_FLAGS(conf
, msg
):
191 check if the waf default flags for setting the name of lib
200 return conf
.check(features
='cc cshlib',vnum
="1",fragment
=snip
,msg
=msg
)
203 def CHECK_NEED_LC(conf
, msg
):
204 '''check if we need -lc'''
206 dir = find_config_dir(conf
)
210 bdir
= os
.path
.join(dir, 'testbuild2')
211 if not os
.path
.exists(bdir
):
215 subdir
= os
.path
.join(dir, "liblctest")
219 Utils
.writef(os
.path
.join(subdir
, 'liblc1.c'), '#include <stdio.h>\nint lib_func(void) { FILE *f = fopen("foo", "r");}\n')
221 bld
= Build
.BuildContext()
223 bld
.all_envs
.update(conf
.all_envs
)
224 bld
.all_envs
['default'] = env
225 bld
.lst_variants
= bld
.all_envs
.keys()
226 bld
.load_dirs(dir, bdir
)
228 bld
.rescan(bld
.srcnode
)
230 bld(features
='cc cshlib',
231 source
='liblctest/liblc1.c',
232 ldflags
=conf
.env
['EXTRA_LDFLAGS'],
238 conf
.check_message(msg
, '', True)
241 conf
.check_message(msg
, '', False)
246 def CHECK_SHLIB_W_PYTHON(conf
, msg
):
247 '''check if we need -undefined dynamic_lookup'''
249 dir = find_config_dir(conf
)
255 #include <crt_externs.h>
256 #define environ (*_NSGetEnviron())
258 static PyObject *ldb_module = NULL;
260 extern char **environ;
262 ldb_module = PyImport_ImportModule("ldb");
265 return conf
.check(features
='cc cshlib',uselib
='PYEMBED',fragment
=snip
,msg
=msg
)
267 # this one is quite complex, and should probably be broken up
268 # into several parts. I'd quite like to create a set of CHECK_COMPOUND()
269 # functions that make writing complex compound tests like this much easier
271 def CHECK_LIBRARY_SUPPORT(conf
, rpath
=False, version_script
=False, msg
=None):
272 '''see if the platform supports building libraries'''
276 msg
= "rpath library support"
278 msg
= "building library support"
280 dir = find_config_dir(conf
)
282 bdir
= os
.path
.join(dir, 'testbuild')
283 if not os
.path
.exists(bdir
):
288 subdir
= os
.path
.join(dir, "libdir")
292 Utils
.writef(os
.path
.join(subdir
, 'lib1.c'), 'int lib_func(void) { return 42; }\n')
293 Utils
.writef(os
.path
.join(dir, 'main.c'), 'int main(void) {return !(lib_func() == 42);}\n')
295 bld
= Build
.BuildContext()
297 bld
.all_envs
.update(conf
.all_envs
)
298 bld
.all_envs
['default'] = env
299 bld
.lst_variants
= bld
.all_envs
.keys()
300 bld
.load_dirs(dir, bdir
)
302 bld
.rescan(bld
.srcnode
)
306 ldflags
.append("-Wl,--version-script=%s/vscript" % bld
.path
.abspath())
307 Utils
.writef(os
.path
.join(dir,'vscript'), 'TEST_1.0A2 { global: *; };\n')
309 bld(features
='cc cshlib',
310 source
='libdir/lib1.c',
311 target
='libdir/lib1',
315 o
= bld(features
='cc cprogram',
321 o
.rpath
=os
.path
.join(bdir
, 'default/libdir')
323 # compile the program
327 conf
.check_message(msg
, '', False)
331 lastprog
= o
.link_task
.outputs
[0].abspath(env
)
334 if 'LD_LIBRARY_PATH' in os
.environ
:
335 old_ld_library_path
= os
.environ
['LD_LIBRARY_PATH']
337 old_ld_library_path
= None
338 ADD_LD_LIBRARY_PATH(os
.path
.join(bdir
, 'default/libdir'))
340 # we need to run the program, try to get its result
341 args
= conf
.SAMBA_CROSS_ARGS(msg
=msg
)
342 proc
= Utils
.pproc
.Popen([lastprog
] + args
, stdout
=Utils
.pproc
.PIPE
, stderr
=Utils
.pproc
.PIPE
)
343 (out
, err
) = proc
.communicate()
348 w('\nreturncode %r\n' % proc
.returncode
)
349 ret
= (proc
.returncode
== 0)
352 os
.environ
['LD_LIBRARY_PATH'] = old_ld_library_path
or ''
354 conf
.check_message(msg
, '', ret
)
360 def CHECK_PERL_MANPAGE(conf
, msg
=None, section
=None):
361 '''work out what extension perl uses for manpages'''
365 msg
= "perl man%s extension" % section
367 msg
= "perl manpage generation"
369 conf
.check_message_1(msg
)
371 dir = find_config_dir(conf
)
373 bdir
= os
.path
.join(dir, 'testbuild')
374 if not os
.path
.exists(bdir
):
377 Utils
.writef(os
.path
.join(bdir
, 'Makefile.PL'), """
378 use ExtUtils::MakeMaker;
381 'EXE_FILES' => [ 'WafTest' ]
384 back
= os
.path
.abspath('.')
386 proc
= Utils
.pproc
.Popen(['perl', 'Makefile.PL'],
387 stdout
=Utils
.pproc
.PIPE
,
388 stderr
=Utils
.pproc
.PIPE
)
389 (out
, err
) = proc
.communicate()
392 ret
= (proc
.returncode
== 0)
394 conf
.check_message_2('not found', color
='YELLOW')
398 man
= Utils
.readf(os
.path
.join(bdir
,'Makefile'))
399 m
= re
.search('MAN%sEXT\s+=\s+(\w+)' % section
, man
)
401 conf
.check_message_2('not found', color
='YELLOW')
404 conf
.check_message_2(ext
)
407 conf
.check_message_2('ok')
412 def CHECK_COMMAND(conf
, cmd
, msg
=None, define
=None, on_target
=True, boolean
=False):
413 '''run a command and return result'''
415 msg
= 'Checking %s' % ' '.join(cmd
)
416 conf
.COMPOUND_START(msg
)
419 cmd
.extend(conf
.SAMBA_CROSS_ARGS(msg
=msg
))
421 ret
= Utils
.cmd_output(cmd
)
423 conf
.COMPOUND_END(False)
426 conf
.COMPOUND_END('ok')
428 conf
.DEFINE(define
, '1')
431 conf
.COMPOUND_END(ret
)
433 conf
.DEFINE(define
, ret
, quote
=True)
438 def CHECK_UNAME(conf
):
439 '''setup SYSTEM_UNAME_* defines'''
441 for v
in "sysname machine release version".split():
442 if not conf
.CHECK_CODE('''
444 if (uname(&n) == -1) return -1;
447 define
='SYSTEM_UNAME_%s' % v
.upper(),
451 headers
='sys/utsname.h',
453 msg
="Checking uname %s type" % v
):
458 def CHECK_INLINE(conf
):
459 '''check for the right value for inline'''
460 conf
.COMPOUND_START('Checking for inline')
461 for i
in ['inline', '__inline__', '__inline']:
462 ret
= conf
.CHECK_CODE('''
464 static %s foo_t static_foo () {return 0; }
465 %s foo_t foo () {return 0; }''' % (i
, i
),
466 define
='INLINE_MACRO',
471 conf
.DEFINE('inline', i
, quote
=False)
474 conf
.COMPOUND_END(ret
)
480 def CHECK_XSLTPROC_MANPAGES(conf
):
481 '''check if xsltproc can run with the given stylesheets'''
484 if not conf
.CONFIG_SET('XSLTPROC'):
485 conf
.find_program('xsltproc', var
='XSLTPROC')
486 if not conf
.CONFIG_SET('XSLTPROC'):
489 s
='http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
490 conf
.CHECK_COMMAND('%s --nonet %s 2> /dev/null' % (conf
.env
.XSLTPROC
, s
),
491 msg
='Checking for stylesheet %s' % s
,
492 define
='XSLTPROC_MANPAGES', on_target
=False,
494 if not conf
.CONFIG_SET('XSLTPROC_MANPAGES'):
495 print "A local copy of the docbook.xsl wasn't found on your system" \
496 " consider installing package like docbook-xsl"
499 # Determine the standard libpath for the used compiler,
500 # so we can later use that to filter out these standard
501 # library paths when some tools like cups-config or
502 # python-config report standard lib paths with their
506 def CHECK_STANDARD_LIBPATH(conf
):
507 # at least gcc and clang support this:
509 cmd
= conf
.env
.CC
+ ['-print-search-dirs']
510 out
= Utils
.cmd_output(cmd
).split('\n')
512 # option not supported by compiler - use a standard list of directories
513 dirlist
= [ '/usr/lib', '/usr/lib64' ]
515 raise Utils
.WafError('Unexpected error running "%s"' % (cmd
))
520 if line
.startswith("libraries: ="):
521 dirliststr
= line
[len("libraries: ="):]
522 dirlist
= [ os
.path
.normpath(x
) for x
in dirliststr
.split(':') ]
525 conf
.env
.STANDARD_LIBPATH
= dirlist
528 waf_config_c_parse_flags
= config_c
.parse_flags
;
529 def samba_config_c_parse_flags(line1
, uselib
, env
):
531 # We do a special treatment of the rpath components
532 # in the linkflags line, because currently the upstream
533 # parse_flags function is incomplete with respect to
534 # treatment of the rpath. The remainder of the linkflags
535 # line is later passed to the original funcion.
537 lst1
= shlex
.split(line1
)
543 # NOTE on special treatment of -Wl,-R and -Wl,-rpath:
545 # It is important to not put a library provided RPATH
546 # into the LINKFLAGS but in the RPATH instead, since
547 # the provided LINKFLAGS get prepended to our own internal
548 # RPATH later, and hence can potentially lead to linking
549 # in too old versions of our internal libs.
551 # We do this filtering here on our own because of some
552 # bugs in the real parse_flags() function.
554 if x
== '-Wl,-rpath' or x
== '-Wl,-R':
556 if x
.startswith('-Wl,'):
560 elif x
.startswith('-Wl,-R,'):
562 elif x
.startswith('-Wl,-R'):
564 elif x
.startswith('-Wl,-rpath,'):
570 env
.append_value('RPATH_' + uselib
, rpath
)
572 line2
= ' '.join(lst2
)
573 waf_config_c_parse_flags(line2
, uselib
, env
)
576 config_c
.parse_flags
= samba_config_c_parse_flags