U
    !šbgdH  ã                   @   sN  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
gZddddgZdZd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d8d9„ ƒZ"e
d:ƒed;ƒ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/libz/usr/local/libz/opt/local/libz/sw/libz/libz/usr/includez/usr/local/includez/opt/local/includez/sw/includezboost/version.hppz†
#include <iostream>
#include <boost/version.hpp>
int main() { std::cout << BOOST_LIB_VERSION << ":" << BOOST_VERSION << std::endl; }
zT
#include <boost/system/error_code.hpp>
int main() { boost::system::error_code c; }
a  
#include <pthread.h>
static void* f(void*) { return 0; }
int main() {
	pthread_t th;
	pthread_attr_t attr;
	pthread_attr_init(&attr);
	pthread_create(&th, &attr, &f, 0);
	pthread_join(th, 0);
	pthread_cleanup_push(0, 0);
	pthread_cleanup_pop(0);
	pthread_attr_destroy(&attr);
}
z=
#include <boost/thread.hpp>
int main() { boost::thread t; }
aI  
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
int main() {
	using namespace boost::log;
	add_common_attributes();
	add_console_log(std::clog, keywords::format = "%Message%");
	BOOST_LOG_TRIVIAL(debug) << "log is working" << std::endl;
}
c                 C   s   t dkrdpdS )NÚwin32ÚiwZil©ÚPLATFORM©Úenv© r   ú1/home/yuhw/wc/larsoft925/src/0.29.2/waft/boost.pyÚ<lambda>i   ó    r   c                 C   s   t dkrdpdS )NÚdarwinzclang-darwinÚclangr
   r   r   r   r   r   j   r   c                 C   s   t  d| jd ¡rdpdS )NZMinGWr   ÚmgwÚgcc)ÚreÚsearchÚCXXr   r   r   r   r   k   r   ZbcbÚcomoÚcwZxgccÚedgÚkccZbckÚmpr   ÚvcÚqccÚswZtruZxlc)Zborlandr   r   r   r   r   zg++r   ZicpcZintelr   ZkylixZmipsproZmingwÚmsvcr   Úsunzsunc++Ztru64cxxZvacppc                 C   s´   |   d¡} | jdtdddd� | jdtddd	d� | jd
ddddd� | jdtdddd� | jddddd� | jdtdddd� dtjd tjd f }| jdt|dd| d� d S ) NzBoost Optionsz--boost-includesÚ Zboost_includeszdpath to the directory where the boost includes are,
				   e.g., /path/to/boost_1_55_0/stage/include)ÚtypeÚdefaultÚdestÚhelpz--boost-libsZ
boost_libsz[path to the directory where the boost libs are,
				   e.g., path/to/boost_1_55_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_groupÚ
add_optionÚstrÚsysÚversion_info)ÚoptZ
py_versionr   r   r   Úoptions„   sF    
 þ þ þÿ
ÿ þ ÿþr1   c                 C   s&   |sd S | j  |¡}|r"| t¡S d S ©N)ÚrootÚfind_dirÚ	find_nodeÚBOOST_VERSION_FILE)ÚselfÚdÚdnoder   r   r   Ú__boost_get_version_file¡   s    
r:   c                 C   s¦   |   |¡}|rŒz| ¡ }W n$ tk
r>   t d| ¡ ¡ Y nNX t dtj¡}| 	|¡}t dtj¡}| 	|¡}|rŒ|rŒ| 
d¡| 
d¡fS | jt|gddd� d¡S )z*silently retrieve the boost version numberzCould not read the file %rz%^#define\s+BOOST_LIB_VERSION\s+"(.+)"z ^#define\s+BOOST_VERSION\s+(\d+)r*   T)ÚfragmentÚincludesÚexecuteÚ
define_retú:)r:   ÚreadÚEnvironmentErrorr   ÚerrorÚabspathr   ÚcompileÚMr   ÚgroupÚ	check_cxxÚBOOST_VERSION_CODEÚsplit)r7   r8   ÚnodeÚtxtZre_but1Zm1Zre_but2Zm2r   r   r   Úboost_get_versionª   s    


rL   c                 O   sŽ   |r|d p|  d¡}|r(|  |¡r(|S | j  dd¡ d¡t D ]}|  |¡r@|  S q@|rv|  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))Úgetr:   ÚenvironrI   ÚBOOST_INCLUDESÚend_msgÚfatal)r7   ÚkÚkwr<   r8   r   r   r   Úboost_get_includes¼   s    


rV   c                 C   sN   |}|s&t  ¡ }|tkr|}n| jj}|tkr6t| }t|tƒrD|pL|| jƒS r2   )r   Úunversioned_sys_platformÚBOOST_TOOLSETSr   ÚCXX_NAMEÚ
isinstancer-   )r7   ÚccÚtoolsetZbuild_platformr   r   r   Úboost_get_toolsetÌ   s    r]   c                 O   s,  d|kr"| j  d¡t |d ¡fS |r.|d p6| d¡}|rR| j  |¡}| d¡}|rZ|sÆ| j dd¡ d¡t D ]R}|s|qr| j  |¡}|rž| d¡}|rž qÆ| j  |d	 ¡}|rr| d¡}|rr qÆqr|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   Úlibsz*boost_*ÚLIBr#   rM   Ú64zlibs not found in %srN   zAlibs not found, please provide a --boost-libs argument (see help)z.Found the boost path in %r with the libraries:z    %r)r3   r4   r   Úto_listrO   Úant_globrP   rI   Ú
BOOST_LIBSrR   rS   Úto_log)r7   rT   rU   r`   Úpathr^   r8   Ú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
„‰t d¡‰‡‡fdd„‰‡ ‡‡‡‡‡‡‡f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 r2   )Ú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)r7   r   r   Úfind_lib
  s
    
z boost_get_libs.<locals>.find_libz$\.(a|so|lib|dll|dylib)(\.[0-9\.]+)?$c                    s.   |   d¡r"ˆ jjdkr"| dd … } ˆ d| ¡S )NÚlibr!   é   r#   )Ú
startswithr   ÚCC_NAMEÚsub)rk   )r7   Úwo_extr   r   Úformat_lib_name  s    z'boost_get_libs.<locals>.format_lib_namec           
         sˆ  g }t  | ¡} | s|S g }ˆ dd¡r0| d¡ ˆ d¡rZ| d|rHdpJdˆd f ¡ n|rh| d¡ |rvd |¡pxd}|r†ˆjjpŒˆjj}| d	¡d
 }| D ]â}|dkrÒd 	|ˆd 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ÚmtFú-mtÚabiz%s%sz-sú-r#   z%sé   ÚpythonzV({0})?((-py{2})|(-py{1}(?=[^0-9]))|({2})|(-{1}.{3})|({1}(?=[^0-9]))|(?=[^0-9])(?!-py))r   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 %srN   )r   rc   rO   ÚappendÚjoinr   Zcxxstlib_PATTERNÚcxxshlib_PATTERNÚ	partitionÚformatrf   r   rD   rk   rR   rC   rS   )
Z	lib_namesZ	is_staticr`   ÚtZtags_patÚextrq   ZtagsÚpatternro   )r^   rp   rw   rU   rg   r7   Útoolset_patÚversionr   r   Ú
match_libs  sB    


 
&
úz"boost_get_libs.<locals>.match_libsrq   FÚstlib)	ri   Úsortedr]   rO   r   ÚBOOST_VERSIONr   rD   rC   )r7   rT   rU   r\   rˆ   r   )	r^   rp   rw   rU   rg   r7   r†   r‡   rv   r   Úboost_get_libsþ   s    
*rŒ   c                 O   sØ   |  dd¡}|  d¡ t ¡ dkr0ddddg}nd	d
dddddddddg}|D ]z}zR| j ¡  | j d| |¡ | j d| |¡ | jtd|dd� |  	|¡ W  dS  | j
jk
rÆ   | j ¡  Y qNX qN|  	d¡ dS )a4  
	Computes which flags should be added to CXXFLAGS and LINKFLAGS to compile in multi-threading mode

	Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3,
	boost/thread.hpp will trigger a #error if -pthread isn't used:
	  boost/config/requires_threads.hpp:47:5: #error "Compiler threading support
	  is not turned on. Please set the correct command line options for
	  threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"

	Based on _BOOST_PTHREAD_FLAG(): https://github.com/tsuna/boost.m4/blob/master/build-aux/boost.m4
    Úuselib_storeÚBOOSTz)Checking the flags needed to use pthreadsÚsunosz	-pthreadsz	-lpthreadry   z-pthreadr#   z
-lpthreadsz-Kthreadz-kthreadz	-llthreadz	-mthreadsz--thread-safeúCXXFLAGS_%szLINKFLAGS_%sNF)ÚcodeÚmsgÚuser=   ÚNone)rO   Ú	start_msgr   rW   r   ÚstashÚappend_valuerG   ÚPTHREAD_CODErR   ÚerrorsÚConfigurationErrorÚrevert)r7   rT   rU   ÚvarZboost_pthread_flagsZboost_pthread_flagr   r   r   Ú_check_pthread_flagD  s,    
    ÿ

r�   c                    sˆ  ˆj d sˆ d¡ |r |d p(| d¡| d¡dœ‰ˆjj ¡ D ]<\}}| d¡sVqB|tdƒd… }|rn|px| |d	¡ˆ|< qB| d
d¡‰ˆjdddd� ˆj j	rÎˆ 
ˆj j	d dg¡}t dd| ¡  ¡ ˆ d¡ ˆjf ˆŽ ˆj dˆ < }ˆ |¡}|d ˆj _t|d ƒˆj _ˆ dt|d ƒd t|d ƒd d t|d ƒd f ¡ tj�rvt 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�rFt dd| ¡ t dd#|	 ¡ t dd$|
 ¡ ‡fd%d&„‰‡fd'd(„‰‡‡fd)d*„‰ ˆ d+ƒ�r‚ˆ ||¡ ‡ ‡‡‡fd,d-„}ˆ d.d¡�r*ˆ d/¡ ˆ | d0d	¡¡}|d1k�rˆj d2ˆ   d3g7  < d}t |¡D ]$}| ˆj jd	 ¡�rîd4} �q�qî|�sP|gˆj dˆ < |	ˆj d!ˆ < ˆj d ˆ = ˆj dˆ = d5d6gg fD ]’}ˆj   ¡  ˆj d7ˆ   |7  < z
|ƒ  W n4 t!j"k
�r¾ } zˆj  #¡  |}W 5 d}~X Y n.X ˆ d8ˆj d7ˆ   ¡ d}ˆj  $¡   �qð�q\|dk	�r(ˆjd9|d:� ˆ d;¡ nˆ d<¡ ˆ d;¡ nZˆ d=¡ z
|ƒ  W n: t!j"k
�rx } 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   rq   r‰   )rq   r‰   Zboost_Nr#   r�   rŽ   zdpkg-architectureÚDPKG_ARCHITECTUREF)rœ   Ú	mandatoryz-qDEB_HOST_MULTIARCHz/usr/lib/%szChecking boost includeszINCLUDES_%sr*   z%d.%d.%di † éd   iè  Ú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                    s   ˆ d o| ˆ d kS )Nrq   r   ©rq   ©Úparamsr   r   Ú	has_shlib¸  s    zcheck_boost.<locals>.has_shlibc                    s   ˆ d o| ˆ d kS )Nr‰   r   r¤   r¥   r   r   Ú	has_stlibº  s    zcheck_boost.<locals>.has_stlibc                    s   ˆ | ƒpˆ| ƒS r2   r   r¤   )r§   r¨   r   r   Úhas_lib¼  s    zcheck_boost.<locals>.has_libÚthreadc                      sŒ   ˆ dƒrˆj tˆdd� ˆ dƒr0ˆj tˆdd� ˆ dƒrˆˆ dƒsXˆjdˆ   dg7  < ˆdƒrxˆjdˆ   dg7  < ˆj tˆdd� d S )	NÚsystemF)r;   r“   r=   rª   Úlogú
DEFINES_%sZBOOST_LOG_NO_THREADSZBOOST_LOG_DYN_LINK)rG   ÚBOOST_ERROR_CODEÚBOOST_THREAD_CODEr   ÚBOOST_LOG_CODEr   )r©   r§   r7   rœ   r   r   Útry_linkÂ  s    zcheck_boost.<locals>.try_linkZlinkage_autodetectz(Attempting to detect boost linkage flagsr\   )r   r­   ZBOOST_ALL_NO_LIBTz/MDz/EHscr�   z$ok: winning cxxflags combination: %sz[Could not auto-detect boost linking flags combination, you may report it to boost.py author)ÚexrN   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   rS   rO   r1   Ú__dict__Úitemsrs   rj   Úfind_programrž   Úcmd_and_logre   ÚinsertÚstripr•   rV   rL   r‹   ÚintZBOOST_VERSION_NUMBERrR   r   ÚverboseÚpprintÚwarnrŒ   r�   r]   r   ÚlistdirÚendswithr€   r–   r   rš   r›   Úcommit)r7   rT   rU   rm   ÚvalueZdeb_host_multiarchÚincZversionsrg   r`   Zstlibsr±   r\   Zhas_dllsrh   ÚcxxflagsÚeÚexcr   )r©   r§   r¨   r¦   r7   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 |¡d� W q8   Y q8Y q8X q8d S )NÚinstallTÚinstall_pathz	${BINDIR})Ú
install_toÚinstall_from)Úinstall_boostÚdoner   Úis_win32ÚbldÚcmdrs   Úgetattrr   Z	LIB_BOOSTÚ	find_filer€   ZLIBPATH_BOOSTÚadd_install_filesr3   r5   )r7   Úinst_torq   ro   r   r   r   rÌ     s    rÌ   F)%Ú__doc__r.   r   Úwaflibr   r   r   Zwaflib.Configurer   Zwaflib.TaskGenr   r   re   rQ   r6   rH   r®   r˜   r¯   r°   rW   r   Zdetect_intelZdetect_clangZdetect_mingwrX   r1   r:   rL   rV   r]   ri   rŒ   r�   rÅ   rÌ   rÍ   r   r   r   r   Ú<module>   sv   (ì




#
E
<
