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):
38 '''verify that a C prototype matches the one on the current system'''
39 if not conf.CHECK_DECLS(function, headers=headers):
41 return conf.CHECK_CODE('%s; void *_x = (void *)%s' % (prototype, function),
47 msg='Checking C prototype for %s' % function)
51 def CHECK_CHARSET_EXISTS(conf, charset, outcharset='UCS-2LE', headers=None, define=None):
52 '''check that a named charset is able to be used with iconv_open() for conversion
55 msg = 'Checking if can we convert from %s to %s' % (charset, outcharset)
57 define = 'HAVE_CHARSET_%s' % charset.upper().replace('-','_')
58 return conf.CHECK_CODE('''
59 iconv_t cd = iconv_open("%s", "%s");
60 if (cd == 0 || cd == (iconv_t)-1) return -1;
61 ''' % (charset, outcharset),
68 def find_config_dir(conf):
69 '''find a directory to run tests in'''
72 dir = os.path.join(conf.blddir, '.conf_check_%d' % k)
86 conf.fatal('cannot create a configuration test folder %r' % dir)
91 conf.fatal('cannot use the configuration test folder %r' % dir)
95 # this one is quite complex, and should probably be broken up
96 # into several parts. I'd quite like to create a set of CHECK_COMPOUND()
97 # functions that make writing complex compound tests like this much easier
99 def CHECK_LIBRARY_SUPPORT(conf, rpath=False, msg=None):
100 '''see if the platform supports building libraries'''
104 msg = "rpath library support"
106 msg = "building library support"
108 dir = find_config_dir(conf)
110 bdir = os.path.join(dir, 'testbuild')
111 if not os.path.exists(bdir):
116 subdir = os.path.join(dir, "libdir")
120 dest = open(os.path.join(subdir, 'lib1.c'), 'w')
121 dest.write('int lib_func(void) { return 42; }\n')
124 dest = open(os.path.join(dir, 'main.c'), 'w')
125 dest.write('int main(void) {return !(lib_func() == 42);}\n')
128 bld = Build.BuildContext()
130 bld.all_envs.update(conf.all_envs)
131 bld.all_envs['default'] = env
132 bld.lst_variants = bld.all_envs.keys()
133 bld.load_dirs(dir, bdir)
135 bld.rescan(bld.srcnode)
137 bld(features='cc cshlib',
138 source='libdir/lib1.c',
139 target='libdir/lib1',
142 o = bld(features='cc cprogram',
148 o.rpath=os.path.join(bdir, 'default/libdir')
150 # compile the program
154 conf.check_message(msg, '', False)
158 lastprog = o.link_task.outputs[0].abspath(env)
161 if 'LD_LIBRARY_PATH' in os.environ:
162 old_ld_library_path = os.environ['LD_LIBRARY_PATH']
164 old_ld_library_path = None
165 ADD_LD_LIBRARY_PATH(os.path.join(bdir, 'default/libdir'))
167 # we need to run the program, try to get its result
168 args = conf.SAMBA_CROSS_ARGS(msg=msg)
169 proc = Utils.pproc.Popen([lastprog] + args, stdout=Utils.pproc.PIPE, stderr=Utils.pproc.PIPE)
170 (out, err) = proc.communicate()
175 w('\nreturncode %r\n' % proc.returncode)
176 ret = (proc.returncode == 0)
179 os.environ['LD_LIBRARY_PATH'] = old_ld_library_path or ''
181 conf.check_message(msg, '', ret)
187 def CHECK_PERL_MANPAGE(conf, msg=None, section=None):
188 '''work out what extension perl uses for manpages'''
192 msg = "perl man%s extension" % section
194 msg = "perl manpage generation"
196 conf.check_message_1(msg)
198 dir = find_config_dir(conf)
200 bdir = os.path.join(dir, 'testbuild')
201 if not os.path.exists(bdir):
204 dest = open(os.path.join(bdir, 'Makefile.PL'), 'w')
206 use ExtUtils::MakeMaker;
209 'EXE_FILES' => [ 'WafTest' ]
213 back = os.path.abspath('.')
215 proc = Utils.pproc.Popen(['perl', 'Makefile.PL'],
216 stdout=Utils.pproc.PIPE,
217 stderr=Utils.pproc.PIPE)
218 (out, err) = proc.communicate()
221 ret = (proc.returncode == 0)
223 conf.check_message_2('not found', color='YELLOW')
227 f = open(os.path.join(bdir,'Makefile'), 'r')
230 m = re.search('MAN%sEXT\s+=\s+(\w+)' % section, man)
232 conf.check_message_2('not found', color='YELLOW')
235 conf.check_message_2(ext)
238 conf.check_message_2('ok')
243 def CHECK_COMMAND(conf, cmd, msg=None, define=None, on_target=True):
244 '''run a command and return result'''
246 msg = 'Checking %s' % ' '.join(cmd)
247 conf.COMPOUND_START(msg)
250 cmd.extend(conf.SAMBA_CROSS_ARGS(msg=msg))
252 ret = Utils.cmd_output(cmd)
254 conf.COMPOUND_END(False)
257 conf.COMPOUND_END(ret)
259 conf.DEFINE(define, ret, quote=True)
264 def CHECK_UNAME(conf):
265 '''setup SYSTEM_UNAME_* defines'''
267 for v in "sysname machine release version".split():
268 if not conf.CHECK_CODE('''
270 if (uname(&n) == -1) return -1;
273 define='SYSTEM_UNAME_%s' % v.upper(),
277 headers='sys/utsname.h',
279 msg="Checking uname %s type" % v):