summaryrefslogtreecommitdiff
path: root/source4/build/scons/iconv.py
blob: 940e2d814d19a94127bc24de0a6fb88b032532e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Based on the M4 macro by Bruno Haible.

def exists(env):
	return True

def generate(env):
	env['custom_tests']['CheckIconv'] = CheckIconv

def _CheckIconvPath(context,path):
	# Some systems have iconv in libc, some have it in libiconv (OSF/1 and
  	# those with the standalone portable libiconv installed).
	context.Message("checking for iconv in " + path)

	main = """
int main()
{
	iconv_t cd = iconv_open("","");
    iconv(cd,NULL,NULL,NULL,NULL);
    iconv_close(cd);
	return 0;
}"""

	have_giconv_iconv = context.TryLink("""
#include <stdlib.h>
#include <giconv.h>
""" + main, '.c')
	if have_giconv_iconv:
		context.Result(1)
		return ("giconv.h", "")

	have_iconv_iconv = context.TryLink("""
#include <stdlib.h>
#include <iconv.h>
""" + main, '.c')

	if have_iconv_iconv:
		context.Result(1)
		return ("iconv.h", "")

	#FIXME: Add -lgiconv
	have_giconv_lib_iconv = context.TryLink("""
#include <stdlib.h>
#include <giconv.h>
""" + main, '.c')
	if have_giconv_lib_iconv:
		context.Result(1)
		return ("giconv.h", "-lgiconv")

	#FIXME: Add -liconv
	have_iconv_lib_iconv = context.TryLink("""
#include <stdlib.h>
#include <iconv.h>
"""+main,'.c')

	if have_iconv_lib_iconv:
		context.Result(1)
		return ("iconv.h", "-liconv")

	return None

def CheckIconv(context):
	context.Message("checking for iconv")
	
	look_dirs = ['/usr','/usr/local','/sw']

	for p in look_dirs:
		_CheckIconvPath(context,p) #FIXME: Handle return value

	if context.TryRun("""
#include <iconv.h>
main() {
       iconv_t cd = iconv_open("ASCII", "UCS-2LE");
       if (cd == 0 || cd == (iconv_t)-1) return -1;
       return 0;
}
""", '.c'):
		context.Result(1)
		return (1,[])
	
	context.Result(0)
	return (0,[])