2010-02-26 14:21:50 +03:00
# a waf tool to add autoconf-like macros to the configure section
import Build , os , Logs , sys , Configure , Options
import string , Task , Utils , optparse
from Configure import conf
from Logs import debug
from TaskGen import extension
from samba_utils import *
####################################################
# some autoconf like helpers, to make the transition
# to waf a bit easier for those used to autoconf
# m4 files
2010-03-07 08:05:08 +03:00
2010-02-26 14:21:50 +03:00
@runonce
@conf
def DEFINE ( conf , d , v ) :
2010-03-07 08:05:08 +03:00
''' define a config option '''
2010-02-26 14:21:50 +03:00
conf . define ( d , v , quote = False )
conf . env . append_value ( ' CCDEFINES ' , d + ' = ' + str ( v ) )
@runonce
2010-03-07 05:56:40 +03:00
def CHECK_HEADER ( conf , h , add_headers = True ) :
2010-03-07 08:05:08 +03:00
''' check for a header '''
2010-03-07 05:56:40 +03:00
if conf . check ( header_name = h ) and add_headers :
2010-02-26 14:21:50 +03:00
conf . env . hlist . append ( h )
2010-03-07 06:27:56 +03:00
return True
return False
2010-02-26 14:21:50 +03:00
2010-03-07 08:05:08 +03:00
2010-02-26 14:21:50 +03:00
@conf
2010-03-07 05:56:40 +03:00
def CHECK_HEADERS ( conf , list , add_headers = True ) :
2010-03-07 08:05:08 +03:00
''' check for a list of headers '''
2010-03-07 06:27:56 +03:00
ret = True
2010-03-07 07:18:05 +03:00
for hdr in to_list ( list ) :
2010-03-07 06:27:56 +03:00
if not CHECK_HEADER ( conf , hdr , add_headers ) :
ret = False
return ret
2010-02-26 14:21:50 +03:00
2010-03-07 08:05:08 +03:00
2010-02-26 14:21:50 +03:00
@conf
def CHECK_TYPES ( conf , list ) :
2010-03-07 08:05:08 +03:00
''' check for a list of types '''
2010-03-07 06:27:56 +03:00
ret = True
2010-03-07 07:18:05 +03:00
for t in to_list ( list ) :
2010-03-07 06:27:56 +03:00
if not conf . check ( type_name = t , header_name = conf . env . hlist ) :
ret = False
return ret
2010-02-26 14:21:50 +03:00
2010-03-07 08:05:08 +03:00
2010-02-26 14:21:50 +03:00
@conf
def CHECK_TYPE_IN ( conf , t , hdr ) :
2010-03-07 08:05:08 +03:00
''' check for a type in a specific header '''
2010-02-26 14:21:50 +03:00
if conf . check ( header_name = hdr ) :
conf . check ( type_name = t , header_name = hdr )
2010-03-07 06:27:56 +03:00
return True
return False
2010-02-26 14:21:50 +03:00
2010-03-07 08:05:08 +03:00
2010-02-26 14:21:50 +03:00
@conf
2010-03-07 07:52:45 +03:00
def CHECK_TYPE ( conf , t , alternate = None , headers = None , define = None ) :
2010-03-07 08:05:08 +03:00
''' check for a type with an alternate '''
2010-03-07 07:52:45 +03:00
if headers is None :
headers = conf . env . hlist
if define is not None :
ret = conf . check ( type_name = t , header_name = headers , define_name = define )
else :
ret = conf . check ( type_name = t , header_name = headers )
if not ret and alternate is not None :
2010-02-26 14:21:50 +03:00
conf . DEFINE ( t , alternate )
2010-03-07 07:52:45 +03:00
return ret
2010-02-26 14:21:50 +03:00
2010-03-07 08:05:08 +03:00
2010-02-26 14:21:50 +03:00
@conf
2010-03-17 12:40:03 +03:00
def CHECK_VARIABLE ( conf , v , define = None , always = False , headers = None ) :
2010-03-07 08:05:08 +03:00
''' check for a variable declaration (or define) '''
2010-02-26 14:21:50 +03:00
hdrs = ' '
2010-03-17 12:40:03 +03:00
if headers is not None :
2010-03-07 07:18:05 +03:00
hlist = to_list ( headers )
2010-03-17 12:40:03 +03:00
else :
hlist = conf . env . hlist
for h in hlist :
2010-02-26 14:21:50 +03:00
hdrs + = ' #include < %s > \n ' % h
2010-03-07 05:48:33 +03:00
if define is None :
define = ' HAVE_ %s ' % v . upper ( )
2010-02-26 14:21:50 +03:00
if conf . check ( fragment =
2010-03-17 12:40:03 +03:00
'''
% s
int main ( void ) {
#ifndef %s
void * _x ; _x = ( void * ) & % s ;
#endif
return 0 ;
2010-03-07 07:18:05 +03:00
}
2010-03-17 12:40:03 +03:00
''' % (hdrs, v, v),
2010-02-26 14:21:50 +03:00
execute = 0 ,
msg = " Checking for variable %s " % v ) :
2010-03-07 05:48:33 +03:00
conf . DEFINE ( define , 1 )
2010-03-07 06:27:56 +03:00
return True
2010-03-07 05:48:33 +03:00
elif always :
conf . DEFINE ( define , 0 )
2010-03-07 06:27:56 +03:00
return False
2010-02-26 14:21:50 +03:00
2010-03-07 06:32:27 +03:00
@conf
2010-03-17 12:40:03 +03:00
def CHECK_DECLS ( conf , vars , reverse = False , headers = None ) :
2010-03-07 06:32:27 +03:00
''' check a list of variable declarations, using the HAVE_DECL_xxx form
2010-03-17 12:40:03 +03:00
of define
When reverse == True then use HAVE_xxx_DECL instead of HAVE_DECL_xxx
'''
2010-03-07 06:32:27 +03:00
ret = True
2010-03-07 07:18:05 +03:00
for v in to_list ( vars ) :
2010-03-17 12:40:03 +03:00
if not reverse :
define = ' HAVE_DECL_ %s ' % v . upper ( )
else :
define = ' HAVE_ %s _DECL ' % v . upper ( )
if not CHECK_VARIABLE ( conf , v , define = define , headers = headers ) :
2010-03-07 06:32:27 +03:00
ret = False
return ret
2010-02-26 14:21:50 +03:00
@runonce
def CHECK_FUNC ( conf , f ) :
2010-03-07 08:05:08 +03:00
''' check for a function '''
2010-03-07 06:27:56 +03:00
return conf . check ( function_name = f , header_name = conf . env . hlist )
2010-02-26 14:21:50 +03:00
@conf
def CHECK_FUNCS ( conf , list ) :
2010-03-07 08:05:08 +03:00
''' check for a list of functions '''
2010-03-07 06:27:56 +03:00
ret = True
2010-03-07 07:18:05 +03:00
for f in to_list ( list ) :
2010-03-07 06:27:56 +03:00
if not CHECK_FUNC ( conf , f ) :
ret = False
return ret
2010-02-26 14:21:50 +03:00
2010-03-07 08:05:08 +03:00
2010-03-07 07:18:05 +03:00
@conf
2010-03-07 07:19:37 +03:00
def CHECK_SIZEOF ( conf , vars , headers = None , define = None ) :
2010-03-07 08:05:08 +03:00
''' check the size of a type '''
2010-03-07 07:18:05 +03:00
hdrs = ' '
if headers is not None :
hlist = to_list ( headers )
else :
hlist = conf . env . hlist
for h in hlist :
hdrs + = ' #include < %s > \n ' % h
for v in to_list ( vars ) :
2010-03-07 07:19:37 +03:00
if define is None :
define_name = ' SIZEOF_ %s ' % string . replace ( v . upper ( ) , ' ' , ' _ ' )
else :
define_name = define
2010-03-07 07:18:05 +03:00
conf . check ( fragment =
'''
% s
int main ( void ) {
printf ( " %% u \\ n " , ( unsigned ) sizeof ( % s ) ) ;
return 0 ;
}
''' % (hdrs, v),
execute = 1 ,
define_ret = True ,
2010-03-07 07:19:37 +03:00
define_name = define_name ,
2010-03-07 07:18:05 +03:00
quote = False ,
msg = " Checking size of %s " % v )
2010-02-26 14:21:50 +03:00
2010-03-07 08:18:33 +03:00
@conf
2010-03-07 09:00:22 +03:00
def CHECK_CODE ( conf , code , define ,
always = False , execute = False , addmain = True ,
headers = None , msg = None ) :
''' check if some code compiles and/or runs '''
2010-03-07 08:18:33 +03:00
hdrs = ' '
if headers is not None :
hlist = to_list ( headers )
else :
hlist = conf . env . hlist
for h in hlist :
hdrs + = ' #include < %s > \n ' % h
2010-03-07 09:00:22 +03:00
if execute :
execute = 1
else :
execute = 0
if addmain :
fragment = ' #include " confdefs.h " \n %s \n int main(void) { %s ; return 0; } ' % ( hdrs , code )
else :
fragment = ' #include " confdefs.h " \n %s \n %s ' % ( hdrs , code )
conf . write_config_header ( ' confdefs.h ' , top = True )
if msg is None :
msg = " Checking for %s " % define
if conf . check ( fragment = fragment ,
execute = execute ,
ccflags = ' -I %s ' % conf . curdir ,
includes = ' # . ../default ' ,
msg = msg ) :
2010-03-07 08:18:33 +03:00
conf . DEFINE ( define , 1 )
return True
elif always :
conf . DEFINE ( define , 0 )
return False
2010-03-07 08:05:08 +03:00
@conf
def CHECK_STRUCTURE_MEMBER ( conf , structname , member ,
always = False , define = None , headers = None ) :
''' check for a structure member '''
hdrs = ' '
if headers is not None :
hlist = to_list ( headers )
else :
hlist = conf . env . hlist
for h in hlist :
hdrs + = ' #include < %s > \n ' % h
if define is None :
define = ' HAVE_ %s ' % member . upper ( )
if conf . check ( fragment =
'''
% s
int main ( void ) {
% s s ;
void * _x ; _x = ( void * ) & s . % s ;
return 0 ;
}
''' % (hdrs, structname, member),
execute = 0 ,
msg = " Checking for member %s in %s " % ( member , structname ) ) :
conf . DEFINE ( define , 1 )
return True
elif always :
conf . DEFINE ( define , 0 )
return False
2010-02-26 14:21:50 +03:00
#################################################
# return True if a configuration option was found
@conf
def CONFIG_SET ( conf , option ) :
return ( option in conf . env ) and ( conf . env [ option ] != ( ) )
Build . BuildContext . CONFIG_SET = CONFIG_SET
###########################################################
# check that the functions in 'list' are available in 'library'
# if they are, then make that library available as a dependency
#
# if the library is not available and mandatory==True, then
# raise an error.
#
# If the library is not available and mandatory==False, then
# add the library to the list of dependencies to remove from
# build rules
2010-03-07 06:27:56 +03:00
#
# optionally check for the functions first in libc
2010-02-26 14:21:50 +03:00
@conf
2010-03-07 06:27:56 +03:00
def CHECK_FUNCS_IN ( conf , list , library , mandatory = False , checklibc = False ) :
# first see if the functions are in libc
if checklibc :
remaining = [ ]
2010-03-07 07:18:05 +03:00
for f in to_list ( list ) :
2010-03-07 06:27:56 +03:00
if not CHECK_FUNC ( conf , f ) :
remaining . append ( f )
else :
2010-03-07 07:18:05 +03:00
remaining = to_list ( list )
2010-03-07 06:27:56 +03:00
if remaining == [ ] :
LOCAL_CACHE_SET ( conf , ' EMPTY_TARGETS ' , library . upper ( ) , True )
return True
2010-02-26 14:21:50 +03:00
if not conf . check ( lib = library , uselib_store = library ) :
conf . ASSERT ( not mandatory ,
" Mandatory library ' %s ' not found for functions ' %s ' " % ( library , list ) )
# if it isn't a mandatory library, then remove it from dependency lists
LOCAL_CACHE_SET ( conf , ' EMPTY_TARGETS ' , library . upper ( ) , True )
2010-03-07 06:27:56 +03:00
return False
ret = True
for f in remaining :
if not conf . check ( function_name = f , lib = library , header_name = conf . env . hlist ) :
ret = False
2010-02-26 14:21:50 +03:00
conf . env [ ' LIB_ ' + library . upper ( ) ] = library
LOCAL_CACHE_SET ( conf , ' TARGET_TYPE ' , library , ' SYSLIB ' )
2010-03-07 06:27:56 +03:00
return ret
2010-02-26 14:21:50 +03:00
#################################################
# write out config.h in the right directory
@conf
def SAMBA_CONFIG_H ( conf , path = None ) :
if os . path . normpath ( conf . curdir ) != os . path . normpath ( os . environ . get ( ' PWD ' ) ) :
return
if path is None :
conf . write_config_header ( ' config.h ' , top = True )
else :
conf . write_config_header ( path )
##############################################################
# setup a configurable path
@conf
def CONFIG_PATH ( conf , name , default ) :
if not name in conf . env :
conf . env [ name ] = conf . env [ ' PREFIX ' ] + default
conf . define ( name , conf . env [ name ] , quote = True )
##############################################################
# add some CFLAGS to the command line
@conf
def ADD_CFLAGS ( conf , flags ) :
if not ' EXTRA_CFLAGS ' in conf . env :
conf . env [ ' EXTRA_CFLAGS ' ] = [ ]
2010-03-07 07:18:05 +03:00
conf . env [ ' EXTRA_CFLAGS ' ] . extend ( to_list ( flags ) )
2010-02-26 14:21:50 +03:00
2010-03-17 13:53:29 +03:00
##############################################################
# add some extra include directories to all builds
@conf
def ADD_EXTRA_INCLUDES ( conf , includes ) :
if not ' EXTRA_INCLUDES ' in conf . env :
conf . env [ ' EXTRA_INCLUDES ' ] = [ ]
2010-03-07 07:18:05 +03:00
conf . env [ ' EXTRA_INCLUDES ' ] . extend ( to_list ( includes ) )
2010-03-17 13:53:29 +03:00
2010-02-26 14:21:50 +03:00
##############################################################
# work out the current flags. local flags are added first
def CURRENT_CFLAGS ( bld , cflags ) :
if not ' EXTRA_CFLAGS ' in bld . env :
list = [ ]
else :
list = bld . env [ ' EXTRA_CFLAGS ' ] ;
2010-03-07 07:18:05 +03:00
ret = to_list ( cflags )
2010-02-26 14:21:50 +03:00
ret . extend ( list )
return ret