a
    P·5gdH  ã                   @   sD  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 g d¢Zg d¢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d)d*„ ƒZed+d,„ ƒZed-d.„ ƒZ ed/d0„ ƒZ!ed1d2„ ƒZ"e
d3ƒed4ƒd5d6„ ƒƒZ#d7e#_$dS )8aK  

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_method)z/usr/libz/usr/local/libz/opt/local/libz/sw/libz/lib)z/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   ú7/home/yuhw/wc/larsoft925/src/wct-porting2/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Ú Ú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-libsÚ
boost_libsz[path to the directory where the boost libs are,
				   e.g., path/to/boost_1_55_0/stage/libz
--boost-mtÚ
store_trueFÚboost_mtzselect multi-threaded libraries)Úactionr&   r'   r(   z--boost-abiÚ	boost_abiz|select libraries with tags (gd for debug, static is automatically added),
				   see doc Boost, Getting Started, chapter 6.1z--boost-linkage_autodetectÚboost_linkage_autodetectzRauto-detect boost linkage options (don't get used to it / might break other stuff))r,   r'   r(   z--boost-toolsetÚboost_toolsetzHforce a toolset e.g. msvc, vc90, 						gcc, mingw, mgw45 (default: auto)z%d%dr   é   z--boost-pythonÚ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„   s<    
þþþÿ
ÿþÿþr8   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    
rA   c                 C   s¤   |   |¡}|rŠz| ¡ }W n" ty<   t d| ¡ ¡ Y nN0 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+)r0   T)ÚfragmentÚincludesÚexecuteÚ
define_retú:)rA   ÚreadÚEnvironmentErrorr   ÚerrorÚabspathr   ÚcompileÚMr   ÚgroupÚ	check_cxxÚBOOST_VERSION_CODEÚsplit)r>   r?   ÚnodeÚtxtZre_but1Zm1Zre_but2Zm2r   r   r   Úboost_get_versionª   s    


rS   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   rC   ZINCLUDEr#   ú;zheaders not found in %súThe configuration failedzHheaders not found, please provide a --boost-includes argument (see help))ÚgetrA   ÚenvironrP   ÚBOOST_INCLUDESÚend_msgÚfatal)r>   ÚkÚkwrC   r?   r   r   r   Úboost_get_includes¼   s    


r]   c                 C   sN   |}|s&t  ¡ }|tv r|}n| jj}|tv r6t| }t|tƒrD|pL|| jƒS r9   )r   Úunversioned_sys_platformÚBOOST_TOOLSETSr   ÚCXX_NAMEÚ
isinstancer4   )r>   ÚccÚtoolsetZbuild_platformr   r   r   Úboost_get_toolsetÌ   s    rd   c                 O   s,  d|v 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#   rT   Ú64zlibs not found in %srU   zAlibs not found, please provide a --boost-libs argument (see help)z.Found the boost path in %r with the libraries:z    %r)r:   r;   r   Úto_listrV   Úant_globrW   rP   Ú
BOOST_LIBSrY   rZ   Úto_log)r>   r[   r\   rg   Úpathre   r?   Úxr   r   r   Ú__boost_get_libs_pathÚ   s<    




rp   c                    s°   ˆj f i ˆ¤Ž\‰‰ 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 r9   )ÚlenÚname)Úfr   r   r   r     r   z boost_get_libs.<locals>.<lambda>T)ÚkeyÚreverserc   r#   z(-%s[0-9]{0,3})z-%sc                    s0   |D ]&}|   |j¡rˆ  d| ¡ |  S qd S )NzFound boost lib %s)r   rr   rm   )Zre_libre   Úfile)r>   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)rr   )r>   Ú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   r0   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 %srU   )r   rj   rV   ÚappendÚjoinr   Zcxxstlib_PATTERNÚcxxshlib_PATTERNÚ	partitionÚformatrm   r   rK   rr   rY   rJ   rZ   )
Z	lib_namesZ	is_staticrg   ÚtZtags_patÚextrx   ZtagsÚpatternrv   )re   rw   r~   r\   rn   r>   Útoolset_patÚversionr   r   Ú
match_libs  sB    


 
&
úz"boost_get_libs.<locals>.match_libsrx   FÚstlib)	rp   Úsortedrd   rV   r   ÚBOOST_VERSIONr   rK   rJ   )r>   r[   r\   rc   r�   r   )	re   rw   r~   r\   rn   r>   r�   rŽ   r}   r   Úboost_get_libsþ   s    
*r“   c              	   O   sÀ   |  dd¡}|  d¡ t ¡ dkr,g d¢}ng d¢}|D ]x}zR| j ¡  | j d| |¡ | j d| |¡ | jtd	|d
d� |  	|¡ W  d	S  | j
jy®   | j ¡  Y q80 q8|  	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Úsunos)ú	-pthreadsú	-lpthreadr€   ú-pthread)r#   z
-lpthreadsz-Kthreadz-kthreadz	-llthreadr™   r—   z	-mthreadsr˜   z--thread-safer€   úCXXFLAGS_%szLINKFLAGS_%sNF)ÚcodeÚmsgÚuserD   ÚNone)rV   Ú	start_msgr   r^   r   ÚstashÚappend_valuerN   ÚPTHREAD_CODErY   ÚerrorsÚConfigurationErrorÚrevert)r>   r[   r\   Ú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 i ˆ¤Ž ˆj dˆ < }ˆ |¡}|d ˆj _t|d ƒˆj _ˆ dt|d ƒd t|d ƒd d t|d ƒd f ¡ tj�rzt ddˆj dˆ   ¡ ˆd �s’ˆd �s’dS d|v �s¦dˆv �r°t d¡ ˆ d¡ ˆjf i ˆ¤Ž\}}	}
|gˆj dˆ < |gˆj dˆ < |	ˆj d ˆ < |
ˆj d!ˆ < ˆ d"¡ tj�rNt dd| ¡ t dd#|	 ¡ t dd$|
 ¡ ‡fd%d&„‰‡fd'd(„‰‡‡fd)d*„‰ ˆ d+ƒ�rŠˆ ||¡ ‡ ‡‡‡fd,d-„}ˆ d.d¡�r4ˆ d/¡ ˆ | d0d	¡¡}|d1v �rˆj d2ˆ   d3g7  < d}t |¡D ]$}| ˆj jd	 ¡�röd4} �q�qö|�sX|gˆj dˆ < |	ˆj d!ˆ < ˆj d ˆ = ˆj dˆ = d5d6gg fD ]”}ˆj   ¡  ˆj d7ˆ   |7  < z
|ƒ  W n6 t!j"�yÈ } zˆj  #¡  |}W Y d}~n6d}~0 0 ˆ d8ˆj d7ˆ   ¡ d}ˆj  $¡   �qú�qd|du�r2ˆjd9|d:� ˆ d;¡ nˆ d<¡ ˆ d;¡ n\ˆ d=¡ z
|ƒ  W n< t!j"�y„ } z ˆ d>¡ ˆ d;¡ W Y d}~n
d}~0 0 ˆ 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   rx   r�   )rx   r�   Zboost_Nr#   r”   r•   zdpkg-architectureÚDPKG_ARCHITECTUREF)r¦   Ú	mandatoryz-qDEB_HOST_MULTIARCHz/usr/lib/%szChecking boost includeszINCLUDES_%sr0   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 v S )Nrx   r   ©rx   ©Úparamsr   r   Ú	has_shlib¸  s    zcheck_boost.<locals>.has_shlibc                    s   ˆ d o| ˆ d v S )Nr�   r   r®   r¯   r   r   Ú	has_stlibº  s    zcheck_boost.<locals>.has_stlibc                    s   ˆ | ƒpˆ| ƒS r9   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)rB   r�   rD   r´   Úlogú
DEFINES_%sZBOOST_LOG_NO_THREADSZBOOST_LOG_DYN_LINK)rN   ÚBOOST_ERROR_CODEÚBOOST_THREAD_CODEr   ÚBOOST_LOG_CODEr   )r³   r±   r>   r¦   r   r   Útry_linkÂ  s    zcheck_boost.<locals>.try_linkZlinkage_autodetectz(Attempting to detect boost linkage flagsrc   )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)ÚexrU   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   rZ   rV   r8   Ú__dict__Úitemsrz   rq   Úfind_programr¨   Úcmd_and_logrl   ÚinsertÚstriprŸ   r]   rS   r’   ÚintZBOOST_VERSION_NUMBERrY   r   ÚverboseÚpprintÚwarnr“   r§   rd   r   ÚlistdirÚendswithr‡   r    r   r¤   r¥   Úcommit)r>   r[   r\   rt   ÚvalueZdeb_host_multiarchÚincZversionsrn   rg   Zstlibsr»   rc   Zhas_dllsro   ÚcxxflagsÚeÚexcr   )r³   r±   r²   r°   r>   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 q80 q8d S )NÚinstallTÚinstall_pathz	${BINDIR})Ú
install_toÚinstall_from)Úinstall_boostÚdoner   Úis_win32ÚbldÚcmdrz   Úgetattrr   Z	LIB_BOOSTÚ	find_filer‡   ZLIBPATH_BOOSTÚadd_install_filesr:   r<   )r>   Úinst_torx   rv   r   r   r   rÖ     s    rÖ   F)%Ú__doc__r5   r   Úwaflibr   r   r   Zwaflib.Configurer   Zwaflib.TaskGenr   r   rl   rX   r=   rO   r¸   r¢   r¹   rº   r^   r   Zdetect_intelZdetect_clangZdetect_mingwr_   r8   rA   rS   r]   rd   rp   r“   r§   rÏ   rÖ   r×   r   r   r   r   Ú<module>   sv   (ì




#
E
<
