B
    0*\                 @   s   d dl Z d dlZd dlZd dlT d dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZmZ d dlmZ G d	d
 d
ZdZdddZddddddZdd ZdddZdd Zdd ZdS )    N)*)spawn)	move_file)mkpath)newer_pairwisenewer_group)split_quotedexecute)logc            
   @   s   e Zd ZdZdZdZdZdZdZdZ	dZ
ddddddZdddgZdpddZd	d
 Zdd Zdd Zdd Zdqd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 drd/d0Z!d1d2 Z"d3d4 Z#d5d6 Z$d7d8 Z%dsd9d:Z&dtd;d<Z'd=d> Z(dud?d@Z)dAZ*dBZ+dCZ,dvdDdEZ-dwdFdGZ.dxdHdIZ/dydJdKZ0dLdM Z1dNdO Z2dPdQ Z3dzdRdSZ4d{dTdUZ5d|dWdXZ6d}dYdZZ7d~d[d\Z8dd^d_Z9ddadbZ:dcdd Z;dedf Z<ddgdhZ=didj Z>dkdl Z?ddndoZ@dS )	CCompilerNczc++Zobjc)z.cz.ccz.cppz.cxxz.mr   c             C   sf   || _ || _|| _d | _g | _g | _g | _g | _g | _g | _	x$| j
 D ]}| || j
|  qHW d S )N)dry_runforceverbose
output_dirmacrosinclude_dirs	librarieslibrary_dirsruntime_library_dirsobjectsexecutableskeysset_executable)selfr   r   r   key r   >C:\ALexclude\prg\programme\Python37\Lib\distutils\ccompiler.py__init__U   s    zCCompiler.__init__c             K   s@   x:|D ]2}|| j kr(td|| jjf | |||  qW d S )Nz$unknown executable '%s' for class %s)r   
ValueError	__class____name__r   )r   kwargsr   r   r   r   set_executablesy   s
    

zCCompiler.set_executablesc             C   s,   t |trt| |t| nt| || d S )N)
isinstancestrsetattrr   )r   r   valuer   r   r   r      s    
zCCompiler.set_executablec             C   s0   d}x&| j D ]}|d |kr |S |d7 }qW d S )Nr      )r   )r   nameidefnr   r   r   _find_macro   s    zCCompiler._find_macroc             C   sd   x^|D ]V}t |trHt|dkrHt |d ts:|d d krHt |d tstd| d d qW d S )N)r(      r(   r   zinvalid macro definition '%s': z.must be tuple (string,), (string, string), or z(string, None))r$   tuplelenr%   	TypeError)r   Zdefinitionsr+   r   r   r   _check_macro_definitions   s    


z"CCompiler._check_macro_definitionsc             C   s.   |  |}|d k	r| j|= | j||f d S )N)r,   r   append)r   r)   r'   r*   r   r   r   define_macro   s    	
zCCompiler.define_macroc             C   s0   |  |}|d k	r| j|= |f}| j| d S )N)r,   r   r2   )r   r)   r*   Zundefnr   r   r   undefine_macro   s
    
zCCompiler.undefine_macroc             C   s   | j | d S )N)r   r2   )r   dirr   r   r   add_include_dir   s    zCCompiler.add_include_dirc             C   s   |d d  | _ d S )N)r   )r   dirsr   r   r   set_include_dirs   s    zCCompiler.set_include_dirsc             C   s   | j | d S )N)r   r2   )r   libnamer   r   r   add_library   s    zCCompiler.add_libraryc             C   s   |d d  | _ d S )N)r   )r   Zlibnamesr   r   r   set_libraries   s    zCCompiler.set_librariesc             C   s   | j | d S )N)r   r2   )r   r5   r   r   r   add_library_dir  s    zCCompiler.add_library_dirc             C   s   |d d  | _ d S )N)r   )r   r7   r   r   r   set_library_dirs  s    zCCompiler.set_library_dirsc             C   s   | j | d S )N)r   r2   )r   r5   r   r   r   add_runtime_library_dir  s    z!CCompiler.add_runtime_library_dirc             C   s   |d d  | _ d S )N)r   )r   r7   r   r   r   set_runtime_library_dirs  s    z"CCompiler.set_runtime_library_dirsc             C   s   | j | d S )N)r   r2   )r   objectr   r   r   add_link_object   s    zCCompiler.add_link_objectc             C   s   |d d  | _ d S )N)r   )r   r   r   r   r   set_link_objects(  s    zCCompiler.set_link_objectsc             C   s  |d kr| j }nt|ts"td|d kr2| j}n"t|trL|| jpFg  }ntd|d krd| j}n*t|ttfrt|| jpg  }ntd|d krg }| j|d|d}t	||}i }	xRt
t|D ]B}
||
 }||
 }tj|d }| tj| ||f|	|< qW |||||	fS )Nz%'output_dir' must be a string or Nonez/'macros' (if supplied) must be a list of tuplesz6'include_dirs' (if supplied) must be a list of stringsr   )	strip_dirr   r(   )r   r$   r%   r0   r   listr   r.   object_filenamesgen_preprocess_optionsranger/   ospathsplitextr   dirname)r   Zoutdirr   ZincdirssourcesdependsZextrar   pp_optsbuildr*   srcobjextr   r   r   _setup_compile6  s8    


zCCompiler._setup_compilec             C   s0   |dg }|rdg|d d< |r,||d d< |S )Nz-cz-gr   r   )r   rN   debugZbeforecc_argsr   r   r   _get_cc_argsa  s    
zCCompiler._get_cc_argsc             C   s   |d kr| j }nt|ts"td|d kr2| j}n"t|trL|| jpFg  }ntd|d krd| j}n*t|ttfrt|| jpg  }ntd|||fS )Nz%'output_dir' must be a string or Nonez/'macros' (if supplied) must be a list of tuplesz6'include_dirs' (if supplied) must be a list of strings)r   r$   r%   r0   r   rD   r   r.   )r   r   r   r   r   r   r   _fix_compile_argsj  s     


zCCompiler._fix_compile_argsc             C   s   | j ||d}|i fS )N)r   )rE   )r   rL   r   rM   r   r   r   r   _prep_compile  s    	zCCompiler._prep_compilec             C   sH   t |ttfstdt|}|d kr.| j}nt |ts@td||fS )Nz,'objects' must be a list or tuple of stringsz%'output_dir' must be a string or None)r$   rD   r.   r0   r   r%   )r   r   r   r   r   r   _fix_object_args  s    
zCCompiler._fix_object_argsc             C   s   |d kr| j }n*t|ttfr2t|| j p,g  }ntd|d krJ| j}n*t|ttfrlt|| jpfg  }ntd|d kr| j}n*t|ttfrt|| jpg  }ntd|||fS )Nz3'libraries' (if supplied) must be a list of stringsz6'library_dirs' (if supplied) must be a list of stringsz>'runtime_library_dirs' (if supplied) must be a list of strings)r   r$   rD   r.   r0   r   r   )r   r   r   r   r   r   r   _fix_lib_args  s&    zCCompiler._fix_lib_argsc             C   s2   | j r
dS | jr t||dd}n
t||}|S d S )NTnewer)missing)r   r   r   )r   r   output_filer[   r   r   r   
_need_link  s    
zCCompiler._need_linkc       	   	   C   s   t |ts|g}d }t| j}x^|D ]V}tj|\}}| j|}y | j	|}||k rb|}|}W q$ t
k
rx   Y q$X q$W |S )N)r$   rD   r/   language_orderrH   rI   rJ   language_mapgetindexr   )	r   rL   langrb   sourcebaserR   ZextlangZextindexr   r   r   detect_language  s    



zCCompiler.detect_languagec             C   s   d S )Nr   )r   rd   r]   r   r   extra_preargsextra_postargsr   r   r   
preprocess  s    zCCompiler.preprocessc	          	   C   sz   |  ||||||\}}	}}
}| |
||}xH|	D ]@}y|| \}}W n tk
r\   w2Y nX | ||||||
 q2W |	S )N)rS   rV   KeyError_compile)r   rL   r   r   r   rT   rg   rh   rM   r   rN   rO   rU   rQ   rP   rR   r   r   r   compile  s    6
zCCompiler.compilec             C   s   d S )Nr   )r   rQ   rP   rR   rU   rh   rN   r   r   r   rk   C  s    zCCompiler._compilec             C   s   d S )Nr   )r   r   output_libnamer   rT   target_langr   r   r   create_static_libI  s    zCCompiler.create_static_libZshared_objectZshared_library
executablec             C   s   t d S )N)NotImplementedError)r   Ztarget_descr   output_filenamer   r   r   r   export_symbolsrT   rg   rh   
build_temprn   r   r   r   linki  s    9zCCompiler.linkc             C   s2   |  tj|| j|dd|||||||	|
|| d S )Nshared)lib_type)ru   r   SHARED_LIBRARYlibrary_filename)r   r   rm   r   r   r   r   rs   rT   rg   rh   rt   rn   r   r   r   link_shared_lib  s    
zCCompiler.link_shared_libc             C   s(   |  tj|||||||||	|
|| d S )N)ru   r   SHARED_OBJECT)r   r   rr   r   r   r   r   rs   rT   rg   rh   rt   rn   r   r   r   link_shared_object  s
    
zCCompiler.link_shared_objectc             C   s.   |  tj|| |||||d |||	d |
 d S )N)ru   r   
EXECUTABLEexecutable_filename)r   r   Zoutput_prognamer   r   r   r   rT   rg   rh   rn   r   r   r   link_executable  s    

zCCompiler.link_executablec             C   s   t d S )N)rq   )r   r5   r   r   r   library_dir_option  s    zCCompiler.library_dir_optionc             C   s   t d S )N)rq   )r   r5   r   r   r   runtime_library_dir_option  s    z$CCompiler.runtime_library_dir_optionc             C   s   t d S )N)rq   )r   libr   r   r   library_option  s    zCCompiler.library_optionc          	   C   s   dd l }|d krg }|d kr g }|d kr,g }|d kr8g }|jd|dd\}}t|d}	z.x|D ]}
|	d|
  q`W |	d|  W d |	  X y| j|g|d}W n tk
r   d	S X y| j|d
||d W n t	t
fk
r   d	S X dS )Nr   z.cT)textwz#include "%s"
z+main (int argc, char **argv) {
    %s();
}
)r   Fza.out)r   r   )tempfileZmkstemprH   fdopenwritecloserl   ZCompileErrorr   Z	LinkErrorr0   )r   funcnameZincludesr   r   r   r   fdZfnamefZinclr   r   r   r   has_function  s8    	

zCCompiler.has_functionc             C   s   t d S )N)rq   )r   r7   r   rT   r   r   r   find_library_file#  s    zCCompiler.find_library_file c             C   s   |d krd}g }x|D ]|}t j|\}}t j|d }|t j|d  }|| jkrhtd||f |rxt j|}|t j	||| j
  qW |S )Nr   r(   z"unknown file type '%s' (from '%s'))rH   rI   rJ   
splitdriveisabssrc_extensionsZUnknownFileErrorbasenamer2   joinobj_extension)r   Zsource_filenamesrC   r   Z	obj_namesZsrc_namere   rR   r   r   r   rE   N  s    

zCCompiler.object_filenamesc             C   s$   |rt j|}t j||| j S )N)rH   rI   r   r   shared_lib_extension)r   r   rC   r   r   r   r   shared_object_filename_  s    z CCompiler.shared_object_filenamec             C   s(   |rt j|}t j||| jp"d S )Nr   )rH   rI   r   r   exe_extension)r   r   rC   r   r   r   r   r~   e  s    zCCompiler.executable_filenamestaticc       
      C   s`   |dkrt dt| |d }t| |d }tj|\}}|||f }	|rPd}tj|||	S )N)r   rv   ZdylibZ
xcode_stubz?'lib_type' must be "static", "shared", "dylib", or "xcode_stub"Z_lib_formatZ_lib_extensionr   )r   getattrrH   rI   splitr   )
r   r9   rw   rC   r   ZfmtrR   r5   re   filenamer   r   r   ry   k  s    zCCompiler.library_filenamer(   c             C   s   t | d S )N)r
   rT   )r   msglevelr   r   r   announce~  s    zCCompiler.announcec             C   s   ddl m} |rt| d S )Nr   )DEBUG)Zdistutils.debugr   print)r   r   r   r   r   r   debug_print  s    zCCompiler.debug_printc             C   s   t jd|  d S )Nzwarning: %s
)sysstderrr   )r   r   r   r   r   warn  s    zCCompiler.warnc             C   s   t |||| j d S )N)r	   r   )r   funcargsr   r   r   r   r   r	     s    zCCompiler.executec             C   s   t || jd d S )N)r   )r   r   )r   cmdr   r   r   r     s    zCCompiler.spawnc             C   s   t ||| jdS )N)r   )r   r   )r   rP   dstr   r   r   r     s    zCCompiler.move_file  c             C   s   t ||| jd d S )N)r   )r   r   )r   r)   moder   r   r   r     s    zCCompiler.mkpath)r   r   r   )N)N)NNNNN)NNNr   NNN)Nr   N)
NNNNNr   NNNN)
NNNNNr   NNNN)
NNNNNr   NNNN)NNNNr   NNN)NNNN)r   )r   r   )r   r   )r   r   )r   r   r   )r(   )Nr(   )r   )Ar!   
__module____qualname__Zcompiler_typer   r   Zstatic_lib_extensionr   Zstatic_lib_formatZshared_lib_formatr   r`   r_   r   r#   r   r,   r1   r3   r4   r6   r8   r:   r;   r<   r=   r>   r?   rA   rB   rS   rV   rW   rX   rY   rZ   r^   rf   ri   rl   rk   ro   r{   rx   r}   ru   rz   r|   r   r   r   r   r   r   rE   r   r~   ry   r   r   r   r	   r   r   r   r   r   r   r   r      s   

$ 

+	 
" 
  
B 
         
4         
         
       
 
*
+


 


r   ))zcygwin.*unix)posixr   )ntmsvcc             C   sV   | d krt j} |d krtj}x4tD ],\}}t||d k	sJt|| d k	r"|S q"W dS )Nr   )rH   r)   r   platform_default_compilersrematch)Zosnamer   patterncompilerr   r   r   get_default_compiler  s    
r   )ZunixccompilerZUnixCCompilerzstandard UNIX-style compiler)Z_msvccompilerZMSVCCompilerzMicrosoft Visual C++)cygwinccompilerZCygwinCCompilerz'Cygwin port of GNU C Compiler for Win32)r   ZMingw32CCompilerz(Mingw32 port of GNU C Compiler for Win32)ZbcppcompilerZBCPPCompilerzBorland C++ Compiler)r   r   cygwinZmingw32Zbcppc              C   s\   ddl m}  g }x,t D ] }|d| d t| d f qW |  | |}|d d S )Nr   )FancyGetoptz	compiler=r-   zList of available compilers:)Zdistutils.fancy_getoptr   compiler_classr   r2   sort
print_help)r   Z	compilersr   Zpretty_printerr   r   r   show_compilers  s    r   c             C   s   | d krt j} y"|d kr t| }t| \}}}W n8 tk
rh   d|  }|d k	r\|d|  }t|Y nX y*d| }t| tj| }	t	|	| }
W nB t
k
r   td| Y n$ tk
r   td||f Y nX |
d ||S )Nz5don't know how to compile C/C++ code on platform '%s'z with '%s' compilerz
distutils.z4can't compile C/C++ code: unable to load module '%s'zBcan't compile C/C++ code: unable to find class '%s' in module '%s')rH   r)   r   r   rj   ZDistutilsPlatformError
__import__r   modulesvarsImportErrorZDistutilsModuleError)Zplatr   r   r   r   Zmodule_name
class_nameZlong_descriptionr   moduleklassr   r   r   new_compiler  s2    
r   c             C   s   g }x| D ]}t |tr2dt|  kr0dks>n td| t|dkr^|d|d   q
t|dkr
|d d kr|d|d   q
|d|  q
W x|D ]}|d|  qW |S )	Nr(   r-   zPbad macro definition '%s': each element of 'macros' list must be a 1- or 2-tuplez-U%sr   z-D%sz-D%s=%sz-I%s)r$   r.   r/   r0   r2   )r   r   rN   Zmacror5   r   r   r   rF   
  s    
$
rF   c             C   s   g }x|D ]}| | | q
W x4|D ],}| |}t|trJ|| }q(| | q(W x^|D ]V}tj|\}}	|r| |g|	}
|
r| |
 q| 	d|  q^| | 
| q^W |S )Nz6no library file corresponding to '%s' found (skipping))r2   r   r   r$   rD   rH   rI   r   r   r   r   )r   r   r   r   Zlib_optsr5   optr   Zlib_dirZlib_nameZlib_filer   r   r   gen_lib_options7  s$    






r   )NN)NNr   r   r   )r   rH   r   Zdistutils.errorsZdistutils.spawnr   Zdistutils.file_utilr   Zdistutils.dir_utilr   Zdistutils.dep_utilr   r   Zdistutils.utilr   r	   Z	distutilsr
   r   r   r   r   r   r   rF   r   r   r   r   r   <module>   s4          

--