2010-02-26 14:21:50 +03:00
# a waf tool to add autoconf-like macros to the configure section
2015-10-27 22:46:46 +03:00
import os , sys
2018-01-31 12:48:43 +03:00
from waflib import Build , Options , Logs , Context
from waflib . Configure import conf
from waflib . TaskGen import feature
from waflib . Tools import c_preproc as preproc
2015-11-05 04:06:42 +03:00
from samba_utils import TO_LIST , GET_TARGET_TYPE , SET_TARGET_TYPE , unique_list , mkdir_p
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
@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 :
2016-03-26 15:18:07 +03:00
conf . env . append_value ( ' CFLAGS ' , ' -D %s = %s ' % ( 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 '''
hlist = conf . env . hlist
if headers :
hlist = hlist [ : ]
hlist . extend ( TO_LIST ( headers ) )
2019-08-26 00:01:22 +03:00
hdrs = " \n " . join ( ' #include < %s > ' % h for h in hlist )
2010-03-23 01:29:19 +03:00
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
2018-01-31 12:48:43 +03:00
conf . start_msg ( msg )
conf . saved_check_message_1 = conf . start_msg
conf . start_msg = null_check_message_1
conf . saved_check_message_2 = conf . end_msg
conf . end_msg = null_check_message_2
2010-03-30 07:41:08 +04:00
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
2018-01-31 12:48:43 +03:00
conf . start_msg = conf . saved_check_message_1
conf . end_msg = conf . saved_check_message_2
p = conf . end_msg
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
2023-12-17 19:37:33 +03:00
( ccflags , ldflags , cpppath , libs ) = 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 = " "
2019-02-09 03:30:50 +03:00
ret = conf . check ( fragment = ' %s \n int main(void) { return 0; } \n ' % hdrs ,
2010-03-23 01:29:19 +03:00
type = ' nolink ' ,
execute = 0 ,
2016-03-26 15:18:07 +03:00
cflags = ccflags ,
2015-11-12 02:27:31 +03:00
mandatory = False ,
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
2022-08-11 01:41:28 +03:00
def CHECK_TYPE ( conf , t , alternate = None , headers = None , define = None , lib = None , msg = None , cflags = ' ' ) :
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 ,
2022-08-11 01:41:28 +03:00
cflags = cflags ,
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
2022-08-11 01:41:28 +03:00
def CHECK_TYPE_IN ( conf , t , headers = None , alternate = None , define = None , cflags = ' ' ) :
2010-03-23 01:29:19 +03:00
''' check for a single type with a header '''
2022-08-11 01:41:28 +03:00
return CHECK_TYPE ( conf , t , headers = headers , alternate = alternate , define = define , cflags = cflags )
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 ,
2022-11-23 17:12:14 +03:00
headers = None , msg = None , lib = None ,
mandatory = False ) :
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 ,
2022-11-23 17:12:14 +03:00
mandatory = mandatory ,
2010-03-23 01:29:19 +03:00
always = always )
2010-02-26 14:21:50 +03:00
2010-03-07 06:32:27 +03:00
@conf
2021-12-06 20:00:33 +03:00
def CHECK_DECLS ( conf , vars , reverse = False , headers = None , lib = 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 ,
2021-12-06 20:00:33 +03:00
lib = lib ,
2010-04-06 02:28:05 +04:00
msg = ' Checking for declaration of %s ' % v ,
always = always ) :
2015-06-12 13:13:23 +03:00
if not CHECK_CODE ( conf ,
'''
return ( int ) % s ;
''' % (v),
execute = False ,
link = False ,
msg = ' Checking for declaration of %s (as enum) ' % v ,
local_include = False ,
headers = headers ,
2021-12-06 20:00:33 +03:00
lib = lib ,
2015-06-12 13:13:23 +03:00
define = define ,
always = always ) :
ret = False
2010-03-07 06:32:27 +03:00
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
2019-02-11 12:03:00 +03:00
in_lib_str = " "
if lib :
in_lib_str = " in %s " % lib
conf . COMPOUND_START ( ' Checking for %s %s ' % ( f , in_lib_str ) )
2010-03-30 07:41:08 +04:00
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
2014-04-21 17:18:16 +04:00
def CHECK_SIZEOF ( conf , vars , headers = None , define = None , critical = True ) :
2010-03-07 08:05:08 +03:00
''' check the size of a type '''
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
2014-04-21 17:18:16 +04:00
ret = False
2010-03-23 01:29:19 +03:00
if v_define is None :
v_define = ' SIZEOF_ %s ' % v . upper ( ) . replace ( ' ' , ' _ ' )
2018-12-22 05:27:32 +03:00
for size in list ( ( 1 , 2 , 4 , 8 , 16 , 32 , 64 ) ) :
2014-04-21 17:18:16 +04:00
if CHECK_CODE ( conf ,
' static int test_array[1 - 2 * !(((long int)(sizeof( %s ))) <= %d )]; ' % ( v , size ) ,
define = v_define ,
quote = False ,
headers = headers ,
local_include = False ,
msg = " Checking if size of %s == %d " % ( v , size ) ) :
conf . DEFINE ( v_define , size )
ret = True
break
if not ret and critical :
Logs . error ( " Couldn ' t determine size of ' %s ' " % v )
sys . exit ( 1 )
2010-03-23 01:29:19 +03:00
return ret
2022-02-24 05:24:13 +03:00
@conf
def CHECK_SIGN ( conf , v , headers = None ) :
''' check the sign of a type '''
define_name = v . upper ( ) . replace ( ' ' , ' _ ' )
for op , signed in [ ( ' < ' , ' signed ' ) ,
( ' > ' , ' unsigned ' ) ] :
if CHECK_CODE ( conf ,
f ' static int test_array[1 - 2 * !((( { v } )-1) { op } 0)]; ' ,
define = f ' { define_name } _ { signed . upper ( ) } ' ,
quote = False ,
headers = headers ,
local_include = False ,
msg = f " Checking if ' { v } ' is { signed } " ) :
return True
return False
2013-02-22 17:20:07 +04:00
@conf
2023-05-09 10:52:04 +03:00
def CHECK_VALUEOF ( conf , v , headers = None , define = None , lib = None ) :
2013-02-22 17:20:07 +04:00
''' 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 ,
2023-05-09 10:52:04 +03:00
lib = lib ,
2013-02-22 17:20:07 +04:00
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 ,
2018-07-03 06:56:13 +03:00
on_target = True , strict = False ) :
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
if addmain :
2016-03-26 15:18:07 +03:00
fragment = ' %s \n int main(void) { %s ; return 0; } \n ' % ( hdrs , code )
2010-03-07 09:00:22 +03:00
else :
2016-03-26 15:18:07 +03:00
fragment = ' %s \n %s \n ' % ( 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 )
2018-07-03 06:56:13 +03:00
# Be strict when relying on a compiler check
# Some compilers (e.g. xlc) ignore non-supported features as warnings
if strict :
2019-02-10 03:29:22 +03:00
if ' WERROR_CFLAGS ' in conf . env :
cflags . extend ( conf . env [ ' WERROR_CFLAGS ' ] )
2018-07-03 06:56:13 +03:00
2010-03-07 16:06:39 +03:00
if local_include :
2018-01-31 12:48:43 +03:00
cflags . append ( ' -I %s ' % conf . path . abspath ( ) )
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 )
2023-12-17 19:37:33 +03:00
( ccflags , ldflags , cpppath , libs ) = library_flags ( conf , uselib )
2012-04-11 12:40:27 +04:00
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 :
2019-10-07 00:37:17 +03:00
test_args = conf . SAMBA_CROSS_ARGS ( msg = msg )
2010-04-21 09:15:55 +04:00
else :
2019-10-07 00:37:17 +03:00
test_args = [ ]
2010-04-21 09:15:55 +04:00
conf . COMPOUND_START ( msg )
2010-04-12 16:06:51 +04:00
2016-03-26 15:18:07 +03:00
try :
ret = conf . check ( fragment = fragment ,
2010-03-23 16:32:23 +03:00
execute = execute ,
define_name = define ,
2016-03-26 15:18:07 +03:00
cflags = cflags ,
2010-03-23 20:48:32 +03:00
ldflags = ldflags ,
2010-03-23 16:32:23 +03:00
includes = includes ,
uselib = uselib ,
type = type ,
msg = msg ,
quote = quote ,
2019-10-07 00:37:17 +03:00
test_args = test_args ,
2010-03-23 16:32:23 +03:00
define_ret = define_ret )
2016-03-26 15:18:07 +03:00
except Exception :
if always :
2018-09-10 11:22:16 +03:00
conf . DEFINE ( define , 0 )
2018-09-07 17:34:48 +03:00
else :
conf . undefine ( define )
2016-03-26 15:18:07 +03:00
conf . COMPOUND_END ( False )
if mandatory :
raise
return False
else :
2018-09-06 10:51:00 +03:00
# Success is indicated by ret but we should unset
# defines set by WAF's c_config.check() because it
# defines it to int(ret) and we want to undefine it
if not ret :
conf . undefine ( define )
conf . COMPOUND_END ( False )
return False
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 :
2016-03-26 15:18:07 +03:00
conf . DEFINE ( define , ret , quote = quote )
conf . COMPOUND_END ( ret )
2010-03-07 08:18:33 +03:00
return True
2010-03-07 08:05:08 +03:00
@conf
def CHECK_STRUCTURE_MEMBER ( conf , structname , member ,
2018-01-19 17:34:32 +03:00
always = False , define = None , headers = None ,
lib = None ) :
2010-03-07 08:05:08 +03:00
''' 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 ,
2018-01-19 17:34:32 +03:00
lib = lib ,
2010-03-23 01:29:19 +03:00
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
2019-11-12 07:17:02 +03:00
def CHECK_CFLAGS ( conf , cflags , fragment = ' int main(void) { return 0; } \n ' ,
mandatory = False ) :
2010-03-23 01:29:19 +03:00
''' check if the given cflags are accepted by the compiler
'''
2017-11-20 23:53:12 +03:00
check_cflags = TO_LIST ( cflags )
if ' WERROR_CFLAGS ' in conf . env :
check_cflags . extend ( conf . env [ ' WERROR_CFLAGS ' ] )
2012-08-06 12:46:30 +04:00
return conf . check ( fragment = fragment ,
2010-03-23 01:29:19 +03:00
execute = 0 ,
2019-11-12 07:17:02 +03:00
mandatory = mandatory ,
2010-03-23 20:52:23 +03:00
type = ' nolink ' ,
2018-06-27 16:44:12 +03:00
cflags = check_cflags ,
2010-03-23 01:29:19 +03:00
msg = " Checking compiler accepts %s " % cflags )
2010-03-07 14:52:13 +03:00
2010-10-21 11:36:41 +04:00
@conf
2019-11-12 07:17:02 +03:00
def CHECK_LDFLAGS ( conf , ldflags ,
mandatory = False ) :
2010-10-21 11:36:41 +04:00
''' check if the given ldflags are accepted by the linker
'''
return conf . check ( fragment = ' int main(void) { return 0; } \n ' ,
execute = 0 ,
ldflags = ldflags ,
2019-11-12 07:17:02 +03:00
mandatory = mandatory ,
2010-10-21 11:36:41 +04:00
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
2013-10-08 14:10:54 +04:00
@conf
def CONFIG_RESET ( conf , option ) :
if option not in conf . env :
return
del conf . env [ option ]
Build . BuildContext . CONFIG_RESET = CONFIG_RESET
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
2023-12-17 19:37:33 +03:00
def library_flags ( self , library ) :
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 = [ ]
2023-12-17 19:37:33 +03:00
libs = [ ]
for lib in TO_LIST ( library ) :
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
2016-03-26 15:18:07 +03:00
extra_ccflags = TO_LIST ( getattr ( self . env , ' CFLAGS_ %s ' % lib . upper ( ) , [ ] ) )
2011-02-15 08:13:05 +03:00
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 ( ) , [ ] ) )
2023-12-17 19:37:33 +03:00
extra_libs = TO_LIST ( getattr ( self . env , ' LIB_ %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 )
2023-12-17 19:37:33 +03:00
libs . extend ( extra_libs )
2016-03-26 15:18:07 +03:00
extra_cpppath = TO_LIST ( getattr ( self . env , ' INCLUDES_ %s ' % lib . upper ( ) , [ ] ) )
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 )
2023-12-17 19:37:33 +03:00
libs = unique_list ( libs )
return ( ccflags , ldflags , cpppath , libs )
2010-03-23 20:48:32 +03:00
2010-03-23 01:29:19 +03:00
@conf
2023-12-17 19:37:33 +03:00
def CHECK_LIB ( conf , library , 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 = [ ]
2023-12-17 19:37:33 +03:00
liblist = TO_LIST ( library )
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
2023-12-17 19:37:33 +03:00
( ccflags , ldflags , cpppath , libs ) = library_flags ( conf , lib )
2010-10-31 16:24:46 +03:00
if shlib :
2023-12-17 04:47:09 +03:00
# Avoid repeating the library if it is already named by
# pkg-config --libs.
kw = { }
if lib not in libs :
kw [ ' lib ' ] = lib
res = conf . check ( features = ' c cshlib ' , fragment = fragment , uselib_store = lib , cflags = ccflags , ldflags = ldflags , uselib = lib . upper ( ) , mandatory = False , * * kw )
2010-10-31 16:24:46 +03:00
else :
2016-03-26 15:18:07 +03:00
res = conf . check ( lib = lib , uselib_store = lib , cflags = ccflags , ldflags = ldflags , uselib = lib . upper ( ) , mandatory = False )
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 :
2023-12-13 22:25:38 +03:00
Logs . error ( " Mandatory library ' %s ' not found for functions ' %s ' " % ( lib , libs ) )
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 :
2014-03-27 19:37:18 +04:00
conf . define ( ' HAVE_LIB %s ' % lib . upper ( ) . replace ( ' - ' , ' _ ' ) . replace ( ' . ' , ' _ ' ) , 1 )
2023-12-17 04:47:09 +03:00
# To avoid losing information from pkg-config, append the library
# only it is not already present.
if lib not in libs :
conf . env . append_value ( ' 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 '''
2018-01-31 12:48:43 +03:00
return os . path . realpath ( conf . path . abspath ( ) ) == os . path . realpath ( Context . launch_dir )
Options . OptionsContext . 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
2015-09-11 22:57:16 +03:00
# we need to build real code that can't be optimized away to test
2018-09-03 11:35:08 +03:00
stack_protect_list = [ ' -fstack-protector-strong ' , ' -fstack-protector ' ]
for stack_protect_flag in stack_protect_list :
flag_supported = conf . check ( fragment = '''
#include <stdio.h>
int main ( void )
{
char t [ 100000 ] ;
while ( fgets ( t , sizeof ( t ) , stdin ) ) ;
return 0 ;
}
''' ,
execute = 0 ,
2018-06-27 16:44:12 +03:00
cflags = [ ' -Werror ' , ' -Wp,-D_FORTIFY_SOURCE=2 ' , stack_protect_flag ] ,
2018-09-03 11:35:08 +03:00
mandatory = False ,
msg = ' Checking if compiler accepts %s ' % ( stack_protect_flag ) )
if flag_supported :
2018-11-20 14:09:31 +03:00
conf . ADD_CFLAGS ( ' %s ' % ( stack_protect_flag ) )
2018-09-03 11:35:08 +03:00
break
2015-01-07 11:54:43 +03:00
2018-09-03 11:49:52 +03:00
flag_supported = conf . check ( fragment = '''
#include <stdio.h>
int main ( void )
{
char t [ 100000 ] ;
while ( fgets ( t , sizeof ( t ) , stdin ) ) ;
return 0 ;
}
''' ,
execute = 0 ,
2018-06-27 16:44:12 +03:00
cflags = [ ' -Werror ' , ' -fstack-clash-protection ' ] ,
2018-09-03 11:49:52 +03:00
mandatory = False ,
msg = ' Checking if compiler accepts -fstack-clash-protection ' )
if flag_supported :
conf . ADD_CFLAGS ( ' -fstack-clash-protection ' )
2012-04-11 02:08:44 +04:00
if Options . options . debug :
2014-03-10 19:15:14 +04:00
conf . ADD_CFLAGS ( ' -g ' , testflags = True )
2012-04-11 02:08:44 +04:00
pidl: optionally annotate output for debug purposes
It can sometimes be hard to tell which bit of pidl generated which bit
of C. This commit wants to help.
If the PIDL_DEVELOPER environment variable is set (via waf
--pidl-developer or some other means), pidl will annotate *most* C
indicating which lines were generated by which bits of pidl. It looks
something like this:
_PUBLIC_ enum ndr_err_code ndr_push_auth_session_info(struct ndr_push *ndr, int ndr_flags, const struct auth_session_info *r)
{ //:PIDL: Parse::Pidl::Samba4::NDR::Parser::ParseTypePushFunction lib/Parse/Pidl/Samba4/NDR/Parser.pm:3079
NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); //:PIDL: Parse::Pidl::Samba4::NDR::Parser::ParseStructPush lib/Parse/Pidl/Samba4/NDR/Parser.pm:604
if (ndr_flags & NDR_SCALARS) {
NDR_CHECK(ndr_push_align(ndr, 5)); //:PIDL: Parse::Pidl::Samba4::NDR::Parser::ParseStructPushPrimitives lib/Parse/Pidl/Samba4/NDR/Parser.pm:1448
NDR_CHECK(ndr_push_unique_ptr(ndr, r->security_token)); //:PIDL: Parse::Pidl::Samba4::NDR::Parser::ParsePtrPush lib/Parse/Pidl/Samba4/NDR/Parser.pm:604
NDR_CHECK(ndr_push_unique_ptr(ndr, r->unix_token));
NDR_CHECK(ndr_push_unique_ptr(ndr, r->info));
NDR_CHECK(ndr_push_unique_ptr(ndr, r->unix_info));
NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, 0));
/* [ignore] 'torture' */ //:PIDL: Parse::Pidl::Samba4::NDR::Parser::ParseElementPushLevel lib/Parse/Pidl/Samba4/NDR/Parser.pm:729
NDR_CHECK(ndr_push_DATA_BLOB(ndr, NDR_SCALARS, r->session_key)); //:PIDL: Parse::Pidl::Samba4::NDR::Parser::ParseDataPush lib/Parse/Pidl/Samba4/NDR/Parser.pm:604
NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, 0)); //:PIDL: Parse::Pidl::Samba4::NDR::Parser::ParsePtrPush lib/Parse/Pidl/Samba4/NDR/Parser.pm:604
/* [ignore] 'credentials' */ //:PIDL: Parse::Pidl::Samba4::NDR::Parser::ParseElementPushLevel lib/Parse/Pidl/Samba4/NDR/Parser.pm:729
The comments starting with '//:PIDL:' have the function name, the filename,
and line number. The comment follows the ordinary output, and uses the '//'
style so as not to interfere with multiline /* */ comments if they happen
to exist.
A '//:PIDL:' comment is added whenever the pidl function or indentation
level changes, and very occasionally at other places if pidl runs for a
while without either of these things happening.
This does not affect pidl parsers that do not inherit from Parse::Pidl::Base,
and is careful to have no performance impact on non-debug generation.
This may help with semi-automated flow analysis.
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-11-30 06:22:22 +03:00
if Options . options . pidl_developer :
conf . env . PIDL_DEVELOPER_MODE = True
2010-03-20 11:38:35 +03:00
if Options . options . developer :
2014-03-10 19:15:14 +04:00
conf . env . DEVELOPER_MODE = True
conf . ADD_CFLAGS ( ' -g ' , testflags = True )
conf . ADD_CFLAGS ( ' -Wall ' , testflags = True )
conf . ADD_CFLAGS ( ' -Wshadow ' , testflags = True )
conf . ADD_CFLAGS ( ' -Wmissing-prototypes ' , testflags = True )
2019-04-29 23:07:08 +03:00
if CHECK_CODE ( conf ,
' struct a { int b; }; struct c { struct a d; } e = { }; ' ,
' CHECK_C99_INIT ' ,
link = False ,
cflags = ' -Wmissing-field-initializers -Werror=missing-field-initializers ' ,
msg = " Checking C99 init of nested structs. " ) :
conf . ADD_CFLAGS ( ' -Wmissing-field-initializers ' , testflags = True )
2019-02-14 14:06:57 +03:00
conf . ADD_CFLAGS ( ' -Wformat-overflow=2 ' , testflags = True )
2019-02-14 14:08:37 +03:00
conf . ADD_CFLAGS ( ' -Wformat-zero-length ' , testflags = True )
2014-03-10 19:15:14 +04:00
conf . ADD_CFLAGS ( ' -Wcast-align -Wcast-qual ' , testflags = True )
conf . ADD_CFLAGS ( ' -fno-common ' , testflags = True )
conf . ADD_CFLAGS ( ' -Werror=address ' , testflags = True )
2010-03-20 11:38:35 +03:00
# we add these here to ensure that -Wstrict-prototypes is not set during configure
2014-03-10 19:15:14 +04:00
conf . ADD_CFLAGS ( ' -Werror=strict-prototypes -Wstrict-prototypes ' ,
testflags = True )
conf . ADD_CFLAGS ( ' -Werror=write-strings -Wwrite-strings ' ,
testflags = True )
conf . ADD_CFLAGS ( ' -Werror-implicit-function-declaration ' ,
testflags = True )
2022-10-27 09:27:13 +03:00
conf . ADD_CFLAGS ( ' -Werror=implicit-int ' ,
testflags = True )
2014-03-10 19:15:14 +04:00
conf . ADD_CFLAGS ( ' -Werror=pointer-arith -Wpointer-arith ' ,
2010-03-23 20:52:23 +03:00
testflags = True )
2014-03-10 19:15:14 +04:00
conf . ADD_CFLAGS ( ' -Werror=declaration-after-statement -Wdeclaration-after-statement ' ,
testflags = True )
2014-11-07 11:36:16 +03:00
conf . ADD_CFLAGS ( ' -Werror=return-type -Wreturn-type ' ,
testflags = True )
2015-02-24 16:12:39 +03:00
conf . ADD_CFLAGS ( ' -Werror=uninitialized -Wuninitialized ' ,
testflags = True )
2017-07-26 17:29:06 +03:00
conf . ADD_CFLAGS ( ' -Wimplicit-fallthrough ' ,
testflags = True )
2018-04-05 23:33:56 +03:00
conf . ADD_CFLAGS ( ' -Werror=strict-overflow -Wstrict-overflow=2 ' ,
testflags = True )
2022-10-27 09:43:39 +03:00
conf . ADD_CFLAGS ( ' -Werror=old-style-definition -Wold-style-definition ' ,
testflags = True )
2010-03-20 11:38:35 +03:00
2014-03-10 19:15:14 +04:00
conf . ADD_CFLAGS ( ' -Wformat=2 -Wno-format-y2k ' , testflags = True )
2017-11-20 11:17:16 +03:00
conf . ADD_CFLAGS ( ' -Wno-format-zero-length ' , testflags = True )
2017-11-21 21:55:16 +03:00
conf . ADD_CFLAGS ( ' -Werror=format-security -Wformat-security ' ,
testflags = True , prereq_flags = ' -Wformat ' )
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 " ) )
2022-07-18 11:39:05 +03:00
if CHECK_CFLAGS ( conf , [ " -Wno-error=array-bounds " ] ) :
conf . define ( ' HAVE_WNO_ERROR_ARRAY_BOUNDS ' , 1 )
2023-08-22 16:52:16 +03:00
if CHECK_CFLAGS ( conf , [ " -Wno-error=stringop-overflow " ] ) :
conf . define ( ' HAVE_WNO_ERROR_STRINGOP_OVERFLOW ' , 1 )
2023-11-09 19:16:17 +03:00
if CHECK_CFLAGS ( conf , [ " -Wno-error=declaration-after-statement " ] ) :
conf . define ( ' HAVE_WNO_ERROR_DECLARATION_AFTER_STATEMENT ' , 1 )
2014-03-12 14:48:06 +04:00
if not Options . options . disable_warnings_as_errors :
conf . ADD_NAMED_CFLAGS ( ' PICKY_CFLAGS ' , ' -Werror -Wno-error=deprecated-declarations ' , testflags = True )
conf . ADD_NAMED_CFLAGS ( ' PICKY_CFLAGS ' , ' -Wno-error=tautological-compare ' , testflags = True )
2020-05-01 00:55:03 +03:00
conf . ADD_NAMED_CFLAGS ( ' PICKY_CFLAGS ' , ' -Wno-error=cast-align ' , testflags = True )
2010-04-09 13:54:40 +04:00
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
2019-05-14 02:25:07 +03:00
if ( Options . options . address_sanitizer or
Options . options . undefined_sanitizer ) :
2019-05-16 02:29:34 +03:00
conf . ADD_CFLAGS ( ' -g -O1 ' , testflags = True )
2023-02-03 15:43:16 +03:00
if ( Options . options . address_sanitizer
or Options . options . memory_sanitizer ) :
2019-05-16 02:29:34 +03:00
conf . ADD_CFLAGS ( ' -fno-omit-frame-pointer ' , testflags = True )
2023-02-03 15:43:16 +03:00
if Options . options . address_sanitizer :
2019-05-14 02:25:07 +03:00
conf . ADD_CFLAGS ( ' -fsanitize=address ' , testflags = True )
2015-01-26 18:16:15 +03:00
conf . ADD_LDFLAGS ( ' -fsanitize=address ' , testflags = True )
conf . env [ ' ADDRESS_SANITIZER ' ] = True
2019-05-14 02:25:07 +03:00
if Options . options . undefined_sanitizer :
conf . ADD_CFLAGS ( ' -fsanitize=undefined ' , testflags = True )
2019-05-16 02:29:34 +03:00
conf . ADD_CFLAGS ( ' -fsanitize=null ' , testflags = True )
conf . ADD_CFLAGS ( ' -fsanitize=alignment ' , testflags = True )
2019-05-14 02:25:07 +03:00
conf . ADD_LDFLAGS ( ' -fsanitize=undefined ' , testflags = True )
conf . env [ ' UNDEFINED_SANITIZER ' ] = True
2015-01-26 18:16:15 +03:00
2023-02-03 15:43:16 +03:00
# MemorySanitizer is only available if you build with clang
if Options . options . memory_sanitizer :
conf . ADD_CFLAGS ( ' -g -O2 ' , testflags = True )
conf . ADD_CFLAGS ( ' -fsanitize=memory ' , testflags = True )
conf . ADD_CFLAGS ( ' -fsanitize-memory-track-origins=2 ' , testflags = True )
conf . ADD_LDFLAGS ( ' -fsanitize=memory ' )
conf . env [ ' MEMORY_SANITIZER ' ] = True
2015-01-07 13:13:04 +03:00
# Let people pass an additional ADDITIONAL_{CFLAGS,LDFLAGS}
# environment variables which are only used the for final build.
#
# The CFLAGS and LDFLAGS environment variables are also
# used for the configure checks which might impact their results.
2019-11-12 07:17:02 +03:00
#
# If these variables don't pass a smoke test, fail the configure
2015-01-07 13:13:04 +03:00
conf . add_os_flags ( ' ADDITIONAL_CFLAGS ' )
2019-11-12 07:17:02 +03:00
if conf . env . ADDITIONAL_CFLAGS :
conf . CHECK_CFLAGS ( conf . env [ ' ADDITIONAL_CFLAGS ' ] ,
mandatory = True )
2015-01-07 13:13:04 +03:00
conf . env [ ' EXTRA_CFLAGS ' ] . extend ( conf . env [ ' ADDITIONAL_CFLAGS ' ] )
2019-11-12 07:17:02 +03:00
2015-01-07 13:13:04 +03:00
conf . add_os_flags ( ' ADDITIONAL_LDFLAGS ' )
2019-11-12 07:17:02 +03:00
if conf . env . ADDITIONAL_LDFLAGS :
conf . CHECK_LDFLAGS ( conf . env [ ' ADDITIONAL_LDFLAGS ' ] ,
mandatory = True )
2015-01-07 13:13:04 +03:00
conf . env [ ' EXTRA_LDFLAGS ' ] . extend ( conf . env [ ' ADDITIONAL_LDFLAGS ' ] )
2010-02-26 14:21:50 +03:00
if path is None :
2016-03-26 15:18:07 +03:00
conf . write_config_header ( ' default/config.h ' , top = True , remove = False )
2010-02-26 14:21:50 +03:00
else :
2016-03-26 15:18:07 +03:00
conf . write_config_header ( os . path . join ( conf . variant , path ) , remove = False )
for key in conf . env . define_key :
conf . undefine ( key , from_env = False )
conf . env . define_key = [ ]
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
2023-02-23 05:52:21 +03:00
def ADD_NAMED_CFLAGS ( conf , name , flags , testflags = False , prereq_flags = None ) :
2010-03-23 20:52:23 +03:00
''' add some CFLAGS to the command line
optionally set testflags to ensure all the flags work
'''
2023-02-23 05:52:21 +03:00
if prereq_flags is None :
prereq_flags = [ ]
2017-11-21 21:53:30 +03:00
prereq_flags = TO_LIST ( prereq_flags )
2010-03-23 20:52:23 +03:00
if testflags :
ok_flags = [ ]
for f in flags . split ( ) :
2017-11-21 21:53:30 +03:00
if CHECK_CFLAGS ( conf , [ f ] + prereq_flags ) :
2010-03-23 20:52:23 +03:00
ok_flags . append ( f )
flags = ok_flags
2014-02-19 18:48:34 +04:00
if not name in conf . env :
conf . env [ name ] = [ ]
conf . env [ name ] . extend ( TO_LIST ( flags ) )
@conf
2023-02-23 05:52:21 +03:00
def ADD_CFLAGS ( conf , flags , testflags = False , prereq_flags = None ) :
2014-02-19 18:48:34 +04:00
''' add some CFLAGS to the command line
optionally set testflags to ensure all the flags work
'''
2023-02-23 05:52:21 +03:00
if prereq_flags is None :
prereq_flags = [ ]
2017-11-21 21:53:30 +03:00
ADD_NAMED_CFLAGS ( conf , ' EXTRA_CFLAGS ' , flags , testflags = testflags ,
prereq_flags = prereq_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
2020-04-03 12:49:44 +03:00
def CURRENT_CFLAGS ( bld , target , cflags ,
allow_warnings = False ,
use_hostcc = False ,
hide_symbols = False ) :
2010-03-28 15:01:04 +04:00
''' work out the current flags. local flags are added first '''
2020-04-03 12:49:44 +03:00
ret = [ ]
if use_hostcc :
ret + = [ ' -D_SAMBA_HOSTCC_ ' ]
ret + = TO_LIST ( cflags )
2010-02-26 14:21:50 +03:00
if not ' EXTRA_CFLAGS ' in bld . env :
list = [ ]
else :
2023-08-29 11:47:58 +03:00
list = bld . env [ ' EXTRA_CFLAGS ' ]
2010-02-26 14:21:50 +03:00
ret . extend ( list )
2014-02-19 18:48:34 +04:00
if not allow_warnings and ' PICKY_CFLAGS ' in bld . env :
2023-08-29 11:47:58 +03:00
list = bld . env [ ' PICKY_CFLAGS ' ]
2014-02-19 18:48:34 +04:00
ret . extend ( list )
2010-04-18 06:43:15 +04:00
if hide_symbols and bld . env . HAVE_VISIBILITY_ATTR :
2015-01-07 11:58:38 +03:00
ret . append ( bld . env . VISIBILITY_CFLAGS )
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 ' ) )
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
2023-03-14 10:53:49 +03:00
# not look into system includes. This roughly matches what
2010-03-21 23:48:10 +03:00
# autoconf does with -C
2018-01-31 12:48:43 +03:00
cache_path = os . path . join ( conf . bldnode . abspath ( ) , ' .confcache ' )
2010-03-21 23:48:10 +03:00
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 ) :
2023-02-03 15:43:16 +03:00
if ( Options . options . address_sanitizer
or Options . options . memory_sanitizer
or Options . options . enable_libfuzzer ) :
2019-04-04 01:23:07 +03:00
# Sanitizers can rely on symbols undefined at library link time and the
# symbols used for fuzzers are only defined by compiler wrappers.
return
2013-05-17 12:43:08 +04:00
if not sys . platform . startswith ( " openbsd " ) :
2019-03-23 02:14:52 +03:00
# we don't want any libraries or modules to rely on runtime
# resolution of symbols
2011-11-13 21:01:09 +04:00
conf . env . undefined_ldflags = conf . ADD_LDFLAGS ( ' -Wl,-no-undefined ' , testflags = True )
2019-03-23 02:14:52 +03:00
if ( conf . env . undefined_ignore_ldflags == [ ] and
conf . CHECK_LDFLAGS ( [ ' -undefined ' , ' dynamic_lookup ' ] ) ) :
2011-11-13 21:01:09 +04:00
conf . env . undefined_ignore_ldflags = [ ' -undefined ' , ' dynamic_lookup ' ]