U
    úá)f-  ã                   @   s<   d Z ddlZddlmZ ddlmZ d
dd„Zddd	„ZdS )aã  
This is NOT a waf tool but generic functions to be called from a waf
tool, in particular by wcb.py.

There's probably a wafier way to do this.

The interpretation of options are very specific so don't change them
unless you really know all the use cases.  The rules are:

If package is optional:

    - omitting all --with-NAME* options will omit use the package

    - explicitly using --with-NAME=false (or "no" or "off") will omit
      use of the package.

If package is mandatory:

    - omitting all --with-NAME* options will use pkg-config to find
      the package.

    - explicitly using --with-NAME=false (or "no" or "off") will
      assert.

In either case:

    - explicitly using --with-NAME=true (or "yes" or "on") will use
      pkg-config to find the package.

    - using --with-NAME* with a path will attempt to locate the
      package without using pkg-config

Note, actually, pgk-config fails often to do its job.  Best to always
use explicit --with-NAME=[<bool>|<dir>].
é    N)Údebugc                 C   sœ   |  ¡ }|  d| ¡} | jd| dd d| d� |d ks@t|ƒrX| jd| dd| d� |d ksht|ƒr˜| jd	| dd
| d� | jd| dd| d� d S )Nz
%s Optionsz	--with-%sÚstringzgive %s installation location)ÚtypeÚdefaultÚhelpz--with-%s-includez%give %s include installation location)r   r   z--with-%s-libz!give %s lib installation locationz--with-%s-libszlist %s link libraries)ÚlowerÚadd_option_groupÚ
add_optionÚlen)ÚoptÚnameÚincsÚlibsr   © r   ú:/home/yuhw/wc/larsoft925/src/wire-cell-dev/waft/generic.pyÚ_options*   s"    ÿÿÿÿr   r   Tc                 C   s,  |  ¡ }| ¡ }	t|ƒ}t| jd| d ƒ}
t| jd| d ƒ}t| jd| d ƒ}t| jd| d ƒ}|rŽt| jd| d ƒ}|rŽdd„ | d¡D ƒ}td	||
||||ƒ |r¼|
râ|
  ¡ d
ksât‚n&|
râ|
  ¡ d
krâtd|||f ƒ d S t|
|||gƒ }|
�o|
  ¡ dk}|d k	}|�r~|�s |�r~|  	d| ¡ d}|�r@|d7 }| j
||	||d� d|	 | jk�rn|  d¡ n|  d¡ d S n¨|�r¶|�sœ|
�rœt |
d¡}|�r¶t| jd|	 |gƒ |�rî|�sÔ|
�rÔt |
d¡}|�rît| jd|	 |gƒ |�r&|�s|
�rt |
d¡}|�r&t| jd|	 |gƒ |�r|  	d|f ¡ |D ](}| j|d|	 d |	g| |	|d� �q@|  tt| jd|	 d ƒƒ¡ |  	d|	 ¡ t| jd|	 d ƒ}|  t|ƒ¡ |  d|	 d ¡�r d| jd|	 < td ||	f ƒ |�r| j j|g7  _ntd!||	f ƒ |�rÎ|  	d"| ¡ |D ](}| j|d|	 d# |	g| |	|d$� �q(t| jd|	 d ƒ}|  t|ƒ¡ |  d|	 d# ¡�r¾d| jd|	 < td%||	f ƒ |�rÎ| j j|g7  _ntd&||	f ƒ |�r(|  	d'| ¡ tƒ }|D ],}| j|| ¡ |d(� || j| ¡  7 }�qì|  t|ƒ¡ d S ))NZwith_zwith_%s_includezwith_%s_libzwith_%s_binzwith_%s_libsc                 S   s   g | ]}|  ¡ r|  ¡ ‘qS r   )Ústrip)Ú.0Úsr   r   r   Ú
<listcomp>E   s      z_configure.<locals>.<listcomp>ú,Z	CONFIGURE)ÚnoZoffZfalsezA%s: skipping non mandatory %s, use --with-%s=[yes|<dir>] to force)ÚyesÚonÚtruez"Checking for %s in PKG_CONFIG_PATHz--cflagsz --libs)ÚpackageÚuselib_storeÚargsÚ	mandatoryÚHAVE_zlocated by pkg-configzmissing from pkg-configZincludeZ	INCLUDES_ÚlibZLIBPATH_ÚbinZPATH_zLocation for %s libsZ_LIB)r    Údefine_nameÚuser   r   zLibs for %sÚLIB_é   z%s: HAVE %s libsz%s: NO %s libszLocation for %s headersZ_INC)Úheader_namer"   r#   r   r   z%s: HAVE %s includesz%s: NO %s includeszBins for %s)Úvarr   )r   ÚupperÚlistÚgetattrÚoptionsÚsplitr   ÚAssertionErrorÚanyÚ	start_msgZ	check_cfgÚenvÚend_msgÚospÚjoinÚsetattrÚ	check_cxxÚstrÚ
is_definedÚREQUIRESÚfind_program)Úctxr   r   r   ZbinsÚpcnamer   Úextusesr   ZUPPERÚinstdirZincdirÚlibdirÚbindirÚmaybeZno_dirsZhave_instdirZhave_pcnamer   ZtrylZ	have_libsZtryhZ	have_incsZ
found_binsZtrybr   r   r   Ú
_configure9   s´     ÿ
  ÿ
  ÿ
rA   )NN)r   r   r   NTr   )	Ú__doc__ÚsysÚos.pathÚpathr2   Úwaflib.Logsr   r   rA   r   r   r   r   Ú<module>   s
   $
