# a set of config tests that use the samba_autoconf functions
# to test for commonly needed configuration options
-import os, Build, shutil, Utils
+
+import os, Build, shutil, Utils, re
from Configure import conf
+from samba_utils import *
@conf
def CHECK_ICONV(conf, define='HAVE_NATIVE_ICONV'):
define=define,
local_include=False,
headers=headers,
+ link=False,
+ execute=False,
msg='Checking C prototype for %s' % function)
@conf
-def CHECK_CHARSET_EXISTS(conf, charset, outcharset='UCS2-LE', libs=None, headers=None, define=None):
+def CHECK_CHARSET_EXISTS(conf, charset, outcharset='UCS-2LE', headers=None, define=None):
'''check that a named charset is able to be used with iconv_open() for conversion
to a target charset
'''
define = 'HAVE_CHARSET_%s' % charset.upper().replace('-','_')
return conf.CHECK_CODE('''
iconv_t cd = iconv_open("%s", "%s");
- if (cd == 0 || cd == (iconv_t)-1) {
- return -1;
- }
- return 0;
- ''' % (charset, outcharset),
+ if (cd == 0 || cd == (iconv_t)-1) return -1;
+ ''' % (charset, outcharset),
define=define,
execute=True,
- libs=libs,
msg=msg,
+ lib='iconv',
headers=headers)
-
-
-# this one is quite complex, and should probably be broken up
-# into several parts. I'd quite like to create a set of CHECK_COMPOUND()
-# functions that make writing complex compound tests like this much easier
-@conf
-def CHECK_RPATH_SUPPORT(conf):
- '''see if the platform supports rpath for libraries'''
+def find_config_dir(conf):
+ '''find a directory to run tests in'''
k = 0
while k < 10000:
dir = os.path.join(conf.blddir, '.conf_check_%d' % k)
os.stat(dir)
except:
conf.fatal('cannot use the configuration test folder %r' % dir)
+ return dir
+
+
+# this one is quite complex, and should probably be broken up
+# into several parts. I'd quite like to create a set of CHECK_COMPOUND()
+# functions that make writing complex compound tests like this much easier
+@conf
+def CHECK_LIBRARY_SUPPORT(conf, rpath=False, msg=None):
+ '''see if the platform supports building libraries'''
+
+ if msg is None:
+ if rpath:
+ msg = "rpath library support"
+ else:
+ msg = "building library support"
+
+ dir = find_config_dir(conf)
bdir = os.path.join(dir, 'testbuild')
if not os.path.exists(bdir):
dest.write('int main(void) {return !(lib_func() == 42);}\n')
dest.close()
- back = os.path.abspath('.')
-
bld = Build.BuildContext()
bld.log = conf.log
bld.all_envs.update(conf.all_envs)
bld.lst_variants = bld.all_envs.keys()
bld.load_dirs(dir, bdir)
- os.chdir(dir)
-
bld.rescan(bld.srcnode)
bld(features='cc cshlib',
o = bld(features='cc cprogram',
source='main.c',
target='prog1',
- uselib_local='lib1',
- rpath=os.path.join(bdir, 'default/libdir'))
+ uselib_local='lib1')
+
+ if rpath:
+ o.rpath=os.path.join(bdir, 'default/libdir')
# compile the program
try:
bld.compile()
- except Utils.WafError:
- ret = Utils.ex_stack()
- else:
- ret = 0
-
- # chdir before returning
- os.chdir(back)
-
- if ret:
- conf.log.write('command returned %r' % ret)
- conf.fatal(str(ret))
+ except:
+ conf.check_message(msg, '', False)
+ return False
# path for execution
lastprog = o.link_task.outputs[0].abspath(env)
+ if not rpath:
+ if 'LD_LIBRARY_PATH' in os.environ:
+ old_ld_library_path = os.environ['LD_LIBRARY_PATH']
+ else:
+ old_ld_library_path = None
+ ADD_LD_LIBRARY_PATH(os.path.join(bdir, 'default/libdir'))
+
# we need to run the program, try to get its result
args = []
proc = Utils.pproc.Popen([lastprog] + args, stdout=Utils.pproc.PIPE, stderr=Utils.pproc.PIPE)
w('\nreturncode %r\n' % proc.returncode)
ret = (proc.returncode == 0)
- conf.check_message('rpath support', '', ret)
+ if not rpath:
+ os.environ['LD_LIBRARY_PATH'] = old_ld_library_path or ''
+
+ conf.check_message(msg, '', ret)
return ret
+
+
+
+@conf
+def CHECK_PERL_MANPAGE(conf, msg=None, section=None):
+ '''work out what extension perl uses for manpages'''
+
+ if msg is None:
+ if section:
+ msg = "perl man%s extension" % section
+ else:
+ msg = "perl manpage generation"
+
+ conf.check_message_1(msg)
+
+ dir = find_config_dir(conf)
+
+ bdir = os.path.join(dir, 'testbuild')
+ if not os.path.exists(bdir):
+ os.makedirs(bdir)
+
+ dest = open(os.path.join(bdir, 'Makefile.PL'), 'w')
+ dest.write("""
+use ExtUtils::MakeMaker;
+WriteMakefile(
+ 'NAME' => 'WafTest',
+ 'EXE_FILES' => [ 'WafTest' ]
+);
+""")
+ dest.close()
+ back = os.path.abspath('.')
+ os.chdir(bdir)
+ proc = Utils.pproc.Popen(['perl', 'Makefile.PL'],
+ stdout=Utils.pproc.PIPE,
+ stderr=Utils.pproc.PIPE)
+ (out, err) = proc.communicate()
+ os.chdir(back)
+
+ ret = (proc.returncode == 0)
+ if not ret:
+ conf.check_message_2('not found', color='YELLOW')
+ return
+
+ if section:
+ f = open(os.path.join(bdir,'Makefile'), 'r')
+ man = f.read()
+ f.close()
+ m = re.search('MAN%sEXT\s+=\s+(\w+)' % section, man)
+ if not m:
+ conf.check_message_2('not found', color='YELLOW')
+ return
+ ext = m.group(1)
+ conf.check_message_2(ext)
+ return ext
+
+ conf.check_message_2('ok')
+ return True