
ŝY|                 @   s?  d  d l  Z  d  d l Z d  d l Z d d l m Z d d l m Z d d l 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 Gd d	   d	 e  Z Gd
 d   d e e  Z Gd d   d e e  Z Gd d   d e e  Z Gd d   d e  Z d S)    N   )mlog)coredata)EnvironmentExceptionversion_compare
Popen_safe   )	GCC_MINGWget_largefile_argsgnu_winlibsmsvc_buildtype_argsmsvc_buildtype_linker_argsmsvc_winlibsvs32_instruction_set_argsvs64_instruction_set_argsClangCompilerCompilerCompilerArgsCrossNoRunExceptionGnuCompilerIntelCompiler	RunResultc                   s^  e  Z d  Z d   f 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 d  d!   Z d" d#   Z d$ d%   Z d& d'   Z d( d)   Z d* d+   Z d, d-   Z d. d/   Z d0 d1   Z d2 d3   Z d4 d5   Z d6 d7   Z d8 d9   Z d: d;   Z d< d=   Z  d> d?   Z! d@ dA   Z" dB dC   Z# dD dE   Z$ dF dG   Z% dH dI   Z& dJ dK   Z' d d dL dM  Z( d d dN dO  Z) dP dQ dR  Z* d d dP dS dT  Z+ dU dV   Z, d d dW dX  Z- d d dY dZ  Z. d[ d\   Z/ d] d^   Z0 d d d_ d`  Z1 d d da db  Z2 d d dc dd  Z3 d d de df  Z4 d d dg dh  Z5 di dj   Z6 e7 dk dl    Z8 e7 dm dn    Z9 d d do dp  Z: d d dq dr  Z; d ds dt  Z< du dv   Z= dw dx   Z> dy dz   Z? d{ d|   Z@ d} d~   ZA   S)	CCompilerNc                s{   t  |  d  s d |  _ n  t   j | |  d |  _ | |  _ |  j j d  t | t	  rn | g |  _
 n	 | |  _
 d  S)Nlanguagecunknownh)hasattrr   super__init__idis_crosscan_compile_suffixesadd
isinstancestrexe_wrapper)selfexelistversionr!   r&   )	__class__ R/mnt/raid6/a/bak/reczko/tools/protein/utils/meson-0.42.1/mesonbuild/compilers/c.pyr   )   s    		zCCompiler.__init__c             C   s   d S)NTr+   )r'   r+   r+   r,   needs_static_linker6   s    zCCompiler.needs_static_linkerc             C   s   d g t  |   S)zM
        Args that are always-on for all C compilers other than MSVC
        z-pipe)r
   )r'   r+   r+   r,   get_always_args9   s    zCCompiler.get_always_argsc             C   s   g  S)zl
        Arguments needed to select a debug crt for the linker
        This is only needed for MSVC
        r+   )r'   r+   r+   r,   get_linker_debug_crt_args?   s    z#CCompiler.get_linker_debug_crt_argsc             C   s   d g S)Nz	-nostdincr+   )r'   r+   r+   r,   get_no_stdinc_argsF   s    zCCompiler.get_no_stdinc_argsc             C   s   d g S)Nz	-nostdlibr+   )r'   r+   r+   r,   get_no_stdlib_link_argsI   s    z!CCompiler.get_no_stdlib_link_argsc             C   s   |  j  | S)N)	warn_args)r'   levelr+   r+   r,   get_warn_argsL   s    zCCompiler.get_warn_argsc             C   s   d g S)Nz-wr+   )r'   r+   r+   r,   get_no_warn_argsO   s    zCCompiler.get_no_warn_argsc             C   s   g  S)Nr+   )r'   prefix
shlib_namesuffixpath	soversionis_shared_moduler+   r+   r,   get_soname_argsS   s    zCCompiler.get_soname_argsc             C   s
   d  | f S)Nr+   )r'   fnamer+   r+   r,   split_shlib_to_partsV   s    zCCompiler.split_shlib_to_partsc             C   s   |  j  | | | | |  S)N)build_unix_rpath_args)r'   	build_dirfrom_dirrpath_pathsbuild_rpathinstall_rpathr+   r+   r,   build_rpath_argsZ   s    zCCompiler.build_rpath_argsc             C   s   d d | d | g S)Nz-MMDz-MQz-MFr+   )r'   	outtargetoutfiler+   r+   r,   get_dependency_gen_args]   s    z!CCompiler.get_dependency_gen_argsc             C   s   | d |  j    S)N.)get_depfile_suffix)r'   Zobjfiler+   r+   r,   depfile_for_object`   s    zCCompiler.depfile_for_objectc             C   s   d S)Ndr+   )r'   r+   r+   r,   rJ   c   s    zCCompiler.get_depfile_suffixc             C   s   |  j  d  d   S)N)r(   )r'   r+   r+   r,   get_exelistf   s    zCCompiler.get_exelistc             C   s   |  j  d  d   S)N)r(   )r'   r+   r+   r,   get_linker_exelisti   s    zCCompiler.get_linker_exelistc             C   s
   d d g S)Nz-Ez-Pr+   )r'   r+   r+   r,   get_preprocess_only_argsl   s    z"CCompiler.get_preprocess_only_argsc             C   s   d g S)Nz-cr+   )r'   r+   r+   r,   get_compile_only_argso   s    zCCompiler.get_compile_only_argsc             C   s   d g S)Nz-O0r+   )r'   r+   r+   r,   get_no_optimization_argsr   s    z"CCompiler.get_no_optimization_argsc             C   s
   |  j    S)z
        Get arguments useful for compiler checks such as being permissive in
        the code quality and not doing any optimization.
        )rQ   )r'   r+   r+   r,   get_compiler_check_argsu   s    z!CCompiler.get_compiler_check_argsc             C   s
   d | g S)Nz-or+   )r'   targetr+   r+   r,   get_output_args|   s    zCCompiler.get_output_argsc             C   s
   d | g S)Nz-or+   )r'   
outputnamer+   r+   r,   get_linker_output_args   s    z CCompiler.get_linker_output_argsc             C   s   d g S)Nz
--coverager+   )r'   r+   r+   r,   get_coverage_args   s    zCCompiler.get_coverage_argsc             C   s   d g S)Nz
--coverager+   )r'   r+   r+   r,   get_coverage_link_args   s    z CCompiler.get_coverage_link_argsc             C   s   d g S)Nz-Werrorr+   )r'   r+   r+   r,   get_werror_args   s    zCCompiler.get_werror_argsc             C   s   g  S)Nr+   )r'   r+   r+   r,   get_std_exe_link_args   s    zCCompiler.get_std_exe_link_argsc             C   s0   | d k r d } n  | r% d | g Sd | g S)N rI   z-isystemz-Ir+   )r'   r9   	is_systemr+   r+   r,   get_include_args   s
    	
zCCompiler.get_include_argsc             C   s   d g S)Nz-sharedr+   )r'   r+   r+   r,   get_std_shared_lib_link_args   s    z&CCompiler.get_std_shared_lib_link_argsc             C   sj   t  |  j d g  d } xI | j d  D]8 } | j d  r* | j d d  d } | j d  Sq* Wg  S)Nz--print-search-dirsr   
z
libraries:=:)r   r(   split
startswith)r'   stdolineZlibstrr+   r+   r,   get_library_dirs   s    zCCompiler.get_library_dirsc             C   s   d g S)Nz-fPICr+   )r'   r+   r+   r,   get_pic_args   s    zCCompiler.get_pic_argsc             C   s   d j  |  j  S)N )joinr(   )r'   r+   r+   r,   name_string   s    zCCompiler.name_stringc             C   s   d t  j j |  d g S)Nz-includer   )osr9   rb   )r'   pch_dirheaderr+   r+   r,   get_pch_use_args   s    zCCompiler.get_pch_use_argsc             C   s"   t  j j |  d d |  j   S)Nr   rI   rk   )rl   r9   rb   get_pch_suffix)r'   header_namer+   r+   r,   get_pch_name   s    zCCompiler.get_pch_namec             C   s   d | g S)Nz-Lr+   )r'   dirnamer+   r+   r,   get_linker_search_args   s    z CCompiler.get_linker_search_argsc             C   s   d | g S)z
        The name of the outputted import library

        This implementation is used only on Windows by compilers that use GNU ld
        z-Wl,--out-implib=r+   )r'   
implibnamer+   r+   r,   gen_import_library_args   s    z!CCompiler.gen_import_library_argsc          
   C   s  t  j d |  j   d d j |  j   t  j d t |  j   g  } t j j | |  } | j	 d d  d } |  j r | d 7} |  j
 d  k r | |  j | d	 d
 7} | |  j   7} q | |  j | d	 d 7} n  | d 7} t j j | |  } t | d   }	 |	 j |  Wd  QX|  j | | g |  j |  }
 t |
 d | \ } } } t  j d d j |
   t  j d  t  j |  t  j d  t  j |  t  j d  | j d k rt d j |  j      n  |  j r|  j
 d  k rd  S|  j
 | g }
 n	 | g }
 t  j d d j |
   t j |
  } | j   | j d k rt d j |  j |  j      n  d  S)NzSanity testing z
 compiler:rh   zIs cross compiler: %s.rI   r   r   Z_crosslinkFTz.exewcwdz#Sanity check compiler command line:zSanity check compile stdout:z"-----
Sanity check compile stderr:z-----z&Compiler {0} can not compile programs.zRunning test binary command: z9Executables created by {0} compiler {1} are not runnable.)r   debugget_display_languageri   r(   r%   r!   rl   r9   rsplitr&   get_cross_extra_flagsrP   openwriterT   r   
returncoder   formatrj   
subprocessPopenwaitr   )r'   work_direnvironmentZsnamecodeextra_flagsZsource_nameZbinnameZbinary_nameofilecmdlistpcrd   stdeper+   r+   r,   sanity_check_impl   sF    *	

!		
zCCompiler.sanity_check_implc             C   s   d } |  j  | | d |  S)Nz?int main(int argc, char **argv) { int class=0; return class; }
zsanitycheckc.c)r   )r'   r   r   r   r+   r+   r,   sanity_check   s    zCCompiler.sanity_checkc             C   s<   i | d 6| d 6} d } |  j  | j |   | | | d  S)Nr6   rn   z{prefix}
        #ifdef __has_include
         #if !__has_include("{header}")
          #error "Header '{header}' could not be found"
         #endif
        #else
         #include <{header}>
        #endif
preprocess)compilesr   )r'   hnamer6   env
extra_argsdependenciesfargsr   r+   r+   r,   
has_header   s    zCCompiler.has_headerc       	      C   s@   i | d 6| d 6| d 6} d } |  j  | j |   | | |  S)Nr6   rn   symbolz{prefix}
        #include <{header}>
        int main () {{
            /* If it's not defined as a macro, try to use as a symbol */
            #ifndef {symbol}
                {symbol};
            #endif
        }})r   r   )	r'   r   r   r6   r   r   r   r   tr+   r+   r,   has_header_symbol   s    zCCompiler.has_header_symbolcompilec             C   s  | d  k r g  } n t  | t  r0 | g } n  | d  k rE g  } n t  | t  s` | g } n  t |   } x{ | D]s } | | j   7} | j   r | |  j   7} n  | d k rs | | j   7} | j   r | |  j   7} q qs qs W| d k r	| |  j	   7} n  | |  j
 | d | d k 7} |  j s| d k rW| | j j |  j 7} q| d k r}| | j j |  j 7} q| d k r| | j j |  j 7} qn  | |  j   7} | | 7} | S)Nrw   r   r   )r$   r%   listr   Zget_compile_argsZneed_threadsthread_flagsZget_link_argsthread_link_flagsr/   r}   r!   r   external_preprocess_argsr   external_argsexternal_link_argsrR   )r'   r   r   r   modeargsrL   r+   r+   r,   _get_compiler_check_args  s<    			
z"CCompiler._get_compiler_check_argsc          	   C   sM   |  j  | | | |  } |  j | | j   |   } | j d k SWd  QXd  S)Nr   )r   r   	to_nativer   )r'   r   r   r   r   r   r   pr+   r+   r,   r   /  s    zCCompiler.compilesc             C   s+   |  j  | | | d d } |  j | |  S)z2Shares common code between self.links and self.runr   rw   )r   r   )r'   r   r   r   r   r   r+   r+   r,   _links_wrapper5  s    zCCompiler._links_wrapperc          	   C   s2   |  j  | | | |   } | j d k SWd  QXd  S)Nr   )r   r   )r'   r   r   r   r   r   r+   r+   r,   links:  s    zCCompiler.linksc             C   sR  |  j  r' |  j d  k r' t d   n  |  j | | | |   } | j d k rx t j d | j | j f  t d  S|  j  r |  j | j	 g } n	 | j	 } y t
 |  \ } } }	 WnF t k
 r}
 z& t j d | |
 f  t d  SWYd  d  }
 ~
 Xn XWd  QXt j d  t j |  t j d  t j |	  t d | j | |	  S)	Nz8Can not run test applications in this cross environment.r   z#Could not compile test file %s: %d
FzCould not run: %s (error: %s)
zProgram stdout:
zProgram stderr:
T)r!   r&   r   r   r   r   rz   
input_namer   output_namer   	Exception)r'   r   r   r   r   r   r   r   soZseer+   r+   r,   run>  s*    	
		#zCCompiler.runc             C   s9   i | d 6| d 6} d } |  j  | j |   | | |  S)Nr6   
expressionzq#include <stdio.h>
        {prefix}
        int main() {{ static int a[1-2*!({expression})]; a[0]=0; return 0; }})r   r   )r'   r   r6   r   r   r   r   r   r+   r+   r,   _compile_intW  s    zCCompiler._compile_intc	       
      C   s   t  | t  r; |  j d | | f | | | |  r; | Sn  | }	 xh | | k  r t | | d  }	 |	 | k rt Pn  |  j d | |	 f | | | |  r |	 } qD |	 } qD W|  j d | |	 f | | | |  r |	 St d   d  S)Nz%s == %dr   z%s >= %dzCross-compile check overflowed)r$   intr   r   )
r'   r   lowhighguessr6   r   r   r   Zcurr+   r+   r,   cross_compute_int^  s    %%	
%zCCompiler.cross_compute_intc	          	   C   s   | d  k r g  } n  |  j  r@ |  j | | | | | | | |  Si | d 6| d 6}	 d }
 |  j |
 j |	   | | |  } | j s d S| j d k r t d   n  t | j  S)Nr6   r   z#include<stdio.h>
        {prefix}
        int main(int argc, char **argv) {{
            printf("%ld\n", (long)({expression}));
            return 0;
        }};r   r   z&Could not run compute_int test binary.rk   )	r!   r   r   r   compiledr   r   r   stdout)r'   r   r   r   r   r6   r   r   r   r   r   resr+   r+   r,   compute_intr  s    		"!	zCCompiler.compute_intc          	   C   sz   | d  k r g  } n  i | d 6| d 6} d } |  j  | j |   | | |  sT d S|  j d | d d d  | | | |  S)Nr6   typezw#include <stdio.h>
        {prefix}
        int main(int argc, char **argv) {{
            {type} something;
        }}r   z
sizeof(%s)   rk   )r   r   r   )r'   typenamer6   r   r   r   r   r   r+   r+   r,   cross_sizeof  s    	!zCCompiler.cross_sizeofc       	      C   s   | d  k r g  } n  i | d 6| d 6} |  j  rK |  j | | | | |  Sd } |  j | j |   | | |  } | j s d S| j d k r t d   n  t | j  S)Nr6   r   z#include<stdio.h>
        {prefix}
        int main(int argc, char **argv) {{
            printf("%ld\n", (long)(sizeof({type})));
            return 0;
        }};r   r   z!Could not run sizeof test binary.rk   )	r!   r   r   r   r   r   r   r   r   )	r'   r   r6   r   r   r   r   r   r   r+   r+   r,   sizeof  s    		!	zCCompiler.sizeofc          	   C   s   | d  k r g  } n  i | d 6| d 6} d } |  j  | j |   | | |  sT d Sd } |  j d d d d  | j |   | | |  S)	Nr6   r   zw#include <stdio.h>
        {prefix}
        int main(int argc, char **argv) {{
            {type} something;
        }}r   zu#include <stddef.h>
        {prefix}
        struct tmp {{
            char c;
            {type} target;
        }};zoffsetof(struct tmp, target)i   rk   )r   r   r   )r'   r   r6   r   r   r   r   r   r+   r+   r,   cross_alignment  s    	!zCCompiler.cross_alignmentc       
      C   s   | d  k r g  } n  |  j  r7 |  j | | | | |  Si | d 6| d 6} d } |  j | j |   | | |  } | j s t d   n  | j d k r t d   n  t | j  }	 |	 d k r t d |   n  |	 S)Nr6   r   a  #include <stdio.h>
        #include <stddef.h>
        {prefix}
        struct tmp {{
            char c;
            {type} target;
        }};
        int main(int argc, char **argv) {{
            printf("%d", (int)offsetof(struct tmp, target));
            return 0;
        }}z!Could not compile alignment test.r   z$Could not run alignment test binary.zICould not determine alignment of %s. Sorry. You might want to file a bug.)	r!   r   r   r   r   r   r   r   r   )
r'   r   r6   r   r   r   r   r   r   Zalignr+   r+   r,   	alignment  s    		!	zCCompiler.alignmentc          
   C   s   d } i | d 6| d 6| d 6} d } |  j  | | | d d j   }	 |  j | j |   |	 d  . }
 |
 j d k r t d	 j |    n  Wd  QX|
 j j | d
  d d  d  S)Nz"MESON_GET_DEFINE_DELIMITER"r6   definedelimzl
        {prefix}
        #ifndef {define}
        # define {define}
        #endif
        {delim}
{define}r   r   r   zCould not get define {!r}r_   r   rk   rk   )r   r   r   r   r   r   rd   rb   )r'   Zdnamer6   r   r   r   r   r   r   r   r   r+   r+   r,   
get_define  s    !!zCCompiler.get_definec              C   s    d }  |  d 7}  d } |  | f S)a0  
        Try to find the function without a prototype from a header by defining
        our own dummy prototype and trying to link with the C library (and
        whatever else the compiler links in by default). This is very similar
        to the check performed by Autoconf for AC_CHECK_FUNCS.
        z
        #define {func} meson_disable_define_of_{func}
        {prefix}
        #include <limits.h>
        #undef {func}
        z^
        #ifdef __cplusplus
        extern "C"
        #endif
        char {func} ();
        z>
        int main () {{
          return {func} ();
        }}r+   )headmainr+   r+   r,   _no_prototype_templ  s
    zCCompiler._no_prototype_templc              C   s   d }  d } |  | f S)z
        Returns a head-er and main() call that uses the headers listed by the
        user for the function prototype while checking if a function exists.
        z{prefix}
#include <limits.h>
z{
int main() {{
            void *a = (void*) &{func};
            long b = (long) a;
            return (int) b;
        }}r+   )r   r   r+   r+   r,   _have_prototype_templ  s    		zCCompiler._have_prototype_templc             C   s[  | d k r g  } n  d | } | j  d d  } |  j r | j j d j | d  } | d k	 r t | t  ru | St d j |    q n  i | d 6| d 6} d	 }	 d
 | k r |  j	   \ }
 } n |  j
   \ }
 } |
 |	 | } |  j | j |   | | |  rd S|  j   d k r&d Sd
 | k | d <d } |  j | j |   | | |  S)ah  
        First, this function looks for the symbol in the default libraries
        provided by the compiler (stdlib + a few others usually). If that
        fails, it checks if any of the headers specified in the prefix provide
        an implementation of the function, and if that fails, it checks if it's
        implemented as a compiler-builtin.
        Nzhas function rh   _
propertiesz$Cross variable {0} is not a boolean.r6   funcz
        #if defined __stub_{func} || defined __stub___{func}
        fail fail fail this function is not going to work
        #endif
        z#includeTmsvcFZno_includesa  {prefix}
        int main() {{
        #ifdef __has_builtin
            #if !__has_builtin(__builtin_{func})
                #error "__builtin_{func} not found"
            #endif
        #elif ! defined({func})
            /* Check for __builtin_{func} only if no includes were added to the
             * prefix above, which means no definition of {func} can be found.
             * We would always check for this, but we get false positives on
             * MSYS2 if we do. Their toolchain is broken, but we can at least
             * give them a workaround. */
            #if {no_includes:d}
                __builtin_{func};
            #else
                #error "No definition for __builtin_{func} found in the prefix"
            #endif
        #endif
        }})replacer!   
cross_infoconfiggetr$   boolr   r   r   r   r   get_id)r'   funcnamer6   r   r   r   varnamevalr   Z
stubs_failr   r   Ztemplr   r+   r+   r,   has_function  s.    	
	
!zCCompiler.has_functionc             C   s   | d  k r g  } n  i | d 6| d 6d d 6} d } x( | D]  }	 | d j  | d |	  7} q= W| | d <d }
 |  j |
 j  |   | | |  S)	Nr6   r   Zfoonamer[   z{}.{};
membersz[{prefix}
        void bar() {{
            {type} {name};
            {members}
        }};)r   r   )r'   r   Zmembernamesr6   r   r   r   r   r   memberr   r+   r+   r,   has_membersp  s    	
zCCompiler.has_membersc             C   s9   i | d 6| d 6} d } |  j  | j |   | | |  S)Nr6   r   zF{prefix}
        void bar() {{
            sizeof({type});
        }};)r   r   )r'   r   r6   r   r   r   r   r   r+   r+   r,   has_type  s    zCCompiler.has_typec       
      C   s2  d } d | j    d } |  j | d d } | |  j   7} d } |  j | | d   } | j d k r d	 } t | j | | j    n  t j	 j
 | j  s d
 } t | j |    n  t | j d  < } x2 | D]* }	 d | |	 k r d S| |	 k r d Sq WWd QXWd QXt d j |    d S)zR
        Check if the compiler prefixes an underscore to global C symbols
        s   meson_uscore_prefixzD#ifdef __cplusplus
        extern "C" {
        #endif
        void zC () {}
        #ifdef __cplusplus
        }
        #endif
        rw   Fsymbols_have_underscore_prefixr   r   z%BUG: Unable to compile {!r} check: {}z1BUG: Can't find compiled test code for {!r} checkrb   _TNz#BUG: {!r} check failed unexpectedly)decoder}   rR   r   r   RuntimeErrorr   rd   rl   r9   isfiler   r~   )
r'   r   Zsymbol_namer   r   nr   more   r+   r+   r,   r     s(    z(CCompiler.symbols_have_underscore_prefixc             C   s'  | |  j  k r g  Sd } | r: t | t  r: | g } n  | sl d | g } |  j | | d | rl | Sn  | |  j   7} d d d d d g } x | D] } x~ | D]v } t j j | d | d	 |  }	 t j j |	  r |	 g St j j | | d	 |  }
 t j j |
  r |
 g Sq Wq Wd  S)
Nz-int main(int argc, char **argv) { return 0; }z-lr   r   dyliblibdllarI   )	ignore_libsr$   r%   r   rf   rl   r9   ri   r   )r'   libnamer   Z
extra_dirsr   r   suffixesrL   r8   trialtrial2r+   r+   r,   find_library  s(    !zCCompiler.find_libraryc             C   s   d g S)Nz-pthreadr+   )r'   r+   r+   r,   r     s    zCCompiler.thread_flagsc             C   s   d g S)Nz-pthreadr+   )r'   r+   r+   r,   r     s    zCCompiler.thread_link_flagsc             C   s   |  j  d | d | S)Nzint i;
r   )r   )r'   r   r   r+   r+   r,   has_multi_arguments  s    zCCompiler.has_multi_arguments)B__name__
__module____qualname__r   r-   r.   r/   r0   r1   r4   r5   r<   r>   rE   rH   rK   rJ   rM   rN   rO   rP   rQ   rR   rT   rV   rW   rX   rY   rZ   r]   r^   rf   rg   rj   ro   rr   rt   rv   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   (   s|   2)#S"r   c               @   sC   e  Z d  Z d d d  Z d d   Z d d   Z d d	   Z d S)
ClangCCompilerNc             C   sh   t  j |  | | | |  t j |  |  d d g } i | d 6| d g d 6| d d g d 6|  _ d  S)Nz-Wallz-Winvalid-pch1z-Wextra2z
-Wpedantic3)r   r   r   r2   )r'   r(   r)   
clang_typer!   r&   default_warn_argsr+   r+   r,   r     s    
zClangCCompiler.__init__c             C   s2   i t  j d d d d d d d d d	 g d  d 6S)
Nc_stdzC language standard to usenonec89c99c11gnu89gnu99gnu11)r   UserComboOption)r'   r+   r+   r,   get_options  s    zClangCCompiler.get_optionsc             C   s:   g  } | d } | j  d k r6 | j d | j   n  | S)Nr   r   z-std=)valueappend)r'   optionsr   stdr+   r+   r,   get_option_compile_args  s
    
z&ClangCCompiler.get_option_compile_argsc             C   s   g  S)Nr+   )r'   r  r+   r+   r,   get_option_link_args  s    z#ClangCCompiler.get_option_link_args)r   r   r   r   r  r  r  r+   r+   r+   r,   r     s   r   c               @   s^   e  Z d  Z d d d d  Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z d S)GnuCCompilerNc             C   sk   t  j |  | | | |  t j |  | |  d d g } i | d 6| d g d 6| d d g d 6|  _ d  S)Nz-Wallz-Winvalid-pchr   z-Wextrar   z
-Wpedanticr   )r   r   r   r2   )r'   r(   r)   gcc_typer!   r&   definesr   r+   r+   r,   r     s    
zGnuCCompiler.__init__c             C   sm   i t  j d d d d d d d d d	 g d  d 6} |  j t k ri | j i t  j d
 d t  d
 6 n  | S)Nr   zC language standard to user   r   r   r   r   r   r   	c_winlibsz&Standard Win libraries to link against)r   r  r
  r	   updateUserStringArrayOptionr   )r'   optsr+   r+   r,   r    s    	zGnuCCompiler.get_optionsc             C   s:   g  } | d } | j  d k r6 | j d | j   n  | S)Nr   r   z-std=)r  r  )r'   r  r   r  r+   r+   r,   r    s
    
z$GnuCCompiler.get_option_compile_argsc             C   s(   |  j  t k r$ | d j d  d   Sg  S)Nr  )r
  r	   r  )r'   r  r+   r+   r,   r    s    z!GnuCCompiler.get_option_link_argsc             C   s   d g S)Nz-sharedr+   )r'   r+   r+   r,   r^   	  s    z)GnuCCompiler.get_std_shared_lib_link_argsc             C   s   d d t  j j |  d g S)Nz-fpch-preprocessz-includer   rk   )rl   r9   rb   )r'   rm   rn   r+   r+   r,   ro     s    zGnuCCompiler.get_pch_use_args)	r   r   r   r   r  r  r  r^   ro   r+   r+   r+   r,   r	    s   r	  c                   sU   e  Z d  Z d d d  Z d d   Z d d   Z d d	   Z   f d
 d   Z   S)IntelCCompilerNc             C   sw   t  j |  | | | |  t j |  |  d |  _ d d d d g } i | d 6| d g d 6| d d	 g d
 6|  _ d  S)Nzc-headerz-Wallz-w3z-diag-disable:remarkz-Wpch-messagesr   z-Wextrar   z
-Wpedanticr   )r   r   r   lang_headerr2   )r'   r(   r)   icc_typer!   r&   r   r+   r+   r,   r     s    	
zIntelCCompiler.__init__c             C   sh   d d g } d d g } t  |  j d  r: | d g 7} n  i t j d d d	 g | | d	  d 6} | S)
Nr   r   r   r   z>=16.0.0r   r   zC language standard to user   )r   r)   r   r  )r'   Zc_stdsZg_stdsr  r+   r+   r,   r    s    zIntelCCompiler.get_optionsc             C   s:   g  } | d } | j  d k r6 | j d | j   n  | S)Nr   r   z-std=)r  r  )r'   r  r   r  r+   r+   r,   r  $  s
    
z&IntelCCompiler.get_option_compile_argsc             C   s   d g S)Nz-sharedr+   )r'   r+   r+   r,   r^   +  s    z+IntelCCompiler.get_std_shared_lib_link_argsc                s   t    j | d d g |  S)Nz-diag-errorZ10006)r   r   )r'   r   r   )r*   r+   r,   r   .  s    z"IntelCCompiler.has_multi_arguments)r   r   r   r   r  r  r^   r   r+   r+   )r*   r,   r    s
   	
r  c               @   s  e  Z d  Z d g Z d g Z dN 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 d$ d%   Z d& d'   Z d( d)   Z d* d+   Z d, d-   Z d. d/   Z d0 d1   Z d2 d3   Z d4 d5   Z d6 d7   Z d8 d9   Z d: d;   Z  e! d< d=    Z" d> d?   Z# d@ dA   Z$ dB dC   Z% dD dE dF  Z& dG dH   Z' dI dJ   Z( dK dL   Z) dM S)OVisualStudioCCompilerz/W3z/O2r   r   pthreadc             C   sq   t  j |  | | | |  d |  _ d d g |  _ i d g d 6d g d 6d g d	 6|  _ d
 g |  _ | |  _ d  S)Nr   z/nologoz/showIncludesz/W2r   z/W3r   z/W4r   b_pch)r   r   r    always_argsr2   base_optionsis_64)r'   r(   r)   r!   exe_wrapr  r+   r+   r,   r   7  s    	
zVisualStudioCCompiler.__init__c             C   s   |  j  S)N)r  )r'   r+   r+   r,   r.   D  s    z%VisualStudioCCompiler.get_always_argsc             C   s   d g S)aO  
        Arguments needed to select a debug crt for the linker

        Sometimes we need to manually select the CRT (C runtime) to use with
        MSVC. One example is when trying to link with static libraries since
        MSVC won't auto-select a CRT for us in that case and will error out
        asking us to select one.
        z/MDdr+   )r'   r+   r+   r,   r/   G  s    	z/VisualStudioCCompiler.get_linker_debug_crt_argsc             C   s   t  | S)N)r   )r'   	buildtyper+   r+   r,   get_buildtype_argsR  s    z(VisualStudioCCompiler.get_buildtype_argsc             C   s   t  | S)N)r   )r'   r  r+   r+   r,   get_buildtype_linker_argsU  s    z/VisualStudioCCompiler.get_buildtype_linker_argsc             C   s   d S)Npchr+   )r'   r+   r+   r,   rp   X  s    z$VisualStudioCCompiler.get_pch_suffixc             C   sO   t  j j |  d j d  d  d  } | j |  j    d j |  } | S)Nr   rI   rk   rk   )rl   r9   rb   r  rp   ri   )r'   rn   Zchoppedpchnamer+   r+   r,   rr   [  s    )z"VisualStudioCCompiler.get_pch_namec             C   sM   t  j j |  d } |  j |  } d | d | d t  j j | |  g S)Nr   z/FIz/Yuz/Fprk   )rl   r9   rb   rr   ri   )r'   rm   rn   baser  r+   r+   r,   ro   a  s    z&VisualStudioCCompiler.get_pch_use_argsc             C   s   d g S)Nz/EPr+   )r'   r+   r+   r,   rO   f  s    z.VisualStudioCCompiler.get_preprocess_only_argsc             C   s   d g S)Nz/cr+   )r'   r+   r+   r,   rP   i  s    z+VisualStudioCCompiler.get_compile_only_argsc             C   s   d g S)Nz/Odr+   )r'   r+   r+   r,   rQ   l  s    z.VisualStudioCCompiler.get_no_optimization_argsc             C   s%   | j  d  r d | g Sd | g S)Nz.exez/Fez/Fo)endswith)r'   rS   r+   r+   r,   rT   o  s    z%VisualStudioCCompiler.get_output_argsc             C   s   g  S)Nr+   )r'   rF   rG   r+   r+   r,   rH   t  s    z-VisualStudioCCompiler.get_dependency_gen_argsc             C   s   d g S)Nrw   r+   )r'   r+   r+   r,   rN   w  s    z(VisualStudioCCompiler.get_linker_exelistc             C   s   d g S)Nz/nologor+   )r'   r+   r+   r,   get_linker_always_argsz  s    z,VisualStudioCCompiler.get_linker_always_argsc             C   s   d | g S)Nz/OUT:r+   )r'   rU   r+   r+   r,   rV   }  s    z,VisualStudioCCompiler.get_linker_output_argsc             C   s   d | g S)Nz	/LIBPATH:r+   )r'   rs   r+   r+   r,   rt     s    z,VisualStudioCCompiler.get_linker_search_argsc             C   s   g  S)Nr+   )r'   r+   r+   r,   rg     s    z"VisualStudioCCompiler.get_pic_argsc             C   s   d g S)Nz/DLLr+   )r'   r+   r+   r,   r^     s    z2VisualStudioCCompiler.get_std_shared_lib_link_argsc             C   s)   t  | t  s t d   n  d | g S)Nz%Module definitions file should be strz/DEF:)r$   r%   r   )r'   defsfiler+   r+   r,   gen_vs_module_defs_args  s    z-VisualStudioCCompiler.gen_vs_module_defs_argsc             C   s9   t  j j |  d d } | d | d | d | g f S)Nr   z.objz/Ycz/Fpz/Fo)rl   r9   splitext)r'   rn   sourcer  Zobjnamer+   r+   r,   gen_pch_args  s    z"VisualStudioCCompiler.gen_pch_argsc             C   s   d | g S)z(The name of the outputted import libraryz/IMPLIB:r+   )r'   ru   r+   r+   r,   rv     s    z-VisualStudioCCompiler.gen_import_library_argsc             C   s   g  S)Nr+   )r'   r@   rA   rB   rC   rD   r+   r+   r,   rE     s    z&VisualStudioCCompiler.build_rpath_argsc             C   s   g  S)Nr+   )r'   r+   r+   r,   r     s    z"VisualStudioCCompiler.thread_flagsc             C   s   g  S)Nr+   )r'   r+   r+   r,   r     s    z'VisualStudioCCompiler.thread_link_flagsc             C   s   i t  j d d t  d 6S)Nr  zWindows libs to link against.)r   r  r   )r'   r+   r+   r,   r    s    z!VisualStudioCCompiler.get_optionsc             C   s   | d j  d  d   S)Nr  )r  )r'   r  r+   r+   r,   r    s    z*VisualStudioCCompiler.get_option_link_argsc             C   s   g  } x | D] } | d k r% q n  | j  d  rK d | d d   } nS | j  d  r | d d   } | |  j k r q q | d } n | d k r q n  | j |  q W| S)	N-mms-bitfields-pthreadz-Lz	/LIBPATH:r   z-lz.lib)r'  r(  )rc   r   r  )clsr   resultir   r+   r+   r,   unix_args_to_native  s    z)VisualStudioCCompiler.unix_args_to_nativec             C   s   d g S)Nz/WXr+   )r'   r+   r+   r,   rY     s    z%VisualStudioCCompiler.get_werror_argsc             C   s    | d k r d } n  d | g S)Nr[   rI   z-Ir+   )r'   r9   r\   r+   r+   r,   r]     s    	z&VisualStudioCCompiler.get_include_argsc             C   s%  d } d } t  j d d |  j  \ } } t j |  t | d   } | j |  Wd  QX|  j | d d } | |  j   7} |  j	 | | | g }	 t
 j d  t
 j d	 d
 j |	   t
 j d |  t |	 d t j j |  d \ }
 } } |
 j d k rd S| | k p#| | k S)NZ9002zint i;
r8   rI   rx   rw   FzRunning VS compile:zCommand line: rh   zCode:
ry   r   )tempfilemkstempdefault_suffixrl   closer~   r   r}   rP   r(   r   rz   ri   r   r9   rb   r   )r'   r   r   Zwarning_textr   fdsrcnamer   r   commandsr   rd   r   r+   r+   r,   r     s     +z)VisualStudioCCompiler.has_multi_argumentsFc             C   sh   | j  d  d  d  } | d g 7} d d j |  g } | rd t |  j d  rd d g | } n  | S)NrI   r   pdbz/Fdz>=18.0z/FSrk   )rb   ri   r   r)   )r'   rel_objr  pdbarrr   r+   r+   r,   get_compile_debugfile_args  s    z0VisualStudioCCompiler.get_compile_debugfile_argsc             C   s=   | j  d  d  d  } | d g 7} d d d j |  g S)NrI   r   r4  z/DEBUGz/PDB:rk   )rb   ri   )r'   
targetfiler6  r+   r+   r,   get_link_debugfile_args  s    z-VisualStudioCCompiler.get_link_debugfile_argsc             C   s,   t  | t  s | g } n  d d   | D S)Nc             S   s   g  |  ] } d  |  q S)z/WHOLEARCHIVE:r+   ).0xr+   r+   r,   
<listcomp>  s   	 z<VisualStudioCCompiler.get_link_whole_for.<locals>.<listcomp>)r$   r   )r'   r   r+   r+   r,   get_link_whole_for  s    z(VisualStudioCCompiler.get_link_whole_forc             C   sU   |  j  r t j | d   S|  j j d  d d k rE | d k rE d  St j | d   S)NrI   r   Z16avx)r  r   r   r)   rb   r   )r'   instruction_setr+   r+   r,   get_instruction_set_args  s
    	(z.VisualStudioCCompiler.get_instruction_set_argsN)r   r   r  )*r   r   r   Zstd_warn_argsZstd_opt_argsr   r   r.   r/   r  r  rp   rr   ro   rO   rP   rQ   rT   rH   rN   r!  rV   rt   rg   r^   r#  r&  rv   rE   r   r   r  r  classmethodr,  rY   r]   r   r7  r9  r=  r@  r+   r+   r+   r,   r  2  sL   			r  ) r   os.pathrl   r-  r[   r   r   mesonlibr   r   r   	compilersr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	  r  r  r+   r+   r+   r,   <module>   s   $d  '"