U
    WÄ±bA6  ã                   @   s>  d Z ddlZddlZddlmZmZmZ ddlmZ ddl	m
Z
mZ dddd	d
ddgZddddgZdZdZdZdZe ¡ Zdd„ Zdd„ Zdd„ Zdeddddeeeeddd d!d"d#d$d$d%d&d'œZd(d)„ Zed*d+„ ƒZed,d-„ ƒZed.d/„ ƒZed0d1„ ƒZed2d3„ ƒZed4d5„ ƒZed6d7„ ƒZe
d8ƒed9ƒd:d;„ ƒƒZ d<e _!dS )=aK  

This is an extra tool, not bundled with the default waf binary.
To add the boost tool to the waf file:
$ ./waf-light --tools=compat15,boost
	or, if you have waf >= 1.6.2
$ ./waf update --files=boost

When using this tool, the wscript will look like:

	def options(opt):
		opt.load('compiler_cxx boost')

	def configure(conf):
		conf.load('compiler_cxx boost')
		conf.check_boost(lib='system filesystem')

	def build(bld):
		bld(source='main.cpp', target='app', use='BOOST')

Options are generated, in order to specify the location of boost includes/libraries.
The `check_boost` configuration function allows to specify the used boost libraries.
It can also provide default arguments to the --boost-mt command-line arguments.
Everything will be packaged together in a BOOST component that you can use.

When using MSVC, a lot of compilation flags need to match your BOOST build configuration:
 - you may have to add /EHsc to your CXXFLAGS or define boost::throw_exception if BOOST_NO_EXCEPTIONS is defined.
   Errors: C4530
 - boost libraries will try to be smart and use the (pretty but often not useful) auto-linking feature of MSVC
   So before calling `conf.check_boost` you might want to disabling by adding
		conf.env.DEFINES_BOOST += ['BOOST_ALL_NO_LIB']
   Errors:
 - boost might also be compiled with /MT, which links the runtime statically.
   If you have problems with redefined symbols,
		self.env['DEFINES_%s' % var] += ['BOOST_ALL_NO_LIB']
		self.env['CXXFLAGS_%s' % var] += ['/MD', '/EHsc']
Passing `--boost-linkage_autodetect` might help ensuring having a correct linkage in some basic cases.

é    N)ÚUtilsÚLogsÚErrors)Úconf)ÚfeatureÚafter_methodz/usr/lib/x86_64-linux-gnuz/usr/lib/i386-linux-gnuz/usr/libz/usr/local/libz/opt/local/libz/sw/libz/libz/usr/includez/usr/local/includez/opt/local/includez/sw/includezboost/version.hppzn
#include <iostream>
#include <boost/version.hpp>
int main() { std::cout << BOOST_LIB_VERSION << std::endl; }
zT
#include <boost/system/error_code.hpp>
int main() { boost::system::error_code c; }
z=
#include <boost/thread.hpp>
int main() { boost::thread t; }
c                 C   s   t dkrdpdS )NÚwin32ÚiwZil©ÚPLATFORM©Úenv© r   ú*/home/yuhw/wc/wire-cell/waf-tools/boost.pyÚ<lambda>O   ó    r   c                 C   s   t dkrdpdS )NÚdarwinzclang-darwinÚclangr
   r   r   r   r   r   P   r   c                 C   s   t  d| jd ¡rdpdS )NZMinGWr   ÚmgwÚgcc)ÚreÚsearchÚCXXr   r   r   r   r   Q   r   ZbcbÚcomoÚcwZxgccÚedgÚkccZbckÚmpr   ÚvcÚqccÚswZtruZxlc)Zborlandr   r   r   r   r   zg++r   ÚicpcZintelr   ZkylixZmipsproZmingwÚmsvcr   Zsunzsunc++Ztru64cxxZvacppc                 C   sª   | j dddddd� | j ddddd	d� | j d
ddddd� | j dddddd� | j ddddd� | j dddddd� dtjd tjd f }| j dd|dd| d� d S ) Nz--boost-includesÚstringÚ Zboost_includeszOpath to the boost includes root (~boost root)
				   e.g. /path/to/boost_1_47_0)ÚtypeÚdefaultÚdestÚhelpz--boost-libsZ
boost_libszZpath to the directory where the boost libs are
				   e.g. /path/to/boost_1_47_0/stage/libz
--boost-mtÚ
store_trueFZboost_mtzselect multi-threaded libraries)Úactionr&   r'   r(   z--boost-abiZ	boost_abiz|select libraries with tags (gd for debug, static is automatically added),
				   see doc Boost, Getting Started, chapter 6.1z--boost-linkage_autodetectZboost_linkage_autodetectzRauto-detect boost linkage options (don't get used to it / might break other stuff))r*   r'   r(   z--boost-toolsetZboost_toolsetzHforce a toolset e.g. msvc, vc90, 						gcc, mingw, mgw45 (default: auto)z%d%dr   é   z--boost-pythonZboost_pythonz;select the lib python with this version 						(default: %s))Ú
add_optionÚsysÚversion_info)ÚoptZ
py_versionr   r   r   Úoptionsj   sD     þ þ þÿ
ÿ þ ÿþr0   c                 C   s&   |sd S | j  |¡}|r"| t¡S d S ©N)ÚrootÚfind_dirÚ	find_nodeÚBOOST_VERSION_FILE)ÚselfÚdZdnoder   r   r   Ú__boost_get_version_file†   s    
r8   c                 C   s|   |   |¡}|rhz| ¡ }W n& tk
r@   t d| ¡  ¡ Y n(X t dtj¡}| 	|¡}|rh| 
d¡S | jt|gddd�S )z*silently retrieve the boost version numberzCould not read the file %rz%^#define\s+BOOST_LIB_VERSION\s+"(.*)"r+   T)ÚfragmentÚincludesÚexecuteÚ
define_ret)r8   ÚreadÚEnvironmentErrorr   ÚerrorÚabspathr   ÚcompileÚMr   ÚgroupÚ	check_cxxÚBOOST_VERSION_CODE)r6   r7   ÚnodeÚtxtZre_butÚmr   r   r   Úboost_get_version�   s    


rI   c                 O   s�   |r|d p|  dd ¡}|r*|  |¡r*|S | j  dd¡ d¡t D ]}|  |¡rB|  S qB|rx|  d| ¡ |  d¡ n|  d¡ |  d¡ d S )	Nr   r:   ZINCLUDEr$   ú;zheaders not found in %súThe configuration failedzHheaders not found, please provide a --boost-includes argument (see help))Úgetr8   ÚenvironÚsplitÚBOOST_INCLUDESÚend_msgÚfatal)r6   ÚkÚkwr:   r7   r   r   r   Úboost_get_includesŸ   s    


rT   c                 C   sN   |}|s&t  ¡ }|tkr|}n| jj}|tkr6t| }t|tƒrD|pL|| jƒS r1   )r   Úunversioned_sys_platformÚBOOST_TOOLSETSr   ÚCXX_NAMEÚ
isinstanceÚstr)r6   ÚccÚtoolsetÚbuild_platformr   r   r   Úboost_get_toolset¯   s    r]   c                 O   s.  d|kr"| j  d¡t |d ¡fS |r.|d p8| dd¡}|rT| j  |¡}| d¡}|r\|sÈ| j dd¡ d	¡t D ]R}|s~qt| j  |¡}|r | d¡}|r  qÈ| j  |d
 ¡}|rt| d¡}|rt qÈqt|sþ|rê|  	d| ¡ |  
d¡ n|  	d¡ |  
d¡ |  d| ¡ |D ]}|  d| ¡ �q||fS )z- return the lib path and all the files in it ÚfilesÚ.r   ÚlibsNz*boost_*ÚLIBr$   rJ   Ú64zlibs not found in %srK   zAlibs not found, please provide a --boost-libs argument (see help)z.Found the boost path in %r with the libraries:z    %r)r2   r3   r   Úto_listrL   Úant_globrM   rN   Ú
BOOST_LIBSrP   rQ   Úto_log)r6   rR   rS   r`   Úpathr^   r7   Úxr   r   r   Ú__boost_get_libs_path½   s<    




ri   c                    s¤   ˆj f ˆŽ\‰‰ tˆ dd„ dd�‰ ˆ ˆ dd¡¡}d| ‰dˆjj ‰‡fd	d
„‰‡fdd„‰‡ ‡‡‡‡‡‡‡fdd„}ˆ ¡ |ˆ dd¡dƒ|ˆ dd¡dƒfS )zJ
	return the lib path and the required libs
	according to the parameters
	c                 S   s   t | jƒ| jfS r1   )ÚlenÚname)Úfr   r   r   r   è   r   z boost_get_libs.<locals>.<lambda>T)ÚkeyÚreverser[   r$   z(-%s[0-9]{0,3})z-%sc                    s0   |D ]&}|   |j¡rˆ  d| ¡ |  S qd S )NzFound boost lib %s)r   rk   rf   )Zre_libr^   Úfile©r6   r   r   Úfind_libí   s
    
z boost_get_libs.<locals>.find_libc                    s4   |   d¡r"ˆ jjdkr"| dd … } | d |  d¡… S )NÚlibr"   é   r_   )Ú
startswithr   ÚCC_NAMEÚrfind)rk   rp   r   r   Úformat_lib_nameô   s    z'boost_get_libs.<locals>.format_lib_namec           
         s€  g }t  | ¡} | s|S g }ˆ dd¡r0| d¡ ˆ dd ¡r\| d|rJdpLdˆd f ¡ n|rj| d¡ |rxd |¡pzd}|rˆˆjjpŽˆjj}| d	¡d
 }| D ]Ø}|dkrÊd 	|ˆd d ˆd ¡}n|}d|ˆ|ˆ|f d||ˆ|f d|ˆ||f d|||f d||f d| fD ]>}ˆ 
d| ¡ ˆt |¡ˆ ƒ}	|	�r| ˆ|	jƒ¡  q¢�qˆ d|ˆ ¡ f ¡ ˆ d¡ q¢|S )NÚmtFz-mtÚabiz%s%sz-sú-r$   z%sé   ÚpythonzK({0})?((-py{2})|(-py{1}(?=[^0-9]))|({2})|({1}(?=[^0-9]))|(?=[^0-9])(?!-py))r   zboost_%s%s%s%s%s$zboost_%s%s%s%s$zboost_%s%s%s$zboost_%s%s$zboost_%szTrying pattern %szlib %s not found in %srK   )r   rc   rL   ÚappendÚjoinr   Úcxxstlib_PATTERNÚcxxshlib_PATTERNÚ	partitionÚformatrf   r   rA   rk   rP   r@   rQ   )
Z	lib_namesZ	is_staticr`   ÚtZtags_patÚextrr   ZtagsÚpatternro   ©r^   rq   rw   rS   rg   r6   Ztoolset_patÚversionr   r   Ú
match_libsù   sB    

 

úz"boost_get_libs.<locals>.match_libsrr   NFÚstlib)ri   Úsortedr]   rL   r   ÚBOOST_VERSIONr@   )r6   rR   rS   r[   rˆ   r   r†   r   Úboost_get_libsá   s    *rŒ   c                    s¼  ˆj d sˆ d¡ |r |d p*| dd¡| dd¡dœ‰ ˆjj ¡ D ]<\}}| d¡sZqF|tdƒd… }|rr|p|| |d	¡ˆ |< qF| d
d¡‰ˆ d¡ ˆj	f ˆ Ž ˆj dˆ < }ˆ 
|¡ˆj _ˆ ˆj j¡ tjrðt ddˆj dˆ   ¡ ˆ d �sˆ d �sdS d|k�sdˆ k�r&t d¡ ˆ d¡ ˆjf ˆ Ž\}}}|gˆj dˆ < |gˆj dˆ < |ˆj dˆ < |ˆj dˆ < ˆ d¡ tj�rÀt dd| ¡ t dd| ¡ t dd| ¡ ‡ ‡‡fdd„}	ˆ  dd¡�r^ˆ d¡ ˆ | dd	¡¡}
|
d k�rHˆj d!ˆ   d"g7  < d}t |¡D ]$}| ˆj jd	 ¡�r*d#} �qP�q*|�sŒ|gˆj dˆ < |ˆj dˆ < ˆj dˆ = ˆj dˆ = d$d%gg fD ]Š}ˆj  ¡  ˆj d&ˆ   |7  < z.|	ƒ  ˆ d'ˆj d&ˆ   ¡ d}W  �q$W n4 tjk
�r } zˆj  ¡  |}W 5 d}~X Y nX �q˜|dk	�r\ˆjd(|d)� ˆ d*¡ nˆ d+¡ ˆ d*¡ nZˆ d,¡ z
|	ƒ  W n: tjk
�r¬ } zˆ d-¡ ˆ d*¡ W 5 d}~X Y nX ˆ d¡ dS ).zÓ
	Initialize boost libraries to be used.

	Keywords: you can pass the same parameters as with the command line (without "--boost-").
	Note that the command line has the priority, and should preferably be used.
	r   z4load a c++ compiler first, conf.load("compiler_cxx")r   rr   Nr‰   )rr   r‰   Zboost_r$   Úuselib_storeZBOOSTzChecking boost includeszINCLUDES_%sÚCYANz
	path : %sÚstaticz9boost: static parameter is deprecated, use stlib instead.zChecking boost libsz
LIBPATH_%szSTLIBPATH_%szLIB_%szSTLIB_%sÚokz	shared libs : %sz	static libs : %sc                      st   ˆ d rdˆ d ks(ˆ d r8dˆ d kr8ˆj tˆdd� ˆ d rLdˆ d ks`ˆ d rpdˆ d krpˆj tˆdd� d S )Nrr   Úsystemr‰   F)r9   Úuser;   Úthread)rD   ÚBOOST_ERROR_CODEÚBOOST_THREAD_CODEr   ©Úparamsr6   Úvarr   r   Útry_linkU  s    ÿ
ÿÿ
ÿzcheck_boost.<locals>.try_linkZlinkage_autodetectFz(Attempting to detect boost linkage flagsr[   )r   z
DEFINES_%sZBOOST_ALL_NO_LIBTz/MDz/EHsczCXXFLAGS_%sz$ok: winning cxxflags combination: %sz[Could not auto-detect boost linking flags combination, you may report it to boost.py author)ÚexrK   zPBoost linkage flags auto-detection not implemented (needed ?) for this toolchainzChecking for boost linkagez=Could not link against boost libraries using supplied options)r   rQ   rL   r0   Ú__dict__Úitemsrt   rj   Ú	start_msgrT   rI   r‹   rP   r   ÚverboseÚpprintÚwarnrŒ   r]   r   ÚlistdirÚendswithr€   Ústashr   ÚConfigurationErrorÚrevert)r6   rR   rS   rm   ÚvalueÚincrg   r`   Zstlibsr™   r[   Zhas_dllsrh   ÚcxxflagsÚexcÚer   r–   r   Úcheck_boost&  sŽ    


þ














r«   ÚcxxÚ
apply_linkc                 C   sŠ   t jstjr| jj d¡sd S dt _t| ddƒ}| jj	D ]L}z6| j 
| jj| | jj¡}| j || jj |¡¡ W q8   Y q8Y q8X q8d S )NÚinstallTÚinstall_pathz	${BINDIR})Úinstall_boostÚdoner   Úis_win32ÚbldÚcmdrt   Úgetattrr   Z	LIB_BOOSTÚ	find_filer€   ZLIBPATH_BOOSTÚinstall_filesr2   r4   )r6   Úinst_torr   ro   r   r   r   r°   Ž  s    r°   F)"Ú__doc__r-   r   Úwaflibr   r   r   Zwaflib.Configurer   Zwaflib.TaskGenr   r   re   rO   r5   rE   r”   r•   rU   r   Zdetect_intelZdetect_clangZdetect_mingwrV   r0   r8   rI   rT   r]   ri   rŒ   r«   r°   r±   r   r   r   r   Ú<module>   sz   (    ÿì




#
D
g