2010-02-26 14:21:50 +03:00
# a waf tool to add autoconf-like macros to the configure section
2011-01-05 14:16:15 +03:00
import Build , os , sys , Options , preproc , Logs
2010-03-17 12:12:16 +03:00
import string
2010-02-26 14:21:50 +03:00
from Configure import conf
from samba_utils import *
2010-04-12 16:06:51 +04:00
import samba_cross
2010-02-26 14:21:50 +03:00
2010-03-23 01:29:19 +03:00
missing_headers = set ( )
2010-02-26 14:21:50 +03:00
####################################################
# 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
2010-03-26 10:05:13 +03:00
def DEFINE ( conf , d , v , add_to_cflags = False , quote = False ) :
2010-03-07 08:05:08 +03:00
''' define a config option '''
2010-03-26 10:05:13 +03:00
conf . define ( d , v , quote = quote )
2010-03-08 12:44:11 +03:00
if add_to_cflags :
conf . env . append_value ( ' CCDEFINES ' , d + ' = ' + str ( v ) )
2010-02-26 14:21:50 +03:00
2010-03-23 01:29:19 +03:00
def hlist_to_string ( conf , headers = None ) :
''' convert a headers list to a set of #include lines '''
hdrs = ' '
hlist = conf . env . hlist
if headers :
hlist = hlist [ : ]
hlist . extend ( TO_LIST ( headers ) )
for h in hlist :
hdrs + = ' #include < %s > \n ' % h
return hdrs
2010-03-30 07:41:08 +04:00
@conf
def COMPOUND_START ( conf , msg ) :
''' start a compound test '''
def null_check_message_1 ( self , * k , * * kw ) :
return
def null_check_message_2 ( self , * k , * * kw ) :
return
v = getattr ( conf . env , ' in_compound ' , [ ] )
if v != [ ] and v != 0 :
conf . env . in_compound = v + 1
return
conf . check_message_1 ( msg )
conf . saved_check_message_1 = conf . check_message_1
conf . check_message_1 = null_check_message_1
conf . saved_check_message_2 = conf . check_message_2
conf . check_message_2 = null_check_message_2
conf . env . in_compound = 1
@conf
def COMPOUND_END ( conf , result ) :
''' start a compound test '''
conf . env . in_compound - = 1
if conf . env . in_compound != 0 :
return
conf . check_message_1 = conf . saved_check_message_1
conf . check_message_2 = conf . saved_check_message_2
p = conf . check_message_2
2012-10-08 13:18:03 +04:00
if result is True :
p ( ' ok ' )
2012-09-27 20:30:47 +04:00
elif not result :
2010-03-30 07:41:08 +04:00
p ( ' not found ' , ' YELLOW ' )
else :
p ( result )
2010-03-23 01:29:19 +03:00
@feature ( ' nolink ' )
def nolink ( self ) :
''' using the nolink type in conf.check() allows us to avoid
the link stage of a test , thus speeding it up for tests
that where linking is not needed '''
pass
2010-03-20 11:26:32 +03:00
2010-03-23 20:48:32 +03:00
def CHECK_HEADER ( conf , h , add_headers = False , lib = None ) :
2010-03-07 08:05:08 +03:00
''' check for a header '''
2011-01-25 05:09:27 +03:00
if h in missing_headers and lib is None :
2010-03-23 01:29:19 +03:00
return False
d = h . upper ( ) . replace ( ' / ' , ' _ ' )
d = d . replace ( ' . ' , ' _ ' )
2010-05-28 17:50:26 +04:00
d = d . replace ( ' - ' , ' _ ' )
2010-03-23 01:29:19 +03:00
d = ' HAVE_ %s ' % d
2010-03-20 11:26:32 +03:00
if CONFIG_SET ( conf , d ) :
if add_headers :
2010-03-23 01:29:19 +03:00
if not h in conf . env . hlist :
conf . env . hlist . append ( h )
2010-03-07 06:27:56 +03:00
return True
2010-03-23 01:29:19 +03:00
2012-04-11 12:40:27 +04:00
( ccflags , ldflags , cpppath ) = library_flags ( conf , lib )
2010-03-23 20:48:32 +03:00
2010-03-23 01:29:19 +03:00
hdrs = hlist_to_string ( conf , headers = h )
2012-02-19 06:58:32 +04:00
if lib is None :
lib = " "
2010-03-23 01:29:19 +03:00
ret = conf . check ( fragment = ' %s \n int main(void) { return 0; } ' % hdrs ,
type = ' nolink ' ,
execute = 0 ,
2010-03-23 20:48:32 +03:00
ccflags = ccflags ,
2012-04-11 12:40:27 +04:00
includes = cpppath ,
2012-02-19 06:58:32 +04:00
uselib = lib . upper ( ) ,
2010-03-23 01:29:19 +03:00
msg = " Checking for header %s " % h )
if not ret :
missing_headers . add ( h )
return False
conf . DEFINE ( d , 1 )
if add_headers and not h in conf . env . hlist :
2010-03-20 11:26:32 +03:00
conf . env . hlist . append ( h )
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-23 20:48:32 +03:00
def CHECK_HEADERS ( conf , headers , add_headers = False , together = False , lib = None ) :
2010-03-23 16:32:23 +03:00
''' check for a list of headers
when together == True , then the headers accumulate within this test .
This is useful for interdependent headers
'''
2010-03-07 06:27:56 +03:00
ret = True
2010-03-23 16:32:23 +03:00
if not add_headers and together :
saved_hlist = conf . env . hlist [ : ]
set_add_headers = True
else :
set_add_headers = add_headers
2010-03-23 01:29:19 +03:00
for hdr in TO_LIST ( headers ) :
2010-03-23 20:48:32 +03:00
if not CHECK_HEADER ( conf , hdr , set_add_headers , lib = lib ) :
2010-03-07 06:27:56 +03:00
ret = False
2010-03-23 16:32:23 +03:00
if not add_headers and together :
conf . env . hlist = saved_hlist
2010-03-07 06:27:56 +03:00
return ret
2010-02-26 14:21:50 +03:00
2010-03-23 16:32:23 +03:00
2010-03-23 20:48:32 +03:00
def header_list ( conf , headers = None , lib = None ) :
2010-03-23 01:29:19 +03:00
''' form a list of headers which exist, as a string '''
hlist = [ ]
if headers is not None :
for h in TO_LIST ( headers ) :
2010-03-23 20:48:32 +03:00
if CHECK_HEADER ( conf , h , add_headers = False , lib = lib ) :
2010-03-23 01:29:19 +03:00
hlist . append ( h )
return hlist_to_string ( conf , headers = hlist )
@conf
2010-03-24 03:23:41 +03:00
def CHECK_TYPE ( conf , t , alternate = None , headers = None , define = None , lib = None , msg = None ) :
2010-03-23 01:29:19 +03:00
''' check for a single type '''
if define is None :
define = ' HAVE_ ' + t . upper ( ) . replace ( ' ' , ' _ ' )
2010-03-24 03:23:41 +03:00
if msg is None :
msg = ' Checking for %s ' % t
2010-03-23 01:29:19 +03:00
ret = CHECK_CODE ( conf , ' %s _x ' % t ,
define ,
execute = False ,
headers = headers ,
local_include = False ,
2010-03-24 03:23:41 +03:00
msg = msg ,
2010-03-23 20:48:32 +03:00
lib = lib ,
2010-03-23 01:29:19 +03:00
link = False )
if not ret and alternate :
conf . DEFINE ( t , alternate )
return ret
2010-03-07 08:05:08 +03:00
2010-02-26 14:21:50 +03:00
@conf
2010-03-23 20:48:32 +03:00
def CHECK_TYPES ( conf , list , headers = None , define = None , alternate = None , lib = None ) :
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-20 08:27:48 +03:00
for t in TO_LIST ( list ) :
2010-03-23 20:48:32 +03:00
if not CHECK_TYPE ( conf , t , headers = headers ,
define = define , alternate = alternate , lib = lib ) :
2010-03-07 06:27:56 +03:00
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
2010-03-23 01:29:19 +03:00
def CHECK_TYPE_IN ( conf , t , headers = None , alternate = None , define = None ) :
''' check for a single type with a header '''
return CHECK_TYPE ( conf , t , headers = headers , alternate = alternate , define = define )
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-23 20:48:32 +03:00
def CHECK_VARIABLE ( conf , v , define = None , always = False ,
headers = None , msg = None , lib = None ) :
2010-03-07 08:05:08 +03:00
''' check for a variable declaration (or define) '''
2010-03-07 05:48:33 +03:00
if define is None :
define = ' HAVE_ %s ' % v . upper ( )
2010-03-22 10:38:38 +03:00
if msg is None :
msg = " Checking for variable %s " % v
2010-03-23 01:29:19 +03:00
return CHECK_CODE ( conf ,
2010-04-13 14:56:19 +04:00
# we need to make sure the compiler doesn't
# optimize it out...
2010-03-23 01:29:19 +03:00
'''
#ifndef %s
2010-04-13 14:56:19 +04:00
void * _x ; _x = ( void * ) & % s ; return ( int ) _x ;
2010-03-23 01:29:19 +03:00
#endif
return 0
''' % (v, v),
execute = False ,
link = False ,
msg = msg ,
local_include = False ,
2010-03-23 20:48:32 +03:00
lib = lib ,
2010-03-23 01:29:19 +03:00
headers = headers ,
define = define ,
always = always )
2010-02-26 14:21:50 +03:00
2010-03-07 06:32:27 +03:00
@conf
2010-04-06 02:28:05 +04:00
def CHECK_DECLS ( conf , vars , reverse = False , headers = None , always = False ) :
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-20 08:27:48 +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 ( )
2010-03-22 10:38:38 +03:00
if not CHECK_VARIABLE ( conf , v ,
define = define ,
headers = headers ,
2010-04-06 02:28:05 +04:00
msg = ' Checking for declaration of %s ' % v ,
always = always ) :
2010-03-07 06:32:27 +03:00
ret = False
return ret
2010-03-30 05:47:54 +04:00
def CHECK_FUNC ( conf , f , link = True , lib = None , headers = None ) :
2010-03-07 08:05:08 +03:00
''' check for a function '''
2010-03-20 09:51:39 +03:00
define = ' HAVE_ %s ' % f . upper ( )
2010-03-20 11:26:32 +03:00
2010-03-23 01:29:19 +03:00
ret = False
2010-03-30 07:41:08 +04:00
conf . COMPOUND_START ( ' Checking for %s ' % f )
2012-09-27 20:30:47 +04:00
if link is None or link :
2010-03-23 01:29:19 +03:00
ret = CHECK_CODE ( conf ,
2010-03-30 07:41:08 +04:00
# this is based on the autoconf strategy
'''
#define %s __fake__%s
#ifdef HAVE_LIMITS_H
# include <limits.h>
#else
# include <assert.h>
#endif
#undef %s
#if defined __stub_%s || defined __stub___%s
#error "bad glibc stub"
2010-03-30 05:47:54 +04:00
#endif
2010-03-30 07:41:08 +04:00
extern char % s ( ) ;
int main ( ) { return % s ( ) ; }
''' % (f, f, f, f, f, f, f),
2010-03-23 01:29:19 +03:00
execute = False ,
link = True ,
addmain = False ,
add_headers = False ,
define = define ,
local_include = False ,
lib = lib ,
headers = headers ,
msg = ' Checking for %s ' % f )
2010-03-30 07:41:08 +04:00
if not ret :
ret = CHECK_CODE ( conf ,
# it might be a macro
2010-04-13 14:56:19 +04:00
# we need to make sure the compiler doesn't
# optimize it out...
' void *__x = (void *) %s ; return (int)__x ' % f ,
2010-03-30 07:41:08 +04:00
execute = False ,
link = True ,
addmain = True ,
add_headers = True ,
define = define ,
local_include = False ,
lib = lib ,
headers = headers ,
msg = ' Checking for macro %s ' % f )
2012-09-27 20:30:47 +04:00
if not ret and ( link is None or not link ) :
2010-03-23 01:29:19 +03:00
ret = CHECK_VARIABLE ( conf , f ,
define = define ,
headers = headers ,
msg = ' Checking for declaration of %s ' % f )
2010-03-30 07:41:08 +04:00
conf . COMPOUND_END ( ret )
2010-03-23 01:29:19 +03:00
return ret
2010-02-26 14:21:50 +03:00
@conf
2010-03-30 05:47:54 +04:00
def CHECK_FUNCS ( conf , list , link = True , lib = None , headers = None ) :
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-20 08:27:48 +03:00
for f in TO_LIST ( list ) :
2010-03-23 01:29:19 +03:00
if not CHECK_FUNC ( conf , f , link = link , lib = lib , headers = headers ) :
2010-03-07 06:27:56 +03:00
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-23 01:29:19 +03:00
ret = True
2010-03-20 08:27:48 +03:00
for v in TO_LIST ( vars ) :
2010-03-23 01:29:19 +03:00
v_define = define
if v_define is None :
v_define = ' SIZEOF_ %s ' % v . upper ( ) . replace ( ' ' , ' _ ' )
if not CHECK_CODE ( conf ,
2010-04-21 09:15:55 +04:00
' printf( " %% u " , (unsigned)sizeof( %s )) ' % v ,
2010-03-23 01:29:19 +03:00
define = v_define ,
execute = True ,
define_ret = True ,
quote = False ,
headers = headers ,
local_include = False ,
msg = " Checking size of %s " % v ) :
ret = False
return ret
2013-02-22 17:20:07 +04:00
@conf
def CHECK_VALUEOF ( conf , v , headers = None , define = None ) :
''' check the value of a variable/define '''
ret = True
v_define = define
if v_define is None :
v_define = ' VALUEOF_ %s ' % v . upper ( ) . replace ( ' ' , ' _ ' )
if CHECK_CODE ( conf ,
' printf( " %% u " , (unsigned)( %s )) ' % v ,
define = v_define ,
execute = True ,
define_ret = True ,
quote = False ,
headers = headers ,
local_include = False ,
msg = " Checking value of %s " % v ) :
return int ( conf . env [ v_define ] )
return None
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 ,
2010-03-23 01:29:19 +03:00
always = False , execute = False , addmain = True ,
add_headers = True , mandatory = False ,
2010-03-19 11:50:21 +03:00
headers = None , msg = None , cflags = ' ' , includes = ' # . ' ,
2010-03-23 16:32:23 +03:00
local_include = True , lib = None , link = True ,
2010-04-21 09:15:55 +04:00
define_ret = False , quote = False ,
on_target = True ) :
2010-03-07 09:00:22 +03:00
''' check if some code compiles and/or runs '''
2010-03-23 01:29:19 +03:00
if CONFIG_SET ( conf , define ) :
return True
2010-03-07 08:18:33 +03:00
if headers is not None :
2010-03-23 20:48:32 +03:00
CHECK_HEADERS ( conf , headers = headers , lib = lib )
2010-03-07 09:00:22 +03:00
2010-03-23 01:29:19 +03:00
if add_headers :
2010-03-23 20:48:32 +03:00
hdrs = header_list ( conf , headers = headers , lib = lib )
2010-03-23 01:29:19 +03:00
else :
hdrs = ' '
2010-03-07 09:00:22 +03:00
if execute :
execute = 1
else :
execute = 0
2010-04-24 20:10:37 +04:00
defs = conf . get_config_header ( )
2010-03-07 09:00:22 +03:00
if addmain :
2010-04-24 20:10:37 +04:00
fragment = ' %s \n %s \n int main(void) { %s ; return 0; } \n ' % ( defs , hdrs , code )
2010-03-07 09:00:22 +03:00
else :
2010-04-24 20:10:37 +04:00
fragment = ' %s \n %s \n %s \n ' % ( defs , hdrs , code )
2010-03-07 09:00:22 +03:00
if msg is None :
msg = " Checking for %s " % define
2010-11-21 15:04:43 +03:00
cflags = TO_LIST ( cflags )
2010-03-07 16:06:39 +03:00
if local_include :
2010-11-21 15:04:43 +03:00
cflags . append ( ' -I %s ' % conf . curdir )
2010-03-07 15:16:20 +03:00
2010-03-23 01:29:19 +03:00
if not link :
type = ' nolink '
else :
type = ' cprogram '
2010-03-23 20:48:32 +03:00
uselib = TO_LIST ( lib )
2012-04-11 12:40:27 +04:00
( ccflags , ldflags , cpppath ) = library_flags ( conf , uselib )
includes = TO_LIST ( includes )
includes . extend ( cpppath )
2010-03-23 20:48:32 +03:00
2012-02-19 07:48:27 +04:00
uselib = [ l . upper ( ) for l in uselib ]
2010-03-23 20:48:32 +03:00
cflags . extend ( ccflags )
2010-03-23 16:32:23 +03:00
2010-04-21 09:15:55 +04:00
if on_target :
exec_args = conf . SAMBA_CROSS_ARGS ( msg = msg )
else :
exec_args = [ ]
conf . COMPOUND_START ( msg )
2010-04-12 16:06:51 +04:00
2010-03-23 16:32:23 +03:00
ret = conf . check ( fragment = fragment ,
execute = execute ,
define_name = define ,
mandatory = mandatory ,
2010-03-23 20:48:32 +03:00
ccflags = cflags ,
ldflags = ldflags ,
2010-03-23 16:32:23 +03:00
includes = includes ,
uselib = uselib ,
type = type ,
msg = msg ,
quote = quote ,
2010-04-12 16:06:51 +04:00
exec_args = exec_args ,
2010-03-23 16:32:23 +03:00
define_ret = define_ret )
if not ret and CONFIG_SET ( conf , define ) :
# sometimes conf.check() returns false, but it
# sets the define. Maybe a waf bug?
ret = True
if ret :
2010-03-23 01:29:19 +03:00
if not define_ret :
conf . DEFINE ( define , 1 )
2010-04-21 09:15:55 +04:00
conf . COMPOUND_END ( True )
else :
conf . COMPOUND_END ( conf . env [ define ] )
2010-03-07 08:18:33 +03:00
return True
2010-03-07 14:52:13 +03:00
if always :
2010-03-07 08:18:33 +03:00
conf . DEFINE ( define , 0 )
2010-04-21 09:15:55 +04:00
conf . COMPOUND_END ( False )
2010-03-07 14:52:13 +03:00
return False
2010-03-07 08:18:33 +03:00
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 '''
if define is None :
define = ' HAVE_ %s ' % member . upper ( )
2010-03-23 01:29:19 +03:00
return CHECK_CODE ( conf ,
' %s s; void *_x; _x=(void *)&s. %s ' % ( structname , member ) ,
define ,
execute = False ,
link = False ,
always = always ,
headers = headers ,
local_include = False ,
msg = " Checking for member %s in %s " % ( member , structname ) )
2010-03-07 08:05:08 +03:00
2010-03-07 14:52:13 +03:00
@conf
2012-08-06 12:46:30 +04:00
def CHECK_CFLAGS ( conf , cflags , fragment = ' int main(void) { return 0; } \n ' ) :
2010-03-23 01:29:19 +03:00
''' check if the given cflags are accepted by the compiler
'''
2012-08-06 12:46:30 +04:00
return conf . check ( fragment = fragment ,
2010-03-23 01:29:19 +03:00
execute = 0 ,
2010-03-23 20:52:23 +03:00
type = ' nolink ' ,
2010-03-23 01:29:19 +03:00
ccflags = cflags ,
msg = " Checking compiler accepts %s " % cflags )
2010-03-07 14:52:13 +03:00
2010-10-21 11:36:41 +04:00
@conf
def CHECK_LDFLAGS ( conf , ldflags ) :
''' check if the given ldflags are accepted by the linker
'''
return conf . check ( fragment = ' int main(void) { return 0; } \n ' ,
execute = 0 ,
ldflags = ldflags ,
msg = " Checking linker accepts %s " % ldflags )
2010-03-07 14:52:13 +03:00
2010-12-10 02:36:24 +03:00
@conf
def CONFIG_GET ( conf , option ) :
''' return True if a configuration option was found '''
if ( option in conf . env ) :
return conf . env [ option ]
else :
return None
2010-02-26 14:21:50 +03:00
@conf
def CONFIG_SET ( conf , option ) :
2010-03-28 15:01:04 +04:00
''' return True if a configuration option was found '''
wafsamba: try to fix the build on AIX with xlc_r
bld.env['CPP'] can be 'None' or '[]', bld.CONFIG_SET("CPP") should return False
File "./buildtools/wafsamba/samba_pidl.py", line 131, in SAMBA_PIDL_LIST
bld.SAMBA_PIDL(name, p, options=options, output_dir=output_dir, symlink=symlink, generate_tables=generate_tables)
File "./buildtools/wafsamba/samba_pidl.py", line 65, in SAMBA_PIDL
cpp = 'CPP="%s"' % bld.CONFIG_GET("CPP")[0]
IndexError: list index out of range
metze
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Sun Jun 10 20:18:49 CEST 2012 on sn-devel-104
2012-06-10 19:48:15 +04:00
if option not in conf . env :
return False
v = conf . env [ option ]
2012-09-27 20:30:47 +04:00
if v is None :
wafsamba: try to fix the build on AIX with xlc_r
bld.env['CPP'] can be 'None' or '[]', bld.CONFIG_SET("CPP") should return False
File "./buildtools/wafsamba/samba_pidl.py", line 131, in SAMBA_PIDL_LIST
bld.SAMBA_PIDL(name, p, options=options, output_dir=output_dir, symlink=symlink, generate_tables=generate_tables)
File "./buildtools/wafsamba/samba_pidl.py", line 65, in SAMBA_PIDL
cpp = 'CPP="%s"' % bld.CONFIG_GET("CPP")[0]
IndexError: list index out of range
metze
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Sun Jun 10 20:18:49 CEST 2012 on sn-devel-104
2012-06-10 19:48:15 +04:00
return False
if v == [ ] :
return False
if v == ( ) :
return False
return True
2010-02-26 14:21:50 +03:00
Build . BuildContext . CONFIG_SET = CONFIG_SET
2010-12-10 02:36:24 +03:00
Build . BuildContext . CONFIG_GET = CONFIG_GET
2010-02-26 14:21:50 +03:00
2011-02-15 08:13:05 +03:00
def library_flags ( self , libs ) :
2010-03-23 20:48:32 +03:00
''' work out flags from pkg_config '''
ccflags = [ ]
ldflags = [ ]
2012-04-11 12:40:27 +04:00
cpppath = [ ]
2010-03-23 20:48:32 +03:00
for lib in TO_LIST ( libs ) :
2012-02-19 05:16:14 +04:00
# note that we do not add the -I and -L in here, as that is added by the waf
2012-02-02 05:36:44 +04:00
# core. Adding it here would just change the order that it is put on the link line
# which can cause system paths to be added before internal libraries
2011-02-15 08:13:05 +03:00
extra_ccflags = TO_LIST ( getattr ( self . env , ' CCFLAGS_ %s ' % lib . upper ( ) , [ ] ) )
extra_ldflags = TO_LIST ( getattr ( self . env , ' LDFLAGS_ %s ' % lib . upper ( ) , [ ] ) )
2012-04-11 12:40:27 +04:00
extra_cpppath = TO_LIST ( getattr ( self . env , ' CPPPATH_ %s ' % lib . upper ( ) , [ ] ) )
2010-06-19 16:45:35 +04:00
ccflags . extend ( extra_ccflags )
ldflags . extend ( extra_ldflags )
2012-04-11 12:40:27 +04:00
cpppath . extend ( extra_cpppath )
2011-02-15 08:13:05 +03:00
if ' EXTRA_LDFLAGS ' in self . env :
ldflags . extend ( self . env [ ' EXTRA_LDFLAGS ' ] )
2010-10-21 10:41:42 +04:00
ccflags = unique_list ( ccflags )
ldflags = unique_list ( ldflags )
2012-04-11 12:40:27 +04:00
cpppath = unique_list ( cpppath )
return ( ccflags , ldflags , cpppath )
2010-03-23 20:48:32 +03:00
2010-03-23 01:29:19 +03:00
@conf
2010-10-31 16:24:46 +03:00
def CHECK_LIB ( conf , libs , mandatory = False , empty_decl = True , set_target = True , shlib = False ) :
2010-10-06 08:23:58 +04:00
''' check if a set of libraries exist as system libraries
2010-03-23 01:29:19 +03:00
2010-10-06 08:23:58 +04:00
returns the sublist of libs that do exist as a syslib or [ ]
'''
2010-10-31 16:24:46 +03:00
fragment = '''
int foo ( )
{
int v = 2 ;
return v * 2 ;
}
'''
2010-10-06 08:23:58 +04:00
ret = [ ]
2010-03-23 20:48:32 +03:00
liblist = TO_LIST ( libs )
2010-03-23 01:29:19 +03:00
for lib in liblist [ : ] :
2010-04-12 10:21:21 +04:00
if GET_TARGET_TYPE ( conf , lib ) == ' SYSLIB ' :
2010-10-06 08:23:58 +04:00
ret . append ( lib )
2010-03-23 01:29:19 +03:00
continue
2010-03-23 20:48:32 +03:00
2012-04-11 12:40:27 +04:00
( ccflags , ldflags , cpppath ) = library_flags ( conf , lib )
2010-10-31 16:24:46 +03:00
if shlib :
2012-02-19 07:48:27 +04:00
res = conf . check ( features = ' cc cshlib ' , fragment = fragment , lib = lib , uselib_store = lib , ccflags = ccflags , ldflags = ldflags , uselib = lib . upper ( ) )
2010-10-31 16:24:46 +03:00
else :
2012-02-19 07:48:27 +04:00
res = conf . check ( lib = lib , uselib_store = lib , ccflags = ccflags , ldflags = ldflags , uselib = lib . upper ( ) )
2010-03-23 20:48:32 +03:00
2010-10-31 16:24:46 +03:00
if not res :
2010-03-28 09:38:27 +04:00
if mandatory :
2010-04-09 15:12:02 +04:00
Logs . error ( " Mandatory library ' %s ' not found for functions ' %s ' " % ( lib , list ) )
2010-03-28 09:38:27 +04:00
sys . exit ( 1 )
2010-03-28 11:33:25 +04:00
if empty_decl :
# if it isn't a mandatory library, then remove it from dependency lists
2010-10-06 08:23:58 +04:00
if set_target :
SET_TARGET_TYPE ( conf , lib , ' EMPTY ' )
2010-03-23 01:29:19 +03:00
else :
conf . define ( ' HAVE_LIB %s ' % lib . upper ( ) . replace ( ' - ' , ' _ ' ) , 1 )
conf . env [ ' LIB_ ' + lib . upper ( ) ] = lib
2010-10-06 08:23:58 +04:00
if set_target :
conf . SET_TARGET_TYPE ( lib , ' SYSLIB ' )
ret . append ( lib )
2010-03-23 01:29:19 +03:00
return ret
2010-03-28 15:01:04 +04:00
2010-02-26 14:21:50 +03:00
@conf
2010-03-28 11:33:25 +04:00
def CHECK_FUNCS_IN ( conf , list , library , mandatory = False , checklibc = False ,
2010-10-06 08:23:58 +04:00
headers = None , link = True , empty_decl = True , set_target = True ) :
2010-03-28 15:01:04 +04:00
"""
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
optionally check for the functions first in libc
"""
2010-03-20 10:36:33 +03:00
remaining = TO_LIST ( list )
liblist = TO_LIST ( library )
# check if some already found
for f in remaining [ : ] :
if CONFIG_SET ( conf , ' HAVE_ %s ' % f . upper ( ) ) :
remaining . remove ( f )
# see if the functions are in libc
2010-03-07 06:27:56 +03:00
if checklibc :
2010-03-20 10:36:33 +03:00
for f in remaining [ : ] :
2010-03-23 01:29:19 +03:00
if CHECK_FUNC ( conf , f , link = True , headers = headers ) :
2010-03-20 10:36:33 +03:00
remaining . remove ( f )
2010-03-07 06:27:56 +03:00
if remaining == [ ] :
2010-03-20 10:36:33 +03:00
for lib in liblist :
2010-03-28 11:33:25 +04:00
if GET_TARGET_TYPE ( conf , lib ) != ' SYSLIB ' and empty_decl :
2010-03-20 09:21:26 +03:00
SET_TARGET_TYPE ( conf , lib , ' EMPTY ' )
2010-03-07 06:27:56 +03:00
return True
2010-10-06 08:23:58 +04:00
checklist = conf . CHECK_LIB ( liblist , empty_decl = empty_decl , set_target = set_target )
2010-03-20 10:36:33 +03:00
for lib in liblist [ : ] :
2010-10-06 08:23:58 +04:00
if not lib in checklist and mandatory :
Logs . error ( " Mandatory library ' %s ' not found for functions ' %s ' " % ( lib , list ) )
sys . exit ( 1 )
2010-03-07 09:35:31 +03:00
2010-03-07 06:27:56 +03:00
ret = True
for f in remaining :
2010-10-06 08:23:58 +04:00
if not CHECK_FUNC ( conf , f , lib = ' ' . join ( checklist ) , headers = headers , link = link ) :
2010-03-07 06:27:56 +03:00
ret = False
2010-03-20 10:36:33 +03:00
2010-03-07 06:27:56 +03:00
return ret
2010-02-26 14:21:50 +03:00
2010-03-28 15:01:04 +04:00
2010-03-28 09:38:27 +04:00
@conf
def IN_LAUNCH_DIR ( conf ) :
''' return True if this rule is being run from the launch directory '''
return os . path . realpath ( conf . curdir ) == os . path . realpath ( Options . launch_dir )
2010-04-13 14:13:00 +04:00
Options . Handler . IN_LAUNCH_DIR = IN_LAUNCH_DIR
2010-03-28 09:38:27 +04:00
2010-02-26 14:21:50 +03:00
@conf
def SAMBA_CONFIG_H ( conf , path = None ) :
2010-03-28 15:01:04 +04:00
''' write out config.h in the right directory '''
2010-03-19 01:39:58 +03:00
# we don't want to produce a config.h in places like lib/replace
# when we are building projects that depend on lib/replace
2010-03-28 09:38:27 +04:00
if not IN_LAUNCH_DIR ( conf ) :
2010-02-26 14:21:50 +03:00
return
2010-03-20 11:38:35 +03:00
2012-04-11 02:08:44 +04:00
if Options . options . debug :
conf . ADD_CFLAGS ( ' -g ' ,
testflags = True )
2010-03-20 11:38:35 +03:00
if Options . options . developer :
# we add these here to ensure that -Wstrict-prototypes is not set during configure
2014-01-31 19:43:15 +04:00
conf . ADD_CFLAGS ( ' -Wall -g -Wshadow -Werror=strict-prototypes -Wstrict-prototypes -Werror=pointer-arith -Wpointer-arith -Wcast-align -Werror=write-strings -Wwrite-strings -Werror-implicit-function-declaration -Wformat=2 -Wno-format-y2k -Wmissing-prototypes -fno-common -Werror=address -Wdeclaration-after-statement ' ,
2010-03-23 20:52:23 +03:00
testflags = True )
2011-09-01 06:45:38 +04:00
conf . ADD_CFLAGS ( ' -Wcast-qual ' , testflags = True )
2010-10-29 04:50:25 +04:00
conf . env . DEVELOPER_MODE = True
2010-03-20 11:38:35 +03:00
2012-08-06 12:46:30 +04:00
# This check is because for ldb_search(), a NULL format string
# is not an error, but some compilers complain about that.
2012-08-17 14:43:07 +04:00
if CHECK_CFLAGS ( conf , [ " -Werror=format " , " -Wformat=2 " ] , '''
2012-08-06 12:46:30 +04:00
int testformat ( char * format , . . . ) __attribute__ ( ( format ( __printf__ , 1 , 2 ) ) ) ;
int main ( void ) {
testformat ( 0 ) ;
return 0 ;
}
''' ):
if not ' EXTRA_CFLAGS ' in conf . env :
conf . env [ ' EXTRA_CFLAGS ' ] = [ ]
conf . env [ ' EXTRA_CFLAGS ' ] . extend ( TO_LIST ( " -Werror=format " ) )
2010-04-09 13:54:40 +04:00
if Options . options . picky_developer :
conf . ADD_CFLAGS ( ' -Werror ' , testflags = True )
if Options . options . fatal_errors :
conf . ADD_CFLAGS ( ' -Wfatal-errors ' , testflags = True )
2010-03-24 04:56:30 +03:00
if Options . options . pedantic :
2010-04-08 01:45:46 +04:00
conf . ADD_CFLAGS ( ' -W ' , testflags = True )
2010-03-24 04:56:30 +03:00
2010-02-26 14:21:50 +03:00
if path is None :
conf . write_config_header ( ' config.h ' , top = True )
else :
conf . write_config_header ( path )
2010-04-19 09:58:37 +04:00
conf . SAMBA_CROSS_CHECK_COMPLETE ( )
2010-02-26 14:21:50 +03:00
@conf
def CONFIG_PATH ( conf , name , default ) :
2010-03-28 15:01:04 +04:00
''' setup a configurable path '''
2010-02-26 14:21:50 +03:00
if not name in conf . env :
2010-03-07 16:26:07 +03:00
if default [ 0 ] == ' / ' :
conf . env [ name ] = default
else :
conf . env [ name ] = conf . env [ ' PREFIX ' ] + default
2010-03-23 20:52:23 +03:00
2010-02-26 14:21:50 +03:00
@conf
2010-03-23 20:52:23 +03:00
def ADD_CFLAGS ( conf , flags , testflags = False ) :
''' add some CFLAGS to the command line
optionally set testflags to ensure all the flags work
'''
if testflags :
ok_flags = [ ]
for f in flags . split ( ) :
if CHECK_CFLAGS ( conf , f ) :
ok_flags . append ( f )
flags = ok_flags
2010-02-26 14:21:50 +03:00
if not ' EXTRA_CFLAGS ' in conf . env :
conf . env [ ' EXTRA_CFLAGS ' ] = [ ]
2010-03-20 08:27:48 +03:00
conf . env [ ' EXTRA_CFLAGS ' ] . extend ( TO_LIST ( flags ) )
2010-02-26 14:21:50 +03:00
2010-10-18 08:17:56 +04:00
@conf
def ADD_LDFLAGS ( conf , flags , testflags = False ) :
''' add some LDFLAGS to the command line
optionally set testflags to ensure all the flags work
2011-02-15 08:13:51 +03:00
this will return the flags that are added , if any
2010-10-18 08:17:56 +04:00
'''
if testflags :
ok_flags = [ ]
for f in flags . split ( ) :
2010-10-21 11:36:41 +04:00
if CHECK_LDFLAGS ( conf , f ) :
2010-10-18 08:17:56 +04:00
ok_flags . append ( f )
flags = ok_flags
if not ' EXTRA_LDFLAGS ' in conf . env :
conf . env [ ' EXTRA_LDFLAGS ' ] = [ ]
conf . env [ ' EXTRA_LDFLAGS ' ] . extend ( TO_LIST ( flags ) )
2011-02-15 08:13:51 +03:00
return flags
2010-03-23 20:52:23 +03:00
2010-03-28 15:01:04 +04:00
2010-03-17 13:53:29 +03:00
@conf
def ADD_EXTRA_INCLUDES ( conf , includes ) :
2010-03-28 15:01:04 +04:00
''' add some extra include directories to all builds '''
2010-03-17 13:53:29 +03:00
if not ' EXTRA_INCLUDES ' in conf . env :
conf . env [ ' EXTRA_INCLUDES ' ] = [ ]
2010-03-20 08:27:48 +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
2010-03-28 15:01:04 +04:00
2010-04-18 06:43:15 +04:00
def CURRENT_CFLAGS ( bld , target , cflags , hide_symbols = False ) :
2010-03-28 15:01:04 +04:00
''' work out the current flags. local flags are added first '''
2010-02-26 14:21:50 +03:00
if not ' EXTRA_CFLAGS ' in bld . env :
list = [ ]
else :
list = bld . env [ ' EXTRA_CFLAGS ' ] ;
2010-03-20 08:27:48 +03:00
ret = TO_LIST ( cflags )
2010-02-26 14:21:50 +03:00
ret . extend ( list )
2010-04-18 06:43:15 +04:00
if hide_symbols and bld . env . HAVE_VISIBILITY_ATTR :
ret . append ( ' -fvisibility=hidden ' )
2010-02-26 14:21:50 +03:00
return ret
2010-03-20 15:41:15 +03:00
2010-03-21 16:50:14 +03:00
@conf
def CHECK_CC_ENV ( conf ) :
2010-03-28 15:01:04 +04:00
""" trim whitespaces from ' CC ' .
The build farm sometimes puts a space at the start """
2010-03-21 16:50:14 +03:00
if os . environ . get ( ' CC ' ) :
conf . env . CC = TO_LIST ( os . environ . get ( ' CC ' ) )
if len ( conf . env . CC ) == 1 :
# make for nicer logs if just a single command
conf . env . CC = conf . env . CC [ 0 ]
2010-03-21 03:17:37 +03:00
2010-03-21 23:48:10 +03:00
@conf
def SETUP_CONFIGURE_CACHE ( conf , enable ) :
''' enable/disable cache of configure results '''
if enable :
# when -C is chosen, we will use a private cache and will
# not look into system includes. This roughtly matches what
# autoconf does with -C
cache_path = os . path . join ( conf . blddir , ' .confcache ' )
mkdir_p ( cache_path )
Options . cache_global = os . environ [ ' WAFCACHE ' ] = cache_path
else :
# when -C is not chosen we will not cache configure checks
# We set the recursion limit low to prevent waf from spending
# a lot of time on the signatures of the files.
Options . cache_global = os . environ [ ' WAFCACHE ' ] = ' '
preproc . recursion_limit = 1
# in either case we don't need to scan system includes
preproc . go_absolute = False
2011-11-13 21:01:09 +04:00
@conf
def SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS ( conf ) :
# we don't want any libraries or modules to rely on runtime
# resolution of symbols
2013-05-17 12:43:08 +04:00
if not sys . platform . startswith ( " openbsd " ) :
2011-11-13 21:01:09 +04:00
conf . env . undefined_ldflags = conf . ADD_LDFLAGS ( ' -Wl,-no-undefined ' , testflags = True )
2013-05-17 12:43:08 +04:00
if not sys . platform . startswith ( " openbsd " ) and conf . env . undefined_ignore_ldflags == [ ] :
2011-11-13 21:01:09 +04:00
if conf . CHECK_LDFLAGS ( [ ' -undefined ' , ' dynamic_lookup ' ] ) :
conf . env . undefined_ignore_ldflags = [ ' -undefined ' , ' dynamic_lookup ' ]