
Y                 @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d d l m Z d d l	 m
 Z
 m Z d d l m Z d d l m Z m Z d d l m Z d d l m Z d d	 l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d d
 l m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% m& Z& m' Z' m( Z( m) Z) m* Z* m+ Z+ m, Z, m- Z- m. Z. m/ Z/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 d Z7 i d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z8 d d   Z9 d d d  Z: d d    Z; d! d"   Z< d# d$   Z= d% d&   Z> d' d(   Z? d) d*   Z@ d+ d,   ZA d- d.   ZB d/ d0   ZC Gd1 d2   d2  ZD d3 d4   ZE Gd5 d6   d6  ZF Gd7 d8   d8  ZG d S)9    N   )coredata)ArLinkerVisualStudioLinker)mesonlib)EnvironmentException
Popen_safe)mlog)	compilers)	CLANG_OSXCLANG_STANDARD	CLANG_WIN
GCC_CYGWIN	GCC_MINGWGCC_OSXGCC_STANDARDICC_STANDARDis_assembly	is_header
is_library
is_llvm_ir	is_object	is_source)ClangCCompilerClangCPPCompilerClangObjCCompilerClangObjCPPCompilerG95FortranCompilerGnuCCompilerGnuCPPCompilerGnuFortranCompilerGnuObjCCompilerGnuObjCPPCompilerIntelCCompilerIntelCPPCompilerIntelFortranCompilerJavaCompilerMonoCompilerNAGFortranCompilerOpen64FortranCompilerPathScaleFortranCompilerPGIFortranCompilerRustCompilerSunFortranCompilerValaCompilerVisualStudioCCompilerVisualStudioCPPCompilerzmeson.buildCFLAGScZCXXFLAGScppZ	OBJCFLAGSobjcZOBJCXXFLAGSobjcppZFFLAGSfortranZDFLAGSdZ	VALAFLAGSZvalac              C   sy   d }  d } d } t  j |  d g  s0 d  }  n  t  j | d g  sN d  } n  t  j | d g  sl d  } n  |  | | f S)NZgcovrZlcovZgenhtmlz	--version)r   Z
exe_exists)Z	gcovr_exeZlcov_exeZgenhtml_exe r8   R/mnt/raid6/a/bak/reczko/tools/protein/utils/meson-0.42.1/mesonbuild/environment.pyfind_coverage_toolsO   s    			r:   z1.5c             C   s   x d d g D]s } y& t  | d g  d d  \ } } Wn t t f k
 rV w Yn X| j d k r t j | d |   r | Sq Wd  S)Nninjazninja-buildz	--versionr      z>=)r   FileNotFoundErrorPermissionError
returncoder   Zversion_compare)versionnpfoundr8   r8   r9   detect_ninja\   s    &%rD   c              C   s`   t  j j d d  j   }  |  s\ y t  j d j   }  Wq\ t k
 rX t d   Yq\ Xn  |  S)z:
    The architecture of Windows itself: x86 or amd64
    ZPROCESSOR_ARCHITEW6432 ZPROCESSOR_ARCHITECTUREz'Unable to detect native OS architecture)osenvirongetlowerKeyErrorr   )Zarchr8   r8   r9   detect_native_windows_archh   s    rK   c             C   s   t    } | d k r | Sx |  j   D]t } | j d k rx d t j k rx t j j d d  j   } | d k rx | Sn  | j d k r& | j d  r& d Sq& W| S)a  
    Detecting the 'native' architecture of Windows is not a trivial task. We
    cannot trust that the architecture that Python is built for is the 'native'
    one because you can run 32-bit apps on 64-bit Windows using WOW64 and
    people sometimes install 32-bit Python on 64-bit Windows.

    We also can't rely on the architecture of the OS itself, since it's
    perfectly normal to compile and run 32-bit applications on Windows as if
    they were native applications. It's a terrible experience to require the
    user to supply a cross-info file to compile 32-bit applications on 64-bit
    Windows. Thankfully, the only way to compile things with Visual Studio on
    Windows is by entering the 'msvc toolchain' environment, which can be
    easily detected.

    In the end, the sanest method is as follows:
    1. Check if we're in an MSVC toolchain environment, and if so, return the
       MSVC toolchain architecture as our 'native' architecture.
    2. If not, check environment variables that are set by Windows and WOW64 to
       find out the architecture that Windows is built for, and use that as our
       'native' architecture.
    amd64ZmsvcZVCINSTALLDIRZPlatformx86gcc__i386__)rK   valuesidrF   rG   rH   rI   has_builtin_define)r
   Zos_archcompilerplatformr8   r8   r9   detect_windows_archx   s    	rU   c             C   s   t  j   r t |   } n t j   j   } | j d  rO | j d  rO d S| j d  rb d S| d	 k rw d } n  | d k r xC |  j   D]5 } y | j	 d  r d SWq t  j
 k
 r Yq Xq Wd S| S)
z
    Python is inconsistent in its platform module.
    It returns different values for the same cpu.
    For x86 it might return 'x86', 'i686' or somesuch.
    Do some canonicalization.
    iZ86rM   ZarmrL   x64x86_64rO   )zamd64rW   )r   
is_windowsrU   rT   machinerI   
startswithendswithrP   rR   MesonException)r
   trialr2   r8   r8   r9   detect_cpu_family   s$    		r_   c             C   s   t  j   r t |   } n t j   j   } | d k rB d } n  | d k r xC |  j   D]5 } y | j d  rw d SWq[ t  j k
 r Yq[ Xq[ Wd S| S)NrL   rW   rX   rO   Zi686)zamd64zx64)	r   rY   rU   rT   rZ   rI   rP   rR   r]   )r
   r^   r2   r8   r8   r9   
detect_cpu   s    		r`   c              C   s)   t  j   j   }  |  j d  r% d S|  S)Ncygwin)rT   systemrI   r[   )rb   r8   r8   r9   detect_system   s    rc   c             C   s;   |  s t  j   S| j j   r7 | j j d d d k Sd S)zg
    Host machine is windows?

    Note: 'host' is the machine on which compiled binaries will run
    host_machinerb   windowsF)r   rY   
cross_infohas_hostconfig)is_crossenvr8   r8   r9   for_windows   s
    
rk   c             C   s;   |  s t  j   S| j j   r7 | j j d d d k Sd S)zf
    Host machine is cygwin?

    Note: 'host' is the machine on which compiled binaries will run
    rd   rb   ra   F)r   	is_cygwinrf   rg   rh   )ri   rj   r8   r8   r9   
for_cygwin   s
    
rm   c             C   s;   |  s t  j   S| j j   r7 | j j d d d k Sd S)zq
    Host machine is Darwin (iOS/OS X)?

    Note: 'host' is the machine on which compiled binaries will run
    rd   rb   darwinF)r   Zis_osxrf   rg   rh   )ri   rj   r8   r8   r9   
for_darwin   s
    
ro   c             C   s/   d } t  j | |   } | r+ | j d  Sd S)Nz-(?<!(\d|\.))(\d{1,2}(\.\d+)+(-[a-zA-Z0-9]+)?)r   zunknown version)researchgroup)textZversion_regexmatchr8   r8   r9   search_version  s
    ru   c               @   s  e  Z d  Z d Z d Z e j j e d  Z d d   Z	 d d   Z
 d d	   Z d
 d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d  d!   Z e d" d#    Z e d$ d%    Z e d& d'    Z d( d)   Z d* d+ d,  Z d- d.   Z d/ d0   Z d1 d2   Z  d3 d4   Z! d5 d6   Z" d7 d8   Z# d9 d:   Z$ d; d<   Z% d= d>   Z& d? d@   Z' dA dB   Z( dC dD   Z) dE dF   Z* dG dH   Z+ dI dJ   Z, dK dL   Z- dM dN   Z. dO dP   Z/ dQ dR   Z0 dS dT   Z1 dU dV   Z2 dW dX   Z3 dY dZ   Z4 d[ d\   Z5 d] d^   Z6 d_ d`   Z7 da db   Z8 dc dd   Z9 de df   Z: dg dh   Z; di dj   Z< dk S)lEnvironmentzmeson-privatez
meson-logszcoredata.datc             C   s  | |  _  | |  _ | |  _ t j j | t j  |  _ t j j | t j	  |  _	 t j
 |  j d d t j
 |  j	 d d y= t j j |  j   t j  } t j |  |  _ d |  _ Wn< t k
 r t j |  |  _ |  j |  j _ d |  _ Yn X|  j j rt |  j j  |  _ n	 d  |  _ | |  _ | |  _ t j   rqd d d d g |  _ d d d	 d
 g |  _ n$ d d d g |  _ d d	 d
 g |  _ d g |  _ d g |  _ d d d d d d g |  _ d g |  _ d g |  _ d g |  _  d g |  _! |  j"   } | rt j   sF| rd|  j j#   rd|  j j$ d d d k rdd |  _% d |  _& d |  _' n{ | rwt j(   s| r|  j j#   r|  j j$ d d d k rd |  _% d |  _& d |  _' n d |  _% d |  _& d |  _' d t j) k rt* j+ d  |  _, n d g |  _, d  S)Nexist_okTFclZccrN   clangzc++zg++zclang++ZgfortranZg95Zf95Zf90Zf77Zifortarlibzgcc-arzllvm-arrd   rb   re   exeobjra   orE   ZSTRIPstrip)-
source_dir	build_dirmeson_script_launcherrF   pathjoinrv   private_dirscratch_dirlog_dirmakedirsget_build_dircoredata_filer   loadZfirst_invocationr=   ZCoreDataZ
cross_fileCrossBuildInforf   Zcmd_line_optionsoriginal_cmd_line_argsr   rY   Z	default_cZdefault_cppZdefault_objcZdefault_objcppZdefault_fortrandefault_static_linkervs_static_linkergcc_static_linkerclang_static_linkeris_cross_buildrg   rh   
exe_suffixobject_suffixwin_libdir_layoutrl   rG   shlexsplitZnative_strip_bin)selfr   r   Zmain_script_launcheroptionsr   cdfZcrossr8   r8   r9   __init__  sb    						/		/					zEnvironment.__init__c             C   s   |  j  d  k	 S)N)rf   )r   r8   r8   r9   r   Y  s    zEnvironment.is_cross_buildc             C   sN   t  j j |  j   t j  } t j |  j |  t  j | d | | f | S)Ntimes)	rF   r   r   r   rv   r   r   saveutime)r   mtimer   r8   r8   r9   dump_coredata\  s    zEnvironment.dump_coredatac             C   s"   d d  l  } t j j | j j  S)Nr   )Zmesonbuild.scriptsrF   r   dirnamescripts__file__)r   
mesonbuildr8   r8   r9   get_script_dirb  s    zEnvironment.get_script_dirc             C   s   |  j  S)N)r   )r   r8   r8   r9   get_log_dirf  s    zEnvironment.get_log_dirc             C   s   |  j  S)N)r   )r   r8   r8   r9   get_coredatai  s    zEnvironment.get_coredatac             C   s   |  j  S)N)r   )r   r8   r8   r9   get_build_commandl  s    zEnvironment.get_build_commandc             C   s
   t  |  S)N)r   )r   fnamer8   r8   r9   r   o  s    zEnvironment.is_headerc             C   s
   t  |  S)N)r   )r   r   r8   r8   r9   r   r  s    zEnvironment.is_sourcec             C   s
   t  |  S)N)r   )r   r   r8   r8   r9   r   u  s    zEnvironment.is_assemblyc             C   s
   t  |  S)N)r   )r   r   r8   r8   r9   r   x  s    zEnvironment.is_llvm_irc             C   s
   t  |  S)N)r   )r   r   r8   r8   r9   r   {  s    zEnvironment.is_objectc             C   s
   t  |  S)N)r   )r   r   r8   r8   r9   r   ~  s    zEnvironment.is_libraryc             C   sy   d | } d | } d } xX |  j  D]M } | j |  sH | j |  rL d S| re | j |  re d S| d k } q$ Wd S)Nz--z-DFT)r   r[   )r   optionZtrial1Ztrial2Zprevious_is_plaindrV   r8   r8   r9   had_argument_for  s    

zEnvironment.had_argument_forc             C   s   xz | j    D]l \ } } | |  j j k r> | |  j j | <q |  j j | } t |  t |  k r | |  j j | <q q Wd  S)N)itemsr   Zuser_optionstype)r   r   namevalueZoldvalr8   r8   r9   merge_options  s    zEnvironment.merge_optionsc       	      C   s   |  d d d g } t  | d d d t j \ } } } | j d k r] t d | |   n  i  } x | j d	  D] } | s qs n  | j d
 d  ^ } } | d k r qs n  t |  d k r d | | <n  t |  d k rs | d | | d <qs qs W| S)zH
        Detect GNU compiler platform type (Apple, MinGW, Unix)
        z-Ez-dM-writerE   stdinr   z$Unable to detect GNU compiler type:

 r<   z#definer   T)r   
subprocessPIPEr?   r   r   len)	rS   argsrB   outputerrordefinesliner7   restr8   r8   r9   get_gnu_compiler_defines  s     $z$Environment.get_gnu_compiler_definesc             C   sR   d } |  j  d d  } |  j  d d  } |  j  d d  } | j | | | f  S)N.Z__GNUC__0Z__GNUC_MINOR__Z__GNUC_PATCHLEVEL__)rH   r   )r   dotmajorminorZpatchr8   r8   r9   get_gnu_version_from_defines  s
    z(Environment.get_gnu_version_from_definesc             C   s@   d |  k r t  Sd |  k s( d |  k r, t Sd |  k r< t St S)NZ	__APPLE__Z__MINGW32__Z__MINGW64__Z
__CYGWIN__)r   r   r   r   )r   r8   r8   r9   get_gnu_compiler_type  s    z!Environment.get_gnu_compiler_typec             C   sW  |  j    r | r t j |  j j d |  } | d d k r^ | d d  } |  j   } n g  } | g } d } |  j j   r |  j j d j d d  } qGg  } n | t j	 k rt
 j t j	 |  } | d d k r | d d  } |  j   } n g  } | g } d } d } n+ t |  d	 |  } |  j   } d } d } | | | | f S)
z
        The list of compilers is detected in the exact same way for
        C, C++, ObjC, ObjC++, Fortran so consolidate it here.
        binariesr   ccacher   NTZexe_wrapperFZdefault_)r   r   stringlistifyrf   rh   detect_ccacheneed_exe_wrapperrH   rF   rG   r   r   getattr)r   langevar
want_crossr
   r   ri   exe_wrapr8   r8   r9   _get_compilers  s2    				zEnvironment._get_compilersrS   c             C   sh   d j  | |  } | rX | d 7} x3 | j   D]" \ } } | d j  | |  7} q/ Wn  t |   d  S)NzUnknown {}(s): {}z(
The follow exceptions were encountered:z
Running "{0}" gave "{1}")formatr   r   )r   
exceptionsr   ZbintypeZerrmsgr2   er8   r8   r9   _handle_exceptions  s    
zEnvironment._handle_exceptionsc             C   s  i  } |  j  | | |  \ } } } } x`| D]X}	 t |	 t  rO |	 g }	 n  d |	 k sg d |	 k r d t j k r d d   }
 |
 t j j t j d d d   |
 t j j t j d d d   g } |
 t j d   } | | k r q. q n  d } n d } y  t	 |	 | g  \ } } } WnB t
 k
 ri} z" | | d	 j |	 | g  <w. WYd  d  } ~ Xn Xt |  } d
 | k r|  j |	  } | sd | d	 j |	  <q. n  |  j |  } |  j |  } | d k rt n t } | | |	 | | | | |  Sd | k rd | k s*t | |   r3t } n* d | k sNt | |   rWt } n t } | d k rot n t } | | |	 | | | |  Sd | k sd | k rBt |  } | d k rt |  } n  | d k rd } t | j |    n  | j d  d j d  } | d k r&t n t } | |	 | | | |  Sd | k r. t } | d k rft n t  } | | |	 | | | |  Sq. W|  j! | |  d  S)Nrx   zcl.exeZWATCOMc             S   s   t  j j t  j j |    S)N)rF   r   normcaseabspath)rB   r8   r8   r9   sanitize  s    z7Environment._detect_c_or_cpp_compiler.<locals>.sanitizeZBINNTz/?z	--versionr   zFree Software Foundationzno pre-processor definesr2   ry   ZApplere   Z	Microsoftzunknown versionz4Failed to detect MSVC compiler arch: stderr was
{!r}r   r   z x64z(ICC))"r   
isinstancestrrF   rG   r   r   shutilwhichr   OSErrorru   r   r   r   r   r   ro   r   rk   r   r   r   r   r   r   r   r\   r/   r0   r   r#   r$   r   )r   r   r   r   popen_exceptionsr
   r   ri   r   rS   r   Z
watcom_clsZfound_clargrB   outerrr   r@   r   gtypeclsZcltypemZis_64Z	inteltyper8   r8   r9   _detect_c_or_cpp_compiler  sj    !
"(		 		z%Environment._detect_c_or_cpp_compilerc             C   s   |  j  d d |  S)Nr2   CC)r   )r   r   r8   r8   r9   detect_c_compiler<  s    zEnvironment.detect_c_compilerc             C   s   |  j  d d |  S)Nr3   CXX)r   )r   r   r8   r8   r9   detect_cpp_compiler?  s    zEnvironment.detect_cpp_compilerc             C   sE  i  } |  j  d d |  \ } } } } x| D]} t | t  rO | g } n  xd d g D]} y  t | | g  \ }	 }
 } WnB t k
 r } z" | | d j | | g  <w\ WYd  d  } ~ Xn Xt |
  } d |
 k rD|  j |  } | sd | d j |  <q\ n  |  j |  } |  j	 |  } t
 | | | | | |  Sd |
 k rct | | | |  Sd	 | k rt |  } t | | | |  Sd
 |
 k rt | | | |  Sd | k rt | | | |  Sd |
 k rt | | | |  Sd | k r
t | | | |  Sd | k r\ t | | | |  Sq\ Wq. W|  j | |  d  S)Nr6   ZFCz	--versionz-Vr   zGNU Fortranzno pre-processor definesZG95zSun Fortranzifort (IFORT)zPathScale EKOPath(tm)zPGI CompilerszOpen64 Compiler SuitezNAG Fortran)r   r   r   r   r   r   ru   r   r   r   r    r   r-   r%   r*   r+   r)   r(   r   )r   r   r   r
   r   ri   r   rS   r   rB   r   r   r   r@   r   r   r8   r8   r9   detect_fortran_compilerB  sH    ! z#Environment.detect_fortran_compilerc             C   s   |  j  S)N)r   )r   r8   r8   r9   get_scratch_dirq  s    zEnvironment.get_scratch_dirc             C   s)   t  j j t  d } t  j j | d  S)Nr   zdepfixer.py)rF   r   r   r   r   )r   r   r8   r8   r9   get_depfixert  s    zEnvironment.get_depfixerc             C   s  i  } |  j  d d |  \ } } } } xa| D]Y} t | t  rO | g } n  d g } y t | |  \ }	 }
 } Wn< t k
 r } z | | d j | |  <WYd  d  } ~ Xn Xt |
  } d |
 k r5|  j |  } | s d | d j |  <q. n  |  j |  } |  j	 |  } t
 | | | | | | |  S|
 j d  r^t | | | t | |  S|
 j d  r. t | | | t | |  Sq. W|  j | |  d  S)	Nr4   ZOBJCz	--versionr   zFree Software Foundationzno pre-processor definesz
Apple LLVMry   )r   r   r   r   r   r   ru   r   r   r   r!   r[   r   r   r   r   )r   r   r   r
   r   ri   r   rS   r   rB   r   r   r   r@   r   r   r8   r8   r9   detect_objc_compilerx  s0    !	*z Environment.detect_objc_compilerc             C   s  i  } |  j  d d |  \ } } } } xa| D]Y} t | t  rO | g } n  d g } y t | |  \ }	 }
 } Wn< t k
 r } z | | d j | |  <WYd  d  } ~ Xn Xt |
  } d |
 k r5|  j |  } | s d | d j |  <q. n  |  j |  } |  j	 |  } t
 | | | | | | |  S|
 j d  r^t | | | t | |  S|
 j d  r. t | | | t | |  Sq. W|  j | |  d  S)	Nr5   ZOBJCXXz	--versionr   zFree Software Foundationzno pre-processor definesz
Apple LLVMry   )r   r   r   r   r   r   ru   r   r   r   r"   r[   r   r   r   r   )r   r   r   r
   r   ri   r   rS   r   rB   r   r   r   r@   r   r   r8   r8   r9   detect_objcpp_compiler  s0    !	*z"Environment.detect_objcpp_compilerc             C   s   d g } y  t  | d g  \ } } } Wn+ t k
 rV t d d j |    Yn Xt |  } d | k r| t | |  St d d j |  d   d  S)NZjavacz-versionz$Could not execute Java compiler "%s"r   zUnknown compiler "")r   r   r   r   ru   r&   )r   exelistrB   r   r   r@   r8   r8   r9   detect_java_compiler  s    	 z Environment.detect_java_compilerc             C   s   d g } y  t  | d g  \ } } } Wn+ t k
 rV t d d j |    Yn Xt |  } d | k r| t | |  St d d j |  d   d  S)NZmcsz	--versionz"Could not execute C# compiler "%s"r   ZMonozUnknown compiler "r   )r   r   r   r   ru   r'   )r   r   rB   r   r   r@   r8   r8   r9   detect_cs_compiler  s    	 zEnvironment.detect_cs_compilerc             C   s   d t  j k r( t j t  j d  } n	 d g } y' t | d g  d d  \ } } Wn+ t k
 r t d d j |    Yn Xt |  } d | k r t	 | |  St d	 d j |  d
   d  S)NZVALACZvalacz	--versionr   r<   z$Could not execute Vala compiler "%s"r   ZValazUnknown compiler "r   )
rF   rG   r   r   r   r   r   r   ru   r.   )r   r   rB   r   r@   r8   r8   r9   detect_vala_compiler  s    	'z Environment.detect_vala_compilerc             C   s   d g } y' t  | d g  d d  \ } } Wn+ t k
 r] t d d j |    Yn Xt |  } d | k r t | |  St d d j |  d   d  S)	NZrustcz	--versionr   r<   z$Could not execute Rust compiler "%s"r   zUnknown compiler "r   )r   r   r   r   ru   r,   )r   r   rB   r   r@   r8   r8   r9   detect_rust_compiler  s    	'z Environment.detect_rust_compilerc             C   s  d } d t  j k r. t j t  j d  } n |  j   rf | rf t j |  j j d d  } d } nx t	 j
 d  r d g } n] t	 j
 d  r d g } nB t	 j
 d  r d g } n' t	 j
 d	  r d	 g } n t d
   y' t | d g  d d  \ } } Wn+ t k
 r2t d d j |    Yn Xt |  } d | k r^t j | | |  Sd | k r}t j | | |  Sd | k rt j | | |  St d d j |  d   d  S)NFZDCr   r7   TZldc2ZldcZgdcZdmdz(Could not find any supported D compiler.z	--versionr   r<   z!Could not execute D compiler "%s"r   zLLVM D compilerzDigital MarszUnknown compiler "r   )rF   rG   r   r   r   r   r   rf   rh   r   r   r   r   r   r   ru   r
   ZLLVMDCompilerZGnuDCompilerZDmdDCompiler)r   r   ri   r   rB   r   r@   r8   r8   r9   detect_d_compiler  s6    	'zEnvironment.detect_d_compilerc             C   s   d g } y  t  | d g  \ } } } Wn+ t k
 rV t d d j |    Yn Xt |  } d | k r t j | |  St d d j |  d   d  S)NZswiftcz-vz%Could not execute Swift compiler "%s"r   ZSwiftzUnknown compiler "r   )r   r   r   r   ru   r
   ZSwiftCompiler)r   r   rB   _r   r@   r8   r8   r9   detect_swift_compiler  s    	 z!Environment.detect_swift_compilerc             C   s&  | j  rD |  j j d d } t | t  r8 | g } n  | g } n d } | t j k ru t j t j |  g } n{ t | t	 j
  r |  j g } nZ t | t	 j  r |  j |  j g } n3 t | t	 j  r |  j |  j g } n |  j g } i  } x | D] } d | k sd | k r$d } n d } y  t | | g  \ } } }	 WnB t k
 r}
 z" |
 | d j | | g  <w WYd  d  }
 ~
 Xn Xd	 | k sd	 |	 k rt |  S| j d
 k rt |  S| j d k r |	 j d  r t |  Sq W|  j | | d  t d d j |    d  S)Nr   rz   ARr{   zlib.exez/?z	--versionr   z/OUT:r   r   usagelinkerzUnknown static linker "%s")ri   rf   rh   r   r   rF   rG   r   r   r
   r/   r   ZGnuCompilerr   r   ZClangCompilerr   r   r   r   r   r?   r   r[   r   r   )r   rS   r   linkersr   r   r   rB   r   r   r   r8   r8   r9   detect_static_linker	  sB    		 

z Environment.detect_static_linkerc             C   sh   y+ t  j d d g d t  j d t  j } Wn t k
 rE d } Yn X| d k r^ d g } n g  } | S)Nr   z	--versionstdoutstderrr   r   )r   callr   r   )r   Z
has_ccacheZcmdlistr8   r8   r9   r   1  s    +zEnvironment.detect_ccachec             C   s   |  j  S)N)r   )r   r8   r8   r9   get_source_dir<  s    zEnvironment.get_source_dirc             C   s   |  j  S)N)r   )r   r8   r8   r9   r   ?  s    zEnvironment.get_build_dirc             C   s   |  j  S)N)r   )r   r8   r8   r9   get_exe_suffixB  s    zEnvironment.get_exe_suffixc             C   s
   |  j    S)z=Install dir for the import library (library used for linking))
get_libdir)r   r8   r8   r9   get_import_lib_dirE  s    zEnvironment.get_import_lib_dirc             C   s
   |  j    S)z9Install dir for shared modules that are loaded at runtime)r  )r   r8   r8   r9   get_shared_module_dirI  s    z!Environment.get_shared_module_dirc             C   s   |  j  r |  j   S|  j   S)z"Install dir for the shared library)r   
get_bindirr  )r   r8   r8   r9   get_shared_lib_dirM  s    	
zEnvironment.get_shared_lib_dirc             C   s
   |  j    S)z"Install dir for the static library)r  )r   r8   r8   r9   get_static_lib_dirS  s    zEnvironment.get_static_lib_dirc             C   s   |  j  S)N)r   )r   r8   r8   r9   get_object_suffixW  s    zEnvironment.get_object_suffixc             C   s   |  j  j d  S)Nprefix)r   get_builtin_option)r   r8   r8   r9   
get_prefixZ  s    zEnvironment.get_prefixc             C   s   |  j  j d  S)Nlibdir)r   r
  )r   r8   r8   r9   r  ]  s    zEnvironment.get_libdirc             C   s   |  j  j d  S)N
libexecdir)r   r
  )r   r8   r8   r9   get_libexecdir`  s    zEnvironment.get_libexecdirc             C   s   |  j  j d  S)Nbindir)r   r
  )r   r8   r8   r9   r  c  s    zEnvironment.get_bindirc             C   s   |  j  j d  S)N
includedir)r   r
  )r   r8   r8   r9   get_includedirf  s    zEnvironment.get_includedirc             C   s   |  j  j d  S)Nmandir)r   r
  )r   r8   r8   r9   
get_mandiri  s    zEnvironment.get_mandirc             C   s   |  j  j d  S)Ndatadir)r   r
  )r   r8   r8   r9   get_datadirl  s    zEnvironment.get_datadirN)=__name__
__module____qualname__r   r   rF   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r8   r8   r8   r9   rv     sl   @	'I/#(rv   c             C   s;  d d   } |  j    } d } t |  d  rH |  j   |  j   k } n  | t k ra g  g  g  f St j j t | d  } | t | |  t j	 |  } t j j d d  } | d |  t j	 |  } | r | | } n  d } | d k rt j j d d  } n  | d |  t j	 |  } | | 7} | | | f S)z
    @compiler: Compiler to fetch environment flags for

    Returns a tuple of (compile_flags, link_flags) for the specified language
    from the inherited environment
    c             S   s&   | r" t  j d j |  |   n  d  S)Nz#Appending {} from environment: {!r})r	   logr   )varvalr8   r8   r9   log_varw  s    z&get_args_from_envvars.<locals>.log_varFget_linker_exelistrE   LDFLAGSr2   r3   r4   r5   CPPFLAGS)r2   zcppzobjczobjcpp)
Zget_languagehasattrZget_exelistr  cflags_mappingrF   rG   rH   r   r   )rS   r  r   Zcompiler_is_linkerZcompile_flagsZ
link_flagsZpreproc_flagsr8   r8   r9   get_args_from_envvarsp  s,    
r#  c               @   s   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z d d   Z	 d d   Z
 d d   Z d d   Z d S)r   c             C   sv   i i  d 6|  _  |  j |  d |  j  k r0 d  Sd |  j  k rQ t j d   n  d |  j  k rr t j d   n  d  S)N
propertiestarget_machinerd   z:Cross info file must have either host or a target machine.r   z!Cross file is missing "binaries".)rh   parse_datafiler   r]   )r   filenamer8   r8   r9   r     s    zCrossBuildInfo.__init__c             C   s   t  | t t t f  S)N)r   r   intbool)r   rV   r8   r8   r9   ok_type  s    zCrossBuildInfo.ok_typec       	      C   s  t  j   } y, t | d   } | j | |  Wd  QXWn" t k
 r\ t d |   Yn Xx`| j   D]R} i  |  j | <x<| | D]0} | | | } d | k s d | k s d | k s d | k r t d |   n  y+ t | i d  d 6i d	 d
 6d d 6 } Wn" t	 k
 r.t d |   Yn X|  j
 |  rR| |  j | | <q t | t  rx0 | D]( } |  j
 |  sht d |   qhqhW| |  j | | <q t d |   q Wqj Wd  S)NrzFile not found: %s.r   	'r   z*Malformed variable name %s in cross file..__builtins__TtrueFZfalsez*Malformed value in cross file variable %s.)configparserConfigParseropenZ	read_filer=   r   Zsectionsrh   eval	Exceptionr*  r   list)	r   r'  rh   fsentryr   resrV   r8   r8   r9   r&    s0    0+zCrossBuildInfo.parse_datafilec             C   s   d |  j  k S)Nrd   )rh   )r   r8   r8   r9   rg     s    zCrossBuildInfo.has_hostc             C   s   d |  j  k S)Nr%  )rh   )r   r8   r8   r9   
has_target  s    zCrossBuildInfo.has_targetc             C   s   | d |  j  d k S)N_stdlibr$  )rh   )r   languager8   r8   r9   
has_stdlib  s    zCrossBuildInfo.has_stdlibc             C   s   |  j  d | d S)Nr$  r;  )rh   )r   r<  r8   r8   r9   
get_stdlib  s    zCrossBuildInfo.get_stdlibc             C   s   |  j  d S)Nr$  )rh   )r   r8   r8   r9   get_properties  s    zCrossBuildInfo.get_propertiesc             C   s   d |  j  k S)Nrd   )rh   )r   r8   r8   r9   need_cross_compiler  s    z"CrossBuildInfo.need_cross_compilerc             C   s   |  j  d j d d   } | d  k	 r) | S|  j   r| t i   d k r| |  j  d d d k r| |  j  d d t   k r| d Sd	 S)
Nr$  Zneeds_exe_wrapperrX   rd   
cpu_familyrM   rb   FT)rh   rH   rg   r_   rc   )r   r   r8   r8   r9   r     s    zCrossBuildInfo.need_exe_wrapperN)r  r  r  r   r*  r&  rg   r:  r=  r>  r?  r@  r   r8   r8   r8   r9   r     s   
r   c               @   s   e  Z d  Z d d   Z d S)MachineInfoc             C   s(   | |  _  | |  _ | |  _ | |  _ d  S)N)rb   rA  cpuendian)r   rb   rA  rC  rD  r8   r8   r9   r     s    			zMachineInfo.__init__N)r  r  r  r   r8   r8   r8   r9   rB    s   rB  )Hr0  rF   rT   rp   r   r   r   rE   r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   build_filenamer"  r:   rD   rK   rU   r_   r`   rc   rk   rm   ro   ru   rv   r#  r   rB  r8   r8   r8   r9   <module>   sB   T^

)   ^,M