build: waf update to fix macos build error
[Samba/gebeck_regimport.git] / buildtools / wafsamba / samba_conftests.py
blob348dc341e402c344916e0d6c80c68d095065318a
1 # a set of config tests that use the samba_autoconf functions
2 # to test for commonly needed configuration options
4 import os, Build, shutil, Utils, re
5 from Configure import conf
6 from samba_utils import *
8 @conf
9 def CHECK_ICONV(conf, define='HAVE_NATIVE_ICONV'):
10 '''check if the iconv library is installed
11 optionally pass a define'''
12 if conf.CHECK_FUNCS_IN('iconv_open', 'iconv', checklibc=True, headers='iconv.h'):
13 conf.DEFINE(define, 1)
14 return True
15 return False
18 @conf
19 def CHECK_LARGEFILE(conf, define='HAVE_LARGEFILE'):
20 '''see what we need for largefile support'''
21 if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
22 define,
23 execute=True,
24 msg='Checking for large file support'):
25 return True
26 if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
27 define,
28 execute=True,
29 cflags='-D_FILE_OFFSET_BITS=64',
30 msg='Checking for -D_FILE_OFFSET_BITS=64'):
31 conf.DEFINE('_FILE_OFFSET_BITS', 64)
32 return True
33 return False
36 @conf
37 def CHECK_C_PROTOTYPE(conf, function, prototype, define, headers=None):
38 '''verify that a C prototype matches the one on the current system'''
39 if not conf.CHECK_DECLS(function, headers=headers):
40 return False
41 return conf.CHECK_CODE('%s; void *_x = (void *)%s' % (prototype, function),
42 define=define,
43 local_include=False,
44 headers=headers,
45 link=False,
46 execute=False,
47 msg='Checking C prototype for %s' % function)
50 @conf
51 def CHECK_CHARSET_EXISTS(conf, charset, outcharset='UCS-2LE', headers=None, define=None):
52 '''check that a named charset is able to be used with iconv_open() for conversion
53 to a target charset
54 '''
55 msg = 'Checking if can we convert from %s to %s' % (charset, outcharset)
56 if define is None:
57 define = 'HAVE_CHARSET_%s' % charset.upper().replace('-','_')
58 return conf.CHECK_CODE('''
59 iconv_t cd = iconv_open("%s", "%s");
60 if (cd == 0 || cd == (iconv_t)-1) return -1;
61 ''' % (charset, outcharset),
62 define=define,
63 execute=True,
64 msg=msg,
65 lib='iconv',
66 headers=headers)
68 def find_config_dir(conf):
69 '''find a directory to run tests in'''
70 k = 0
71 while k < 10000:
72 dir = os.path.join(conf.blddir, '.conf_check_%d' % k)
73 try:
74 shutil.rmtree(dir)
75 except OSError:
76 pass
77 try:
78 os.stat(dir)
79 except:
80 break
81 k += 1
83 try:
84 os.makedirs(dir)
85 except:
86 conf.fatal('cannot create a configuration test folder %r' % dir)
88 try:
89 os.stat(dir)
90 except:
91 conf.fatal('cannot use the configuration test folder %r' % dir)
92 return dir
95 # this one is quite complex, and should probably be broken up
96 # into several parts. I'd quite like to create a set of CHECK_COMPOUND()
97 # functions that make writing complex compound tests like this much easier
98 @conf
99 def CHECK_LIBRARY_SUPPORT(conf, rpath=False, msg=None):
100 '''see if the platform supports building libraries'''
102 if msg is None:
103 if rpath:
104 msg = "rpath library support"
105 else:
106 msg = "building library support"
108 dir = find_config_dir(conf)
110 bdir = os.path.join(dir, 'testbuild')
111 if not os.path.exists(bdir):
112 os.makedirs(bdir)
114 env = conf.env
116 subdir = os.path.join(dir, "libdir")
118 os.makedirs(subdir)
120 dest = open(os.path.join(subdir, 'lib1.c'), 'w')
121 dest.write('int lib_func(void) { return 42; }\n')
122 dest.close()
124 dest = open(os.path.join(dir, 'main.c'), 'w')
125 dest.write('int main(void) {return !(lib_func() == 42);}\n')
126 dest.close()
128 bld = Build.BuildContext()
129 bld.log = conf.log
130 bld.all_envs.update(conf.all_envs)
131 bld.all_envs['default'] = env
132 bld.lst_variants = bld.all_envs.keys()
133 bld.load_dirs(dir, bdir)
135 bld.rescan(bld.srcnode)
137 bld(features='cc cshlib',
138 source='libdir/lib1.c',
139 target='libdir/lib1',
140 name='lib1')
142 o = bld(features='cc cprogram',
143 source='main.c',
144 target='prog1',
145 uselib_local='lib1')
147 if rpath:
148 o.rpath=os.path.join(bdir, 'default/libdir')
150 # compile the program
151 try:
152 bld.compile()
153 except:
154 conf.check_message(msg, '', False)
155 return False
157 # path for execution
158 lastprog = o.link_task.outputs[0].abspath(env)
160 if not rpath:
161 if 'LD_LIBRARY_PATH' in os.environ:
162 old_ld_library_path = os.environ['LD_LIBRARY_PATH']
163 else:
164 old_ld_library_path = None
165 ADD_LD_LIBRARY_PATH(os.path.join(bdir, 'default/libdir'))
167 # we need to run the program, try to get its result
168 args = []
169 proc = Utils.pproc.Popen([lastprog] + args, stdout=Utils.pproc.PIPE, stderr=Utils.pproc.PIPE)
170 (out, err) = proc.communicate()
171 w = conf.log.write
172 w(str(out))
173 w('\n')
174 w(str(err))
175 w('\nreturncode %r\n' % proc.returncode)
176 ret = (proc.returncode == 0)
178 if not rpath:
179 os.environ['LD_LIBRARY_PATH'] = old_ld_library_path or ''
181 conf.check_message(msg, '', ret)
182 return ret
186 @conf
187 def CHECK_PERL_MANPAGE(conf, msg=None, section=None):
188 '''work out what extension perl uses for manpages'''
190 if msg is None:
191 if section:
192 msg = "perl man%s extension" % section
193 else:
194 msg = "perl manpage generation"
196 conf.check_message_1(msg)
198 dir = find_config_dir(conf)
200 bdir = os.path.join(dir, 'testbuild')
201 if not os.path.exists(bdir):
202 os.makedirs(bdir)
204 dest = open(os.path.join(bdir, 'Makefile.PL'), 'w')
205 dest.write("""
206 use ExtUtils::MakeMaker;
207 WriteMakefile(
208 'NAME' => 'WafTest',
209 'EXE_FILES' => [ 'WafTest' ]
211 """)
212 dest.close()
213 back = os.path.abspath('.')
214 os.chdir(bdir)
215 proc = Utils.pproc.Popen(['perl', 'Makefile.PL'],
216 stdout=Utils.pproc.PIPE,
217 stderr=Utils.pproc.PIPE)
218 (out, err) = proc.communicate()
219 os.chdir(back)
221 ret = (proc.returncode == 0)
222 if not ret:
223 conf.check_message_2('not found', color='YELLOW')
224 return
226 if section:
227 f = open(os.path.join(bdir,'Makefile'), 'r')
228 man = f.read()
229 f.close()
230 m = re.search('MAN%sEXT\s+=\s+(\w+)' % section, man)
231 if not m:
232 conf.check_message_2('not found', color='YELLOW')
233 return
234 ext = m.group(1)
235 conf.check_message_2(ext)
236 return ext
238 conf.check_message_2('ok')
239 return True