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
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),
45 msg='Checking C prototype for %s' % function)
49 def CHECK_CHARSET_EXISTS(conf, charset, outcharset='UCS-2LE', headers=None, define=None):
50 '''check that a named charset is able to be used with iconv_open() for conversion
53 msg = 'Checking if can we convert from %s to %s' % (charset, outcharset)
55 define = 'HAVE_CHARSET_%s' % charset.upper().replace('-','_')
56 return conf.CHECK_CODE('''
57 iconv_t cd = iconv_open("%s", "%s");
58 if (cd == 0 || cd == (iconv_t)-1) return -1;
59 ''' % (charset, outcharset),
68 # this one is quite complex, and should probably be broken up
69 # into several parts. I'd quite like to create a set of CHECK_COMPOUND()
70 # functions that make writing complex compound tests like this much easier
72 def CHECK_LIBRARY_SUPPORT(conf, rpath=False, msg=None):
73 '''see if the platform supports building libraries'''
77 msg = "rpath library support"
79 msg = "building library support"
83 dir = os.path.join(conf.blddir, '.conf_check_%d' % k)
97 conf.fatal('cannot create a configuration test folder %r' % dir)
102 conf.fatal('cannot use the configuration test folder %r' % dir)
104 bdir = os.path.join(dir, 'testbuild')
105 if not os.path.exists(bdir):
110 subdir = os.path.join(dir, "libdir")
114 dest = open(os.path.join(subdir, 'lib1.c'), 'w')
115 dest.write('int lib_func(void) { return 42; }\n')
118 dest = open(os.path.join(dir, 'main.c'), 'w')
119 dest.write('int main(void) {return !(lib_func() == 42);}\n')
122 bld = Build.BuildContext()
124 bld.all_envs.update(conf.all_envs)
125 bld.all_envs['default'] = env
126 bld.lst_variants = bld.all_envs.keys()
127 bld.load_dirs(dir, bdir)
129 bld.rescan(bld.srcnode)
131 bld(features='cc cshlib',
132 source='libdir/lib1.c',
133 target='libdir/lib1',
136 o = bld(features='cc cprogram',
142 o.rpath=os.path.join(bdir, 'default/libdir')
144 # compile the program
148 conf.check_message(msg, '', False)
152 lastprog = o.link_task.outputs[0].abspath(env)
155 if 'LD_LIBRARY_PATH' in os.environ:
156 old_ld_library_path = os.environ['LD_LIBRARY_PATH']
158 old_ld_library_path = None
159 ADD_LD_LIBRARY_PATH(os.path.join(bdir, 'default/libdir'))
161 # we need to run the program, try to get its result
163 proc = Utils.pproc.Popen([lastprog] + args, stdout=Utils.pproc.PIPE, stderr=Utils.pproc.PIPE)
164 (out, err) = proc.communicate()
169 w('\nreturncode %r\n' % proc.returncode)
170 ret = (proc.returncode == 0)
173 os.environ['LD_LIBRARY_PATH'] = old_ld_library_path or ''
175 conf.check_message(msg, '', ret)