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 if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
24 msg='Checking for large file support'):
26 if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
29 cflags='-D_FILE_OFFSET_BITS=64',
30 msg='Checking for -D_FILE_OFFSET_BITS=64'):
31 conf.DEFINE('_FILE_OFFSET_BITS', 64)
37 def CHECK_C_PROTOTYPE(conf, function, prototype, define, headers=None, msg=None):
38 '''verify that a C prototype matches the one on the current system'''
39 if not conf.CHECK_DECLS(function, headers=headers):
42 msg = 'Checking C prototype for %s' % function
43 return conf.CHECK_CODE('%s; void *_x = (void *)%s' % (prototype, function),
53 def CHECK_CHARSET_EXISTS(conf, charset, outcharset='UCS-2LE', headers=None, define=None):
54 '''check that a named charset is able to be used with iconv_open() for conversion
57 msg = 'Checking if can we convert from %s to %s' % (charset, outcharset)
59 define = 'HAVE_CHARSET_%s' % charset.upper().replace('-','_')
60 return conf.CHECK_CODE('''
61 iconv_t cd = iconv_open("%s", "%s");
62 if (cd == 0 || cd == (iconv_t)-1) return -1;
63 ''' % (charset, outcharset),
70 def find_config_dir(conf):
71 '''find a directory to run tests in'''
74 dir = os.path.join(conf.blddir, '.conf_check_%d' % k)
88 conf.fatal('cannot create a configuration test folder %r' % dir)
93 conf.fatal('cannot use the configuration test folder %r' % dir)
97 def CHECK_SHLIB_W_PYTHON(conf, msg):
98 '''check if we need -undefined dynamic_lookup'''
100 dir = find_config_dir(conf)
106 #include <crt_externs.h>
107 #define environ (*_NSGetEnviron())
109 static PyObject *ldb_module = NULL;
111 extern char **environ;
113 ldb_module = PyImport_ImportModule("ldb");
116 return conf.check(features='cc cshlib',uselib='PYEMBED',fragment=snip,msg=msg)
118 # this one is quite complex, and should probably be broken up
119 # into several parts. I'd quite like to create a set of CHECK_COMPOUND()
120 # functions that make writing complex compound tests like this much easier
122 def CHECK_LIBRARY_SUPPORT(conf, rpath=False, msg=None):
123 '''see if the platform supports building libraries'''
127 msg = "rpath library support"
129 msg = "building library support"
131 dir = find_config_dir(conf)
133 bdir = os.path.join(dir, 'testbuild')
134 if not os.path.exists(bdir):
139 subdir = os.path.join(dir, "libdir")
143 dest = open(os.path.join(subdir, 'lib1.c'), 'w')
144 dest.write('int lib_func(void) { return 42; }\n')
147 dest = open(os.path.join(dir, 'main.c'), 'w')
148 dest.write('int main(void) {return !(lib_func() == 42);}\n')
151 bld = Build.BuildContext()
153 bld.all_envs.update(conf.all_envs)
154 bld.all_envs['default'] = env
155 bld.lst_variants = bld.all_envs.keys()
156 bld.load_dirs(dir, bdir)
158 bld.rescan(bld.srcnode)
160 bld(features='cc cshlib',
161 source='libdir/lib1.c',
162 target='libdir/lib1',
165 o = bld(features='cc cprogram',
171 o.rpath=os.path.join(bdir, 'default/libdir')
173 # compile the program
177 conf.check_message(msg, '', False)
181 lastprog = o.link_task.outputs[0].abspath(env)
184 if 'LD_LIBRARY_PATH' in os.environ:
185 old_ld_library_path = os.environ['LD_LIBRARY_PATH']
187 old_ld_library_path = None
188 ADD_LD_LIBRARY_PATH(os.path.join(bdir, 'default/libdir'))
190 # we need to run the program, try to get its result
191 args = conf.SAMBA_CROSS_ARGS(msg=msg)
192 proc = Utils.pproc.Popen([lastprog] + args, stdout=Utils.pproc.PIPE, stderr=Utils.pproc.PIPE)
193 (out, err) = proc.communicate()
198 w('\nreturncode %r\n' % proc.returncode)
199 ret = (proc.returncode == 0)
202 os.environ['LD_LIBRARY_PATH'] = old_ld_library_path or ''
204 conf.check_message(msg, '', ret)
210 def CHECK_PERL_MANPAGE(conf, msg=None, section=None):
211 '''work out what extension perl uses for manpages'''
215 msg = "perl man%s extension" % section
217 msg = "perl manpage generation"
219 conf.check_message_1(msg)
221 dir = find_config_dir(conf)
223 bdir = os.path.join(dir, 'testbuild')
224 if not os.path.exists(bdir):
227 dest = open(os.path.join(bdir, 'Makefile.PL'), 'w')
229 use ExtUtils::MakeMaker;
232 'EXE_FILES' => [ 'WafTest' ]
236 back = os.path.abspath('.')
238 proc = Utils.pproc.Popen(['perl', 'Makefile.PL'],
239 stdout=Utils.pproc.PIPE,
240 stderr=Utils.pproc.PIPE)
241 (out, err) = proc.communicate()
244 ret = (proc.returncode == 0)
246 conf.check_message_2('not found', color='YELLOW')
250 f = open(os.path.join(bdir,'Makefile'), 'r')
253 m = re.search('MAN%sEXT\s+=\s+(\w+)' % section, man)
255 conf.check_message_2('not found', color='YELLOW')
258 conf.check_message_2(ext)
261 conf.check_message_2('ok')
266 def CHECK_COMMAND(conf, cmd, msg=None, define=None, on_target=True, boolean=False):
267 '''run a command and return result'''
269 msg = 'Checking %s' % ' '.join(cmd)
270 conf.COMPOUND_START(msg)
273 cmd.extend(conf.SAMBA_CROSS_ARGS(msg=msg))
275 ret = Utils.cmd_output(cmd)
277 conf.COMPOUND_END(False)
280 conf.COMPOUND_END('ok')
282 conf.DEFINE(define, '1')
285 conf.COMPOUND_END(ret)
287 conf.DEFINE(define, ret, quote=True)
292 def CHECK_UNAME(conf):
293 '''setup SYSTEM_UNAME_* defines'''
295 for v in "sysname machine release version".split():
296 if not conf.CHECK_CODE('''
298 if (uname(&n) == -1) return -1;
301 define='SYSTEM_UNAME_%s' % v.upper(),
305 headers='sys/utsname.h',
307 msg="Checking uname %s type" % v):
312 def CHECK_INLINE(conf):
313 '''check for the right value for inline'''
314 conf.COMPOUND_START('Checking for inline')
315 for i in ['inline', '__inline__', '__inline']:
316 ret = conf.CHECK_CODE('''
318 static %s foo_t static_foo () {return 0; }
319 %s foo_t foo () {return 0; }''' % (i, i),
320 define='INLINE_MACRO',
325 conf.DEFINE('inline', i, quote=False)
328 conf.COMPOUND_END(ret)
334 def CHECK_XSLTPROC_MANPAGES(conf):
335 '''check if xsltproc can run with the given stylesheets'''
338 if not conf.CONFIG_SET('XSLTPROC'):
339 conf.find_program('xsltproc', var='XSLTPROC')
340 if not conf.CONFIG_SET('XSLTPROC'):
343 s='http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
344 conf.CHECK_COMMAND('%s --nonet %s 2> /dev/null' % (conf.env.XSLTPROC, s),
345 msg='Checking for stylesheet %s' % s,
346 define='XSLTPROC_MANPAGES', on_target=False,