U
    úá)fÛ  ã                   @   sŠ   d dl Z d dlmZ d dlZd dlZd dlmZ d dlm	Z	 e 
e e¡¡Zdd„ Zeddd„ƒZd	d
„ Zeddd„ƒZeddd„ƒZdS )é    N)Úconf)Údebugc                 C   s   |   d¡} | jdd dd� d S )NzROOT Optionsz--with-rootzgive ROOT installation location)ÚdefaultÚhelp)Úadd_option_groupÚ
add_option)Úopt© r	   ú:/home/yuhw/wc/larsoft925/src/wire-cell-dev/waft/rootsys.pyÚoptions   s
    
ÿr   Fc                 C   s   | j j}|r0| ¡ dkr0|r$tdƒ‚tdƒ d S | j jdg7  _tƒ }t| j dd ƒt	 
dd ¡fD ]}|rb| t |d¡¡ qbt|d�}| jdd
|dœ|—Ž d
| jkrÀ|r´tdƒ‚tdƒ d S | j| jd
 ddd|d� | jdd||d� | jdd|d� d S )N)ÚnoÚoffÚfalsez/ROOT is mandatory but disabled via command linez7root: optional ROOT dependency disabled by command linez-fPICÚ	with_rootÚROOTSYSÚbin)Ú	path_listúroot-configZROOT_CONFIG)ÚvarÚ	mandatoryz'root-config not found but ROOT requiredz;root: skipping non mandatory ROOT, use --with-root to forcez--cflags --libs --ldflagsÚ )ÚpathÚuselib_storeÚargsÚpackager   Z	rootclingZ	ROOTCLING)r   r   r   zRtypes.h)Úheader_nameÚuser   )r   )r   r   ÚlowerÚRuntimeErrorr   ÚenvÚCXXFLAGSÚlistÚgetattrÚosÚgetenvÚappendÚospÚjoinÚdictÚfind_programÚ	check_cfgÚ	check_cxx)Úcfgr   Úinstdirr   ZtopdirÚkwargsr	   r	   r
   Ú
check_root   s8    

  ÿÿr/   c                 C   s   |   ¡  d S )N)r/   )r,   r	   r	   r
   Ú	configure9   s    r0   r   c                 C   sZ  t j |¡dg }t j |¡}|D ],}| jd|  }td|||f ƒ ||7 }q"tƒ }|D ]>}	|	 d¡rrd|	 }
nd| j |	¡ 	¡  }
|
|krZ| 
|
¡ qZd |¡}td|t|ƒf ƒ |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_zroot: USE(%s)=%s: %sú/ú-I%sú zroot: INCS(%s): %súDict.cxxÚlibz.soz.rootmapzDict_rdict.pcmr   c                 S   s   g | ]}|  ¡ ‘qS r	   )Úabspath©Ú.0Úxr	   r	   r
   Ú
<listcomp>_   s     z&gen_rootcling_dict.<locals>.<listcomp>zJ${ROOTCLING} -f ${TGT[0].abspath()} -rml %s -rmf ${TGT[1].abspath()} %s %s)ÚsourceÚtargetÚruler   ú${PREFIX}/lib/N)ÚwaflibÚUtilsÚto_listr   r   r!   Ú
startswithr   Úfind_dirr7   r%   r'   ÚstrÚtypeÚfind_resourceÚinstall_files)ÚbldÚnameÚlinkdefÚheadersÚincludesr   ÚuÚmoreÚincsÚincZnewincÚdict_srcZdict_libZdict_mapZdict_pcmZsource_nodesZsourcesr>   r	   r	   r
   Úgen_rootcling_dict<   s>    




 þ	rS   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 )r3   )r   rD   r7   r8   ©rI   r	   r
   r;   t   s     z%gen_rootcint_dict.<locals>.<listcomp>r4   r5   z"${ROOTCINT} -f ${TGT} -c %s ${SRC})r<   r=   r>   ZDictr   )r<   r=   rM   r   zlib%sDict.rootmapz:${RLIBMAP} -o ${TGT} -l lib%sDict.so -d lib%s.so -c ${SRC}r?   N)r@   rA   rB   r'   ÚshlibrH   )rI   rJ   rK   rL   rM   rP   rR   Zrootmapr	   rT   r
   Úgen_rootcint_dictn   s$    

þý
ÿrV   )F)r   r   r   )r   r   )r#   Zos.pathr   r&   r@   Zwaflib.UtilsZwaflib.Configurer   Zwaflib.Logsr   Údirnamer7   Ú__file__Ú_tooldirr   r/   r0   rS   rV   r	   r	   r	   r
   Ú<module>   s   '1