1 # a set of config tests that use the samba_autoconf functions
2 # to test for commonly needed configuration options
3 import os, Build, shutil, Utils
4 from Configure import conf
7 def CHECK_ICONV(conf, define='HAVE_NATIVE_ICONV'):
8 '''check if the iconv library is installed
9 optionally pass a define'''
10 if conf.CHECK_FUNCS_IN('iconv_open', 'iconv', checklibc=True, headers='iconv.h'):
11 conf.DEFINE(define, 1)
17 def CHECK_LARGEFILE(conf, define='HAVE_LARGEFILE'):
18 '''see what we need for largefile support'''
19 if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
22 msg='Checking for large file support'):
24 if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
27 cflags='-D_FILE_OFFSET_BITS=64',
28 msg='Checking for -D_FILE_OFFSET_BITS=64'):
29 conf.DEFINE('_FILE_OFFSET_BITS', 64)
35 def CHECK_C_PROTOTYPE(conf, function, prototype, define, headers=None):
36 '''verify that a C prototype matches the one on the current system'''
37 if not conf.CHECK_DECLS(function, headers=headers):
39 return conf.CHECK_CODE('%s; void *_x = (void *)%s' % (prototype, function),
43 msg='Checking C prototype for %s' % function)
47 def CHECK_CHARSET_EXISTS(conf, charset, outcharset='UCS2-LE', libs=None, headers=None, define=None):
48 '''check that a named charset is able to be used with iconv_open() for conversion
51 msg = 'Checking if can we convert from %s to %s' % (charset, outcharset)
53 define = 'HAVE_CHARSET_%s' % charset.upper().replace('-','_')
54 return conf.CHECK_CODE('''
55 iconv_t cd = iconv_open("%s", "%s");
56 if (cd == 0 || cd == (iconv_t)-1) {
60 ''' % (charset, outcharset),
69 # this one is quite complex, and should probably be broken up
70 # into several parts. I'd quite like to create a set of CHECK_COMPOUND()
71 # functions that make writing complex compound tests like this much easier
73 def CHECK_RPATH_SUPPORT(conf):
74 '''see if the platform supports rpath for libraries'''
77 dir = os.path.join(conf.blddir, '.conf_check_%d' % k)
91 conf.fatal('cannot create a configuration test folder %r' % dir)
96 conf.fatal('cannot use the configuration test folder %r' % dir)
98 bdir = os.path.join(dir, 'testbuild')
99 if not os.path.exists(bdir):
104 subdir = os.path.join(dir, "libdir")
108 dest = open(os.path.join(subdir, 'lib1.c'), 'w')
109 dest.write('int lib_func(void) { return 42; }\n')
112 dest = open(os.path.join(dir, 'main.c'), 'w')
113 dest.write('int main(void) {return !(lib_func() == 42);}\n')
116 back = os.path.abspath('.')
118 bld = Build.BuildContext()
120 bld.all_envs.update(conf.all_envs)
121 bld.all_envs['default'] = env
122 bld.lst_variants = bld.all_envs.keys()
123 bld.load_dirs(dir, bdir)
127 bld.rescan(bld.srcnode)
129 bld(features='cc cshlib',
130 source='libdir/lib1.c',
131 target='libdir/lib1',
134 o = bld(features='cc cprogram',
138 rpath=os.path.join(bdir, 'default/libdir'))
140 # compile the program
144 conf.check_message('rpath support', '', False)
147 # chdir before returning
151 lastprog = o.link_task.outputs[0].abspath(env)
153 # we need to run the program, try to get its result
155 proc = Utils.pproc.Popen([lastprog] + args, stdout=Utils.pproc.PIPE, stderr=Utils.pproc.PIPE)
156 (out, err) = proc.communicate()
161 w('\nreturncode %r\n' % proc.returncode)
162 ret = (proc.returncode == 0)
164 conf.check_message('rpath support', '', ret)