2010-03-25 01:56:57 +03:00
# a set of config tests that use the samba_autoconf functions
# to test for commonly needed configuration options
2010-03-28 10:24:05 +04:00
2010-03-28 14:00:51 +04:00
import os , Build , shutil , Utils , re
2010-03-25 15:53:10 +03:00
from Configure import conf
2010-03-28 10:24:05 +04:00
from samba_utils import *
2010-03-25 01:56:57 +03:00
@conf
def CHECK_ICONV ( conf , define = ' HAVE_NATIVE_ICONV ' ) :
''' check if the iconv library is installed
optionally pass a define '''
if conf . CHECK_FUNCS_IN ( ' iconv_open ' , ' iconv ' , checklibc = True , headers = ' iconv.h ' ) :
conf . DEFINE ( define , 1 )
return True
return False
@conf
def CHECK_LARGEFILE ( conf , define = ' HAVE_LARGEFILE ' ) :
''' see what we need for largefile support '''
if conf . CHECK_CODE ( ' return !(sizeof(off_t) >= 8) ' ,
define ,
execute = True ,
msg = ' Checking for large file support ' ) :
return True
if conf . CHECK_CODE ( ' return !(sizeof(off_t) >= 8) ' ,
define ,
execute = True ,
cflags = ' -D_FILE_OFFSET_BITS=64 ' ,
msg = ' Checking for -D_FILE_OFFSET_BITS=64 ' ) :
conf . DEFINE ( ' _FILE_OFFSET_BITS ' , 64 )
return True
return False
@conf
def CHECK_C_PROTOTYPE ( conf , function , prototype , define , headers = None ) :
''' verify that a C prototype matches the one on the current system '''
if not conf . CHECK_DECLS ( function , headers = headers ) :
return False
return conf . CHECK_CODE ( ' %s ; void *_x = (void *) %s ' % ( prototype , function ) ,
define = define ,
local_include = False ,
headers = headers ,
2010-03-30 06:19:46 +04:00
link = False ,
execute = False ,
2010-03-25 01:56:57 +03:00
msg = ' Checking C prototype for %s ' % function )
@conf
2010-03-26 09:55:25 +03:00
def CHECK_CHARSET_EXISTS ( conf , charset , outcharset = ' UCS-2LE ' , headers = None , define = None ) :
2010-03-25 01:56:57 +03:00
''' check that a named charset is able to be used with iconv_open() for conversion
to a target charset
'''
msg = ' Checking if can we convert from %s to %s ' % ( charset , outcharset )
if define is None :
define = ' HAVE_CHARSET_ %s ' % charset . upper ( ) . replace ( ' - ' , ' _ ' )
return conf . CHECK_CODE ( '''
iconv_t cd = iconv_open ( " %s " , " %s " ) ;
2010-03-26 09:55:25 +03:00
if ( cd == 0 | | cd == ( iconv_t ) - 1 ) return - 1 ;
''' % (charset, outcharset),
2010-03-25 01:56:57 +03:00
define = define ,
execute = True ,
msg = msg ,
2010-03-26 09:55:25 +03:00
lib = ' iconv ' ,
2010-03-25 01:56:57 +03:00
headers = headers )
2010-03-26 05:12:50 +03:00
2010-03-28 14:00:51 +04:00
def find_config_dir ( conf ) :
''' find a directory to run tests in '''
2010-03-26 05:12:50 +03:00
k = 0
while k < 10000 :
dir = os . path . join ( conf . blddir , ' .conf_check_ %d ' % k )
try :
shutil . rmtree ( dir )
except OSError :
pass
try :
os . stat ( dir )
except :
break
k + = 1
try :
os . makedirs ( dir )
except :
conf . fatal ( ' cannot create a configuration test folder %r ' % dir )
try :
os . stat ( dir )
except :
conf . fatal ( ' cannot use the configuration test folder %r ' % dir )
2010-03-28 14:00:51 +04:00
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 )
2010-03-26 05:12:50 +03:00
bdir = os . path . join ( dir , ' testbuild ' )
if not os . path . exists ( bdir ) :
os . makedirs ( bdir )
env = conf . env
subdir = os . path . join ( dir , " libdir " )
os . makedirs ( subdir )
dest = open ( os . path . join ( subdir , ' lib1.c ' ) , ' w ' )
dest . write ( ' int lib_func(void) { return 42; } \n ' )
dest . close ( )
dest = open ( os . path . join ( dir , ' main.c ' ) , ' w ' )
dest . write ( ' int main(void) { return !(lib_func() == 42);} \n ' )
dest . close ( )
bld = Build . BuildContext ( )
bld . log = conf . log
bld . all_envs . update ( conf . all_envs )
bld . all_envs [ ' default ' ] = env
bld . lst_variants = bld . all_envs . keys ( )
bld . load_dirs ( dir , bdir )
bld . rescan ( bld . srcnode )
bld ( features = ' cc cshlib ' ,
source = ' libdir/lib1.c ' ,
target = ' libdir/lib1 ' ,
name = ' lib1 ' )
o = bld ( features = ' cc cprogram ' ,
source = ' main.c ' ,
target = ' prog1 ' ,
2010-03-28 10:24:05 +04:00
uselib_local = ' lib1 ' )
if rpath :
o . rpath = os . path . join ( bdir , ' default/libdir ' )
2010-03-26 05:12:50 +03:00
# compile the program
try :
bld . compile ( )
2010-03-26 05:20:05 +03:00
except :
2010-03-28 10:24:05 +04:00
conf . check_message ( msg , ' ' , False )
2010-03-26 05:20:05 +03:00
return False
2010-03-26 05:12:50 +03:00
# path for execution
lastprog = o . link_task . outputs [ 0 ] . abspath ( env )
2010-03-28 10:24:05 +04:00
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 ' ) )
2010-03-26 05:12:50 +03:00
# we need to run the program, try to get its result
2010-04-19 09:58:37 +04:00
args = conf . SAMBA_CROSS_ARGS ( msg = msg )
2010-03-26 05:12:50 +03:00
proc = Utils . pproc . Popen ( [ lastprog ] + args , stdout = Utils . pproc . PIPE , stderr = Utils . pproc . PIPE )
( out , err ) = proc . communicate ( )
w = conf . log . write
w ( str ( out ) )
w ( ' \n ' )
w ( str ( err ) )
w ( ' \n returncode %r \n ' % proc . returncode )
ret = ( proc . returncode == 0 )
2010-03-28 10:24:05 +04:00
if not rpath :
os . environ [ ' LD_LIBRARY_PATH ' ] = old_ld_library_path or ' '
conf . check_message ( msg , ' ' , ret )
2010-03-26 05:12:50 +03:00
return ret
2010-03-28 14:00:51 +04:00
@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 %s EXT \ 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