U
    WÄ±b&  ã                   @   sp   d dl Z d dlmZ d dlZd dlZd dlmZ e e 	e
¡¡Zdd„ Zdd„ Zeddd	„ƒZedd
d„ƒZdS )é    N)Úconfc                 C   s   | j dd dd� d S )Nz--with-rootz+Look for CERN ROOT System at the given path)ÚdefaultÚhelp)Ú
add_option)Úopt© r   ú./home/yuhw/wc/wire-cell/waf-tools/find_root.pyÚoptions
   s    ÿr	   c                 C   sÔ   | j  jdg7  _tƒ }t| jdd ƒt dd ¡fD ]}|r2| t 	|d¡¡ q2t
|d�}| jdddi|—Ž | j| j d dd	d
d� | jdd|d� | jdd|d� | jdd|dd� | j  jdddddg7  _d S )Nz-fPICZ	with_rootÚROOTSYSÚbin)Ú	path_listúroot-configÚvarzROOT-CONFIGz--cflags --libs --ldflagsÚ )ÚpathÚuselib_storeÚargsÚpackageZ	rootclingZ	ROOTCLING)r   r   ZrootcintZROOTCINTZrlibmapZRLIBMAPF)r   r   Ú	mandatoryZMinuit2Z
TreePlayerZSpectrumZTMVAZTMVAGui)r   )ÚenvÚCXXFLAGSÚlistÚgetattrr	   ÚosÚgetenvÚappendÚospÚjoinÚdictÚfind_programÚ	check_cfgZLIB_ROOTSYS)Úcfgr   ZtopdirÚkwargsr   r   r   Ú	configure   s     
 ÿr#   r   c                 C   sD  t j |¡dg }t j |¡}|D ]*}| jd|  }t|tƒsD|g}||7 }q"tƒ }|D ]>}	|	 d¡rpd|	 }
nd| j |	¡ 	¡  }
|
|krX| 
|
¡ qXd |¡}|d }d| d }d| d	 }|d
 }t|ƒtdƒkræ| j |¡}||g }d dd„ |D ƒ¡}d|||f }| ||||g||d� |  d|¡ |  d|¡ dS )zn
    rootcling -f NAMEDict.cxx -rml libNAME.so -rmf libNAME.rootmap myHeader1.h myHeader2.h ... LinkDef.h
    r
   Ú	INCLUDES_ú/ú-I%sú úDict.cxxÚlibz.soz.rootmapzDict_rdict.pcmr   c                 S   s   g | ]}|  ¡ ‘qS r   )Úabspath©Ú.0Úxr   r   r   Ú
<listcomp>J   s     z&gen_rootcling_dict.<locals>.<listcomp>zm${ROOTCLING} -f ${TGT[0].abspath()} -noIncludePaths -inlineInputHeader -rml %s -rmf ${TGT[1].abspath()} %s %s)ÚsourceÚtargetÚruleÚuseú${PREFIX}/lib64/N)ÚwaflibÚUtilsÚto_listr   Ú
isinstancer   Ú
startswithr   Úfind_dirr*   r   r   ÚtypeÚfind_resourceÚinstall_files)ÚbldÚnameÚlinkdefÚheadersÚincludesr2   ÚuÚmoreÚincsÚincZnewincÚdict_srcZdict_libZdict_mapZdict_pcmZsource_nodesZsourcesr1   r   r   r   Úgen_rootcling_dict$   s>    





 þ	rG   c                    s–   t j |¡}‡ fdd„t j |¡D ƒ}d |¡}|d }ˆ ||g |d| d� ˆ j||d |dd	� d
| }ˆ |g|d||f d� ˆ  d|¡ dS )zqGenerate a rootcint dictionary, compile it to a shared lib,
    produce its rootmap file and install it all.
    c                    s    g | ]}d ˆ j  |¡ ¡  ‘qS )r&   )r   r9   r*   r+   ©r=   r   r   r.   a   s     z%gen_rootcint_dict.<locals>.<listcomp>r'   r(   z"${ROOTCINT} -f ${TGT} -c %s ${SRC})r/   r0   r1   ZDictr
   )r/   r0   rA   r2   zlib%sDict.rootmapz:${RLIBMAP} -o ${TGT} -l lib%sDict.so -d lib%s.so -c ${SRC}r3   N)r4   r5   r6   r   Úshlibr<   )r=   r>   r?   r@   rA   rD   rF   Zrootmapr   rH   r   Úgen_rootcint_dict[   s$    

þý
ÿrJ   )r   r   r   )r   r   )r   Zos.pathr   r   r4   Zwaflib.UtilsZwaflib.Configurer   Údirnamer*   Ú__file__Ú_tooldirr	   r#   rG   rJ   r   r   r   r   Ú<module>   s   6