a
    	$a;                     @   s  d dl Z d dlZd dlmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZmZmZmZ e ZedXdd	ZdYd
dZedd Zedd Ze
ddd ZdZddZed[ddZd\ddZed]ddZed^ddZed_ddZ ed`ddZ!edad d!Z"dbd#d$Z#edcd%d&Z$eddd'd(Z%eded)d*Z&edfd-d.Z'edgd/d0Z(edhd2d3Z)edid4d5Z*ed6d7 Z+ed8d9 Z,ed:d; Z-e-ej._-e,ej._,e+ej._+d<d= Z/edjd>d?Z0edkd@dAZ1edBdC Z2e2ej3_2edldDdEZ4edFdG Z5edg fdHdIZ6edg fdJdKZ7edmdLdMZ8edNdO Z9dndPdQZ:edRdS Z;edTdU Z<edVdW Z=dS )o    N)BuildOptionsLogsContextconf)feature)	c_preproc)TO_LISTGET_TARGET_TYPESET_TARGET_TYPEunique_listmkdir_pFc                 C   s2   | j |||d |r.| jdd|t|f  dS )zdefine a config optionquoteCFLAGSz-D%s=%sN)defineenvappend_valuestr)r   dvadd_to_cflagsr    r   o/home/jack/SDK/ZBT-AX3000-OpenWrt-21.02/build_dir/hostpkg/samba-4.14.12/./buildtools/wafsamba/samba_autoconf.pyDEFINE   s    r   c                 C   s>   | j j}|r&|dd }|t| ddd |D }|S )z1convert a headers list to a set of #include linesN
c                 s   s   | ]}d | V  qdS )z#include <%s>Nr   ).0hr   r   r   	<genexpr>       z"hlist_to_string.<locals>.<genexpr>)r   hlistextendr
   join)r   headersr!   hdrsr   r   r   hlist_to_string   s    r&   c                 C   sp   dd }dd }t | jdg }|g kr>|dkr>|d | j_dS | | | j| _|| _| j| _|| _d| j_dS )	start a compound testc                 _   s   d S Nr   selfkkwr   r   r   null_check_message_1&   s    z,COMPOUND_START.<locals>.null_check_message_1c                 _   s   d S r(   r   r)   r   r   r   null_check_message_2(   s    z,COMPOUND_START.<locals>.null_check_message_2in_compoundr      N)getattrr   r/   	start_msgsaved_check_message_1end_msgsaved_check_message_2)r   msgr-   r.   r   r   r   r   COMPOUND_START#   s    
r7   c                 C   sd   | j  jd8  _| j jdkr dS | j| _| j| _| j}|du rH|d n|sX|dd n|| dS )r'   r0   r   NTokz	not foundYELLOW)r   r/   r3   r2   r5   r4   )r   resultpr   r   r   COMPOUND_END7   s    
r<   nolinkc                 C   s   dS )zusing 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 neededNr   )r*   r   r   r   r=   H   s    c           
   
   C   s   |t v r|du rdS | dd}|dd}|dd}d| }t| |rp|rl|| jjvrl| jj| dS t| |\}}}t| |d	}|du rd
}| j	d| dd|d|| d| d}	|	st 
| dS | |d |r|| jjvr| jj| |	S )zcheck for a headerNF/_.-HAVE_%sTr$    z %s
int main(void) { return 0; }
r=   r   zChecking for header %s)fragmenttypeexecutecflags	mandatoryincludesuselibr6   r0   )missing_headersupperreplace
CONFIG_SETr   r!   appendlibrary_flagsr&   checkaddr   )
r   r   add_headerslibr   ccflagsldflagscpppathr%   retr   r   r   CHECK_HEADERP   s>    


rZ   c           	      C   s\   d}|s"|r"| j jdd }d}n|}t|D ]}t| |||ds.d}q.|sX|rX|| j _|S )zcheck for a list of headers

    when together==True, then the headers accumulate within this test.
    This is useful for interdependent headers
    TN)rU   F)r   r!   r
   rZ   )	r   r$   rT   ZtogetherrU   rY   Zsaved_hlistZset_add_headersZhdrr   r   r   CHECK_HEADERSu   s    r[   c                 C   s@   g }|dur4t |D ]}t| |d|dr|| qt| |dS )z/form a list of headers which exist, as a stringNF)rT   rU   rC   )r
   rZ   rP   r&   )r   r$   rU   r!   r   r   r   r   header_list   s    r\   c                 C   sb   |du rd|  dd }|du r,d| }t| d| |d|d||dd	}|s^|r^| || |S )	zcheck for a single typeNZHAVE_ r?   Checking for %sz%s _xF)rG   r$   local_includer6   rU   link)rM   rN   
CHECK_CODEr   )r   t	alternater$   r   rU   r6   rY   r   r   r   
CHECK_TYPE   s     
rd   c              	   C   s.   d}t |D ]}t| |||||dsd}q|S )zcheck for a list of typesT)r$   r   rc   rU   F)r
   rd   )r   listr$   r   rc   rU   rY   rb   r   r   r   CHECK_TYPES   s    rf   c                 C   s   t | ||||dS )z%check for a single type with a header)r$   rc   r   )rd   )r   rb   r$   rc   r   r   r   r   CHECK_TYPE_IN   s    rg   c                 C   sH   |du rd|   }|du r$d| }t| d||f dd|d||||d
S )z,check for a variable declaration (or define)NrB   zChecking for variable %sz
                      #ifndef %s
                      void *_x; _x=(void *)&%s; return (int)_x;
                      #endif
                      return 0
                      F)rG   r`   r6   r_   rU   r$   r   alwaysrM   ra   )r   r   r   rh   r$   r6   rU   r   r   r   CHECK_VARIABLE   s"    rj   c                 C   sr   d}t |D ]`}|s"d|  }nd|  }t| |||d| |dst| d| ddd| d|||d		sd}q|S )
zcheck a list of variable declarations, using the HAVE_DECL_xxx form
       of define

       When reverse==True then use HAVE_xxx_DECL instead of HAVE_DECL_xxx
       TzHAVE_DECL_%szHAVE_%s_DECLChecking for declaration of %s)r   r$   r6   rh   z=
                      return (int)%s;
                      Fz(Checking for declaration of %s (as enum))rG   r`   r6   r_   r$   r   rh   )r
   rM   rj   ra   )r   varsreverser$   rh   rY   r   r   r   r   r   CHECK_DECLS   s2    rn   Tc                 C   s   d|   }d}d}|r d| }| d||f  |du s>|rt| d|||||||f dddd|d||d	| d
}|st| d| dddd|d||d| d
}|s|du s|st| |||d| d}| | |S )zcheck for a functionrB   FrD   z in %szChecking for %s%sNa,  
                         #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"
                         #endif
                         extern char %s();
                         int main() { return %s(); }
                         Tr^   )	rG   r`   addmainrT   r   r_   rU   r$   r6   z'void *__x = (void *)%s; return (int)__xzChecking for macro %srk   )r   r$   r6   )rM   r7   ra   rj   r<   )r   fr`   rU   r$   r   rY   Z
in_lib_strr   r   r   
CHECK_FUNC   sT    
rq   c                 C   s,   d}t |D ]}t| ||||dsd}q|S )zcheck for a list of functionsT)r`   rU   r$   F)r
   rq   )r   re   r`   rU   r$   rY   rp   r   r   r   CHECK_FUNCS6  s
    rr   c           	      C   s   t |D ]}|}d}|du r0d| dd }tdD ]>}t| d||f |d|dd||f d	r8| || d
} qxq8|s|rtd|  t	d q|S )zcheck the size of a typeFNz	SIZEOF_%sr]   r?   )r0                   @   zAstatic int test_array[1 - 2 * !(((long int)(sizeof(%s))) <= %d)];zChecking if size of %s == %d)r   r   r$   r_   r6   TzCouldn't determine size of '%s'r0   )
r
   rM   rN   re   ra   r   r   errorsysexit)	r   rl   r$   r   criticalr   v_definerY   sizer   r   r   CHECK_SIZEOF@  s*    

r   c                 C   sX   d}|}|du r$d|  dd }t| d| |ddd|dd| d		rTt| j| S dS )
z$check the value of a variable/defineTNz
VALUEOF_%sr]   r?   zprintf("%%u", (unsigned)(%s))FzChecking value of %s)r   rG   
define_retr   r$   r_   r6   )rM   rN   ra   intr   )r   r   r$   r   rY   r}   r   r   r   CHECK_VALUEOFX  s     	r   rD   # .c                 C   s  t | |rdS |dur$t| ||d |r8t| ||d}nd}|rFd}nd}|r\d||f }nd||f }|	du rxd	| }	t|
}
|rd
| jv r|
| jd
  |r|
d| j   |sd}nd}t|}t	| |\}}}t|}|| dd |D }|
| |r| j
|	d}ng }| |	 z&| j||||
|||||	|||d}W nF ty   |rr| |d n
| | | d |r Y dS 0 |s| | | d dS |s| |d | d n| j|||d | | dS dS )z'check if some code compiles and/or runsTN)r$   rU   rD   r0   r   z%%s
 int main(void) { %s; return 0; }
z%s
%s
r^   WERROR_CFLAGSz-I%sr=   cprogramc                 S   s   g | ]}|  qS r   )rM   )r   lr   r   r   
<listcomp>  r    zCHECK_CODE.<locals>.<listcomp>)r6   )rE   rG   define_namerH   rW   rJ   rK   rF   r6   r   	test_argsr   Fr   )rO   r[   r\   r
   r   r"   rP   pathabspathrQ   ZSAMBA_CROSS_ARGSr7   rR   	Exceptionr   undefiner<   )r   coder   rh   rG   ro   rT   rI   r$   r6   rH   rJ   r_   rU   r`   r   r   	on_targetstrictr%   rE   rF   rK   rV   rW   rX   r   rY   r   r   r   ra   l  s    











ra   c                 C   s@   |du rd|   }t| d||f |dd|||dd||f d
S )zcheck for a structure memberNrB   z %s s; void *_x; _x=(void *)&s.%sFzChecking for member %s in %s)rG   r`   rU   rh   r$   r_   r6   ri   )r   Z
structnamememberrh   r   r$   rU   r   r   r   CHECK_STRUCTURE_MEMBER  s    

r   int main(void) { return 0; }
c                 C   s<   t |}d| jv r"|| jd  | j|d|d|d| dS )z;check if the given cflags are accepted by the compiler
    r   r   r=   zChecking compiler accepts %s)rE   rG   rI   rF   rH   r6   )r
   r   r"   rR   )r   rH   rE   rI   Zcheck_cflagsr   r   r   CHECK_CFLAGS  s    
r   c                 C   s   | j dd||d| dS )z:check if the given ldflags are accepted by the linker
    r   r   zChecking linker accepts %s)rE   rG   rW   rI   r6   )rR   )r   rW   rI   r   r   r   CHECK_LDFLAGS  s    r   c                 C   s   || j v r| j | S dS dS )/return True if a configuration option was foundNr   r   optionr   r   r   
CONFIG_GET  s    

r   c                 C   s@   || j vrdS | j | }|du r$dS |g kr0dS |dkr<dS dS )r   FNr   Tr   )r   r   r   r   r   r   rO     s    

rO   c                 C   s   || j vrd S | j |= d S r(   r   r   r   r   r   CONFIG_RESET  s    
r   c           	      C   s   g }g }g }t |D ]}t t| jd|  g }t t| jd|  g }t t| jd|  g }|| || || t t| jd|  g }|| qd| jv r|| jd  t|}t|}t|}|||fS )zwork out flags from pkg_configz	CFLAGS_%sz
LDFLAGS_%sz
CPPPATH_%szINCLUDES_%sEXTRA_LDFLAGS)r
   r1   r   rM   r"   r   )	r*   libsrV   rW   rX   rU   Zextra_ccflagsZextra_ldflagsZextra_cpppathr   r   r   rQ   %  s$    



rQ   c                 C   s  d}g }t |}|dd D ]}	t| |	dkr:||	 qt| |	\}
}}|rn| jd||	|	|
||	 dd}n| j|	|	|
||	 dd}|s|rtd|	tf  t	
d	 |r|rt| |	d
 q| d|	 dddd d	 |	| jd|	  < |r
| |	d ||	 q|S )z{check if a set of libraries exist as system libraries

    returns the sublist of libs that do exist as a syslib or []
    z.
int foo()
{
    int v = 2;
    return v*2;
}
NSYSLIBzc cshlibF)featuresrE   rU   uselib_storerH   rW   rK   rI   )rU   r   rH   rW   rK   rI   3Mandatory library '%s' not found for functions '%s'r0   EMPTYz
HAVE_LIB%srA   r?   r@   ZLIB_)r
   r   rP   rQ   rR   rM   r   ry   re   rz   r{   r   r   rN   r   )r   r   rI   
empty_decl
set_targetshlibrE   rY   liblistrU   rV   rW   rX   resr   r   r   	CHECK_LIB@  s0    
 
$r   c	                 C   s  t |}	t |}
|	dd D ] }t| d|  r|	| q|rn|	dd D ]}t| |d|drN|	| qN|	g kr|
D ]"}t| |dkrz|rzt| |d qzdS | j|
||d}|
dd D ],}||vr|rt	d||f  t
d	 qd}|	D ] }t| |d
|||dsd}q|S )a  
    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
    NrB   T)r`   r$   r   r   )r   r   r   r0   r]   )rU   r$   r`   F)r
   rO   rM   removerq   r   r   r   r   ry   rz   r{   r#   )r   re   ZlibraryrI   Z	checklibcr$   r`   r   r   	remainingr   rp   rU   Z	checklistrY   r   r   r   CHECK_FUNCS_INn  s0    r   c                 C   s    t j| j t jtjkS )z?return True if this rule is being run from the launch directory)osr   realpathr   r   
launch_dirr   r   r   r   IN_LAUNCH_DIR  s    r   c                 C   s2  t | sdS ddg}|D ]8}| jdddd|gdd	| d
}|r| d|   qRq| jddddgddd
}|rx| d tjjr| jddd tjjrd| j_tjj	rrd| j_
| jddd | jddd | jddd | jddd t| ddddddr| jddd | jddd | jddd | jddd | jddd | jddd | jd dd | jd!dd | jd"dd | jd#dd | jd$dd | jd%dd | jd&dd | jd'dd | jd(dd | jd)dd | jd*dd | jd+dd,d- t| d.d/gd0r8d1| jvr$g | jd1< | jd1 td. tjjsr| jd2d3dd | jd2d4dd | jd2d5dd tjjr| jd6dd tjjr| jd7dd tjjstjjr| jd8dd tjjr| jd9dd | jd:dd | jd:dd d| jd;< tjjrN| jd<dd | jd=dd | jd>dd | jd<dd d| jd?< | d@ | jjr| j| jd@ ddA | jd1 | jd@  | dB | jjr| j| jdB ddA | jdC | jdB  |du r| jdDdddE n| jtj| j|ddF | jjD ]}| j |ddG qg | j_| !  dS )Hz)write out config.h in the right directoryNz-fstack-protector-strongz-fstack-protectora  
                                    #include <stdio.h>

                                    int main(void)
                                    {
                                        char t[100000];
                                        while (fgets(t, sizeof(t), stdin));
                                        return 0;
                                    }
                                    r   z-Werrorz-Wp,-D_FORTIFY_SOURCE=2FzChecking if compiler accepts %s)rE   rG   rH   rI   r6   z%sar  
                                #include <stdio.h>

                                int main(void)
                                {
                                    char t[100000];
                                    while (fgets(t, sizeof(t), stdin));
                                    return 0;
                                }
                                z-fstack-clash-protectionz5Checking if compiler accepts -fstack-clash-protectionz-gT	testflagsz-Wallz-Wshadowz-Wmissing-prototypesz6struct a { int b; }; struct c { struct a d; } e = { };ZCHECK_C99_INITz?-Wmissing-field-initializers -Werror=missing-field-initializersz$Checking C99 init of nested structs.)r`   rH   r6   z-Wmissing-field-initializersz-Wformat-overflow=2z-Wformat-zero-lengthz-Wcast-align -Wcast-qualz-fno-commonz-Werror=addressz--Werror=strict-prototypes -Wstrict-prototypesz%-Werror=write-strings -Wwrite-stringsz%-Werror-implicit-function-declarationz%-Werror=pointer-arith -Wpointer-arithzA-Werror=declaration-after-statement -Wdeclaration-after-statementz!-Werror=return-type -Wreturn-typez%-Werror=uninitialized -Wuninitializedz-Wimplicit-fallthroughz+-Werror=strict-overflow -Wstrict-overflow=2z-Wformat=2 -Wno-format-y2kz-Wno-format-zero-lengthz)-Werror=format-security -Wformat-securityz-Wformatr   prereq_flagsz-Werror=formatz
-Wformat=2z
int testformat(char *format, ...) __attribute__ ((format (__printf__, 1, 2)));

int main(void) {
        testformat(0);
        return 0;
}

EXTRA_CFLAGSPICKY_CFLAGSz*-Werror -Wno-error=deprecated-declarationsz-Wno-error=tautological-comparez-Wno-error=cast-alignz-Wfatal-errorsz-Wz-g -O1z-fno-omit-frame-pointerz-fsanitize=addressZADDRESS_SANITIZERz-fsanitize=undefinedz-fsanitize=nullz-fsanitize=alignmentZUNDEFINED_SANITIZERADDITIONAL_CFLAGS)rI   ADDITIONAL_LDFLAGSr   zdefault/config.h)topr   )r   )Zfrom_env)"r   rR   
ADD_CFLAGSr   optionsdebugZpidl_developerr   ZPIDL_DEVELOPER_MODE	developerZDEVELOPER_MODEra   r   r"   r
   Zdisable_warnings_as_errorsADD_NAMED_CFLAGSZfatal_errorsZpedanticaddress_sanitizerZundefined_sanitizerADD_LDFLAGSadd_os_flagsr   r   r   write_config_headerr   r   r#   variant
define_keyr   ZSAMBA_CROSS_CHECK_COMPLETE)r   r   Zstack_protect_listZstack_protect_flagZflag_supportedkeyr   r   r   SAMBA_CONFIG_H  s    



	













r   c                 C   s:   || j vr6|d dkr"|| j |< n| j d | | j |< dS )zsetup a configurable pathr   r>   PREFIXNr   )r   namedefaultr   r   r   CONFIG_PATHO  s    
r   c                 C   sh   t |}|r<g }| D ]}t| |g| r|| q|}|| jvrPg | j|< | j| t | dS )eadd some CFLAGS to the command line
       optionally set testflags to ensure all the flags work
    N)r
   splitr   rP   r   r"   )r   r   flagsr   r   ok_flagsrp   r   r   r   r   X  s    

r   c                 C   s   t | d|||d dS )r   r   r   N)r   )r   r   r   r   r   r   r   r   h  s    
r   c                 C   sZ   |r.g }|  D ]}t| |r|| q|}d| jvrBg | jd< | jd t| |S )zadd some LDFLAGS to the command line
       optionally set testflags to ensure all the flags work

       this will return the flags that are added, if any
    r   )r   r   rP   r   r"   r
   )r   r   r   r   rp   r   r   r   r   p  s    


r   c                 C   s,   d| j vrg | j d< | j d t| dS )z0add some extra include directories to all buildsZEXTRA_INCLUDESN)r   r"   r
   )r   rJ   r   r   r   ADD_EXTRA_INCLUDES  s    

r   c                 C   sl   t |}d| jvrg }n
| jd }|| |sNd| jv rN| jd }|| |rh| jjrh|| jj |S )z7work out the current flags. local flags are added firstr   r   )r
   r   r"   ZHAVE_VISIBILITY_ATTRrP   ZVISIBILITY_CFLAGS)bldtargetrH   allow_warningshide_symbolsrY   re   r   r   r   CURRENT_CFLAGS  s    




r   c                 C   s$   t jdr tt jd| j_dS )zRtrim whitespaces from 'CC'.
    The build farm sometimes puts a space at the startCCN)r   environgetr
   r   r   r   r   r   r   CHECK_CC_ENV  s    r   c                 C   sR   |r2t j| j d}t| | t_t jd< nd t_t jd< dt	_
dt	_dS )z)enable/disable cache of configure resultsz
.confcacheZWAFCACHErD   r0   FN)r   r   r#   bldnoder   r   r   Zcache_globalr   preprocrecursion_limitgo_absolute)r   enable
cache_pathr   r   r   SETUP_CONFIGURE_CACHE  s    r   c                 C   s\   t jjst jjrd S tjdsX| jddd| j_	| jj
g krX| ddgrXddg| j_
d S )Nopenbsdz-Wl,-no-undefinedTr   z
-undefineddynamic_lookup)r   r   r   Zenable_libfuzzerrz   platform
startswithr   r   Zundefined_ldflagsZundefined_ignore_ldflagsr   r   r   r   r   "SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS  s    r   )FF)N)FN)FFN)NN)NNNNN)NNNN)NNN)NFNNN)FNF)TNN)TNN)NNT)NN)FFTTFNNrD   r   TNTFFTF)FNNN)r   F)F)FTTF)FFNTTT)N)F)FF)>r   rz   waflibr   r   r   r   waflib.Configurer   waflib.TaskGenr   waflib.Toolsr	   r   samba_utilsr
   r   r   r   r   setrL   r   r&   r7   r<   r=   rZ   r[   r\   rd   rf   rg   rj   rn   rq   rr   r   r   ra   r   r   r   r   rO   r   BuildContextrQ   r   r   r   OptionsContextr   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   




%


   
?	      i     


-  1
 (




