15ee49909cc13b88b124d191b9a9d81f0147a8d9
[bbaumbach/samba-autobuild/.git] / source4 / lib / charset / SConscript
1 #!/usr/bin/env python
2 # tastes like -*- python -*-
3
4
5 def _CheckIconvPath(context,path):
6         # Some systems have iconv in libc, some have it in libiconv (OSF/1 and
7         # those with the standalone portable libiconv installed).
8         if path: 
9                 context.Message("checking for iconv in " + path + " ... ")
10                 context.env.Append(LIBPATH=path)
11         else:
12                 context.Message("checking for iconv in default path ... ")
13
14         for l in [None,'giconv','iconv']:
15                 for h in ['giconv.h','iconv.h']:
16                         if l: 
17                                 context.env['LIBS'] = [l]
18                         if context.TryLink("""
19 #include <stdlib.h>
20 #include <%s>
21
22 int main()
23 {
24         iconv_t cd = iconv_open("","");
25     iconv(cd,NULL,NULL,NULL,NULL);
26     iconv_close(cd);
27         return 0;
28 }""" % h, '.c'):
29                                 context.Result(1)
30                                 return True
31                         
32         context.Result(0)
33         return False
34
35 def CheckIconv(context):
36         look_dirs = [None, '/usr','/usr/local','/sw']
37
38         for p in look_dirs:
39                 if _CheckIconvPath(context,p):
40                         break
41
42         if context.TryRun("""
43 #include <iconv.h>
44 main() {
45        iconv_t cd = iconv_open("ASCII", "UCS-2LE");
46        if (cd == 0 || cd == (iconv_t)-1) return -1;
47        return 0;
48 }
49 """, '.c'):
50                 return (1,[])
51         
52         return (0,[])
53
54 if hostenv['configure']:
55         conf = hostenv.Configure( custom_tests = { 'CheckIconv' : CheckIconv })
56         (have_iconv,iconv) = conf.CheckIconv()
57         conf.Finish()
58
59         if not have_iconv:
60                 print "Install iconv for better charset compatibility"
61 else:
62         iconv = [] # FIXME
63
64 charset = hostenv.Library('charset',['iconv.c','charcnv.c',iconv])
65 Export('charset')