a
    	”$aÙ  ã                   @   s”   d dl Z d dlZ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„ Ze dejejB ¡Zi Zdd„ Zd	d
„ Zddd„Zddd„Zeej_dS )é    N)ÚBuildÚLogsÚUtilsÚErrors)ÚTO_LISTc                 C   sN   |sdS t |tƒs|S |D ].\}}t|ƒD ]}t | |¡r*|    S q*qdS )zCfind the installation path for a header, given a header_path optionÚ )Ú
isinstanceÚlistr   Úfnmatch)ÚheaderÚheader_pathÚp1ÚdirÚp2© r   ún/home/jack/SDK/ZBT-AX3000-OpenWrt-21.02/build_dir/hostpkg/samba-4.14.12/./buildtools/wafsamba/samba_headers.pyÚheader_install_path   s    
r   z^\s*#\s*include[ 	]*"([^"]+)"c                 C   sN   t j | ¡}g }tD ]4}t j |¡|kr| dt|  ¡ | d| ¡ q|S )z#find a suggested header path to usez<%s>z"%s")ÚosÚpathÚbasenameÚ
header_mapÚappend)ÚhpathÚbaseÚretÚhr   r   r   Úfind_suggested_header   s    r   c              	   C   s4  | j d  | j¡}| jd  | j¡}tj |¡r:t |¡ tj 	|| jj
¡}t|dd}t|dd}d}d| jjg}| jjD ] }| d¡r|| |dd… ¡ q||D ]z}	|d7 }| jjrä|	 ¡ | jjv rä| | jj|	 ¡  d	 ¡ q¢t |	¡}
|
du r| |	¡ q¢|
 d¡}| d
¡r&|dd… }| jjrJ|| jjv rJ| |	¡ q¢d}|D ]B}tj tj ||¡¡}|tv rR| dt|  ¡ d} q–qR|ržq¢| jjrÆt d||f ¡ | |	¡ q¢t|ƒ}| ¡  t |¡ tj  dtj 	|t !¡ ¡|||f ¡ t" #d||| jjf ¡‚q¢| ¡  | ¡  dS )zGcreate a public header from a private one, output within the build treer   Úr)ÚmodeÚwr   ú#é   NÚ
zbin/default/é   Fz#include <%s>
Tz)Broken public header include '%s' in '%s'zF%s:%u:Error: unable to resolve public header %s (maybe try one of %s)
zHUnable to resolve header path '%s' in public header '%s' in directory %s)$ÚinputsÚabspathÚenvÚoutputsÚbldpathr   r   ÚexistsÚunlinkÚrelpathÚTOPDIRÚopenÚRELPATHÚEXTRA_INCLUDESÚ
startswithr   Zpublic_headers_replaceÚstripÚwriteÚ	re_headerÚmatchÚgroupZpublic_headers_skipÚnormpathÚjoinr   Zpublic_headers_allow_brokenr   Úwarnr   ÚcloseÚsysÚstderrÚgetcwdr   ÚWafError)ÚtaskÚsrcÚtgtZrelsrcÚinfileZoutfileZ
linenumberZsearch_pathsÚiÚlineÚmr   ÚfoundÚsÚpZ	suggestedr   r   r   Úcreate_public_header%   sf    












ÿ
ÿ
rH   Tc           	      C   sn   |sdS t |ƒD ]X}t||ƒ}| d¡dkrH| d¡}|d }|d }n|}tj |¡}| jd||d qdS )z=install some headers - simple version, no munging needed
    Nú:éÿÿÿÿr   r!   ú${INCLUDEDIR})Údestname)r   r   ÚfindÚsplitr   r   r   ÚINSTALL_FILES)	ÚbldÚpublic_headersr   Úpublic_headers_installr   Ú	inst_pathrF   Úh_nameÚ	inst_namer   r   r   Úpublic_headers_simplel   s    


rV   c                 C   s´  |   d¡ | jjs&t| |||d dS t|ƒD ]~}t||ƒ}| d¡dkrh| d¡}|d }|d }n|}tj	 
|¡}| j	 ¡ }	tj	 | j ¡ |	¡}
tj	 |	| j ¡ ¡}tj	 tj	 |
| jj|¡¡}tj	 tj	 |	|¡¡sît d||f ¡‚tj	 ||¡}tj	 tj	 ||¡¡}tj	 tj	 ||¡¡}|t|< | jd	|||f d
t||d}||j_| j ¡ |j_| jjsvg | j_| jj tj	 ||¡¡ |r.| jd|tj	 ||¡dd q.dS )zÕinstall some headers

    header_path may either be a string that is added to the INCLUDEDIR,
    or it can be a dictionary of wildcard patterns which map to destination
    directories relative to INCLUDEDIR
    Úfinal)r   rR   NrI   rJ   r   r!   z0missing source directory %s for public header %szHEADER_%s/%s/%sÚheaders)r5   ÚruleÚsourceÚtargetrK   T)rL   Úflat)ÚSET_BUILD_GROUPr&   Zbuild_public_headersrV   r   r   rM   rN   r   r   r   r%   r+   Úsrcnoder6   r7   r)   r   r=   r   ÚSAMBA_GENERATORrH   r.   r,   Zpublic_headers_listr   rO   )rP   rQ   r   rR   r   rS   rF   rT   rU   ÚcurdirZrelpath1Zrelpath2Z	targetdirr[   Zsrc_pathZtarget_pathÚtr   r   r   ÚPUBLIC_HEADERS}   sP    
ÿ



ü
þrb   )NT)NT)r   Úrer:   r
   Úwaflibr   r   r   r   Úsamba_utilsr   r   ÚcompileÚIÚMr3   r   r   rH   rV   rb   ÚBuildContextr   r   r   r   Ú<module>   s    
G

8