a
    P·5gi  ã                   @   s\   d Z ddlZddlmZ ddlmZ dd„ Zdd„ Zdd	„ Z	dd
d„Z
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:   t | tƒs| S |  ¡ d ¡ v r"dS |  ¡ d ¡ v r6dS | S )zK
    Convert b to Bool if true'ish or false'ish string, else return b.
    zyes on trueTzno off falseF)Ú
isinstanceÚstrÚlowerÚsplit)Úb© r   ú9/home/yuhw/wc/larsoft925/src/wct-porting2/waft/generic.pyÚboolish*   s    
r
   c                 C   sR   t t| d|› �dƒpNt| d|› d�dƒpNt| d|› d�dƒpNt| d|› d�dƒƒS )z3
    Return whether opt is with named package.
    Úwith_NZ_libZ_libsZ_include)r
   Úgetattr)ÚoptÚnamer   r   r	   Úwith_p7   s    ÿþýr   c              	   O   s@   t |ƒt | ¡ ƒ D ]&\}}t| || dd ¡| dd ¡ƒ qd S )NÚincsÚlibs)ÚlistÚitemsÚ_optionsÚget)r   ÚpkgdescÚpkgmapr   Údescr   r   r	   Ú
do_optionsA   s
    

þr   c                 C   sœ   |  ¡ }|  d| ¡} | jd| td d| d� |d u s@t|ƒrX| jd| td| d� |d u sht|ƒr˜| jd| td	| d� | jd
| td| d� d S )Nz
%s Optionsz	--with-%szgive %s installation location)ÚtypeÚdefaultÚhelpz--with-%s-includez%give %s include installation location)r   r   z--with-%s-libz"list %s lib installation locationsz--with-%s-libszlist %s link libraries)r   Úadd_option_groupÚ
add_optionr   Úlen)r   r   r   r   r   r   r   r	   r   H   s"    ÿÿÿÿr   c                 O   s4   t |ƒt | ¡ ƒ D ]\}}t| |fi |¤Ž qd S )N)r   r   Ú
_configure)Úcfgr   r   r   r   r   r   r	   Údo_configureW   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	|›d
|
›d|›d|›d|›d|›�ƒ |rä|
râ|
  ¡ dv rât|› d|
› d�ƒ‚n*|
�r|
  ¡ dv �rtd|||f ƒ d S t|
|||gƒ }|
�o0|
  ¡ dv }|d u}|�rª|�sL|�rª|  	d| ¡ d}|�rl|d7 }| j
||	||d� d|	 | jv �rš|  d¡ n|  d¡ d S n°|�ræ|�sÈ|
�rÈt |
d¡}|�ræt| jd|	 | d¡ƒ |�r"|�s|
�rt |
d¡}|�r"t| jd|	 | d¡ƒ |�rZ|�s@|
�r@t |
d¡}|�rZt| jd |	 |gƒ |�rD|  	d!|f ¡ |D ](}| j|d|	 d" |	g| |	|d#� �qt|  tt| jd|	 d ƒƒ¡ |  	d$|	 ¡ t| jd%|	 d ƒ}|  t|ƒ¡ |  d|	 d" ¡�r4d&| jd|	 < td'||	f ƒ |�rD| 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 )0Nr   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>h   ó    z_configure.<locals>.<listcomp>ú,zconfigure: name=z	 instdir=z incdir=z libdir=z mandatory=z	 extuses=)ÚnoZoffZfalsez is mandatory, "z" not allowedzA%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)r2   Údefine_nameÚuser.   r0   zLibs for %sÚLIB_é   z%s: HAVE %s libsz%s: NO %s libszLocation for %s headersZ_INC)Úheader_namer4   r5   r.   r0   z%s: HAVE %s includesz%s: NO %s includeszBins for %s)Úvarr0   )r   Úupperr   r   Úoptionsr   r   Ú
ValueErrorÚanyÚ	start_msgZ	check_cfgÚenvÚend_msgÚospÚjoinÚsetattrÚ	check_cxxr   Ú
is_definedÚREQUIRESÚfind_program)Úctxr   r   r   ZbinsÚpcnamer0   Ú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	   r    \   s¬    ,ÿ
ÿ
ÿ
r    )NN)r   r   r   NTr   )Ú__doc__ÚsysÚos.pathÚpathrA   Úwaflib.Logsr   r
   r   r   r   r"   r    r   r   r   r	   Ú<module>   s   $

