build: started a library of common config tests for s3/s4
[nivanova/samba-autobuild/.git] / buildtools / wafsamba / samba_conftests.py
1 # a set of config tests that use the samba_autoconf functions
2 # to test for commonly needed configuration options
3
4
5 @conf
6 def CHECK_ICONV(conf, define='HAVE_NATIVE_ICONV'):
7     '''check if the iconv library is installed
8        optionally pass a define'''
9     if conf.CHECK_FUNCS_IN('iconv_open', 'iconv', checklibc=True, headers='iconv.h'):
10         conf.DEFINE(define, 1)
11         return True
12     return False
13
14
15 @conf
16 def CHECK_LARGEFILE(conf, define='HAVE_LARGEFILE'):
17     '''see what we need for largefile support'''
18     if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
19                        define,
20                        execute=True,
21                        msg='Checking for large file support'):
22         return True
23     if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
24                        define,
25                        execute=True,
26                        cflags='-D_FILE_OFFSET_BITS=64',
27                        msg='Checking for -D_FILE_OFFSET_BITS=64'):
28         conf.DEFINE('_FILE_OFFSET_BITS', 64)
29         return True
30     return False
31
32
33 @conf
34 def CHECK_C_PROTOTYPE(conf, function, prototype, define, headers=None):
35     '''verify that a C prototype matches the one on the current system'''
36     if not conf.CHECK_DECLS(function, headers=headers):
37         return False
38     return conf.CHECK_CODE('%s; void *_x = (void *)%s' % (prototype, function),
39                            define=define,
40                            local_include=False,
41                            headers=headers,
42                            msg='Checking C prototype for %s' % function)
43
44
45 @conf
46 def CHECK_CHARSET_EXISTS(conf, charset, outcharset='UCS2-LE', libs=None, headers=None, define=None):
47     '''check that a named charset is able to be used with iconv_open() for conversion
48     to a target charset
49     '''
50     msg = 'Checking if can we convert from %s to %s' % (charset, outcharset)
51     if define is None:
52         define = 'HAVE_CHARSET_%s' % charset.upper().replace('-','_')
53     return conf.CHECK_CODE('''
54                            iconv_t cd = iconv_open("%s", "%s");
55                            if (cd == 0 || cd == (iconv_t)-1) {
56                              return -1;
57                              }
58                              return 0;
59                              ''' % (charset, outcharset),
60                            define=define,
61                            execute=True,
62                            libs=libs,
63                            msg=msg,
64                            headers=headers)