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='UCS-2LE', 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) return -1;
57 ''' % (charset, outcharset),
66 # this one is quite complex, and should probably be broken up
67 # into several parts. I'd quite like to create a set of CHECK_COMPOUND()
68 # functions that make writing complex compound tests like this much easier
70 def CHECK_RPATH_SUPPORT(conf):
71 '''see if the platform supports rpath for libraries'''
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)
95 bdir = os.path.join(dir, 'testbuild')
96 if not os.path.exists(bdir):
101 subdir = os.path.join(dir, "libdir")
105 dest = open(os.path.join(subdir, 'lib1.c'), 'w')
106 dest.write('int lib_func(void) { return 42; }\n')
109 dest = open(os.path.join(dir, 'main.c'), 'w')
110 dest.write('int main(void) {return !(lib_func() == 42);}\n')
113 back = os.path.abspath('.')
115 bld = Build.BuildContext()
117 bld.all_envs.update(conf.all_envs)
118 bld.all_envs['default'] = env
119 bld.lst_variants = bld.all_envs.keys()
120 bld.load_dirs(dir, bdir)
124 bld.rescan(bld.srcnode)
126 bld(features='cc cshlib',
127 source='libdir/lib1.c',
128 target='libdir/lib1',
131 o = bld(features='cc cprogram',
135 rpath=os.path.join(bdir, 'default/libdir'))
137 # compile the program
141 conf.check_message('rpath support', '', False)
144 # chdir before returning
148 lastprog = o.link_task.outputs[0].abspath(env)
150 # we need to run the program, try to get its result
152 proc = Utils.pproc.Popen([lastprog] + args, stdout=Utils.pproc.PIPE, stderr=Utils.pproc.PIPE)
153 (out, err) = proc.communicate()
158 w('\nreturncode %r\n' % proc.returncode)
159 ret = (proc.returncode == 0)
161 conf.check_message('rpath support', '', ret)