B
    18\^@                 @   s   d Z ddlZddlZddlZddlmZmZmZ ddl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 ddlmZ dd	lmZ dd
lmZ dd ZG dd deZG dd deZdZdZdZ dd Z!e"dZ#dd Z$dd Z%dd Z&dS )a  distutils.cygwinccompiler

Provides the CygwinCCompiler class, a subclass of UnixCCompiler that
handles the Cygwin port of the GNU C compiler to Windows.  It also contains
the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
cygwin in no-cygwin mode).
    N)PopenPIPEcheck_output)gen_preprocess_optionsgen_lib_options)UnixCCompiler)
write_file)DistutilsExecErrorCCompilerErrorCompileErrorUnknownFileError)log)LooseVersion)find_executablec              C   s   t jd} | dkr|t j| d | d  }|dkr8dgS |dkrFdgS |d	krTd
gS |dkrbdgS |dkrpdgS td| dS )zaInclude the appropriate MSVC runtime library if Python was built
    with MSVC 7.0 or later.
    zMSC v.   
   Z1300Zmsvcr70Z1310Zmsvcr71Z1400Zmsvcr80Z1500Zmsvcr90Z1600Zmsvcr100zUnknown MS Compiler version %s N)sysversionfind
ValueError)Zmsc_posZmsc_ver r   ]/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/distutils/cygwinccompiler.py	get_msvcr?   s    r   c            
   @   sR   e Zd ZdZdZdZdZdZdZdZ	dZ
dd
dZdd ZdddZdddZdS )CygwinCCompilerz? Handles the Cygwin port of the GNU C compiler to Windows.
    cygwinz.oz.az.dllzlib%s%sz%s%sz.exer   c             C   s   t | ||| t \}}| d||f  |tk	rB| d|  t \| _| _| _	| | j
d| j| j| j	f   | jdkrd| _nd| _| jdkrd}nd	}| jd
dddd| j|f d | jdkrdg| _| d nt | _d S )Nz%Python's GCC status: %s (details: %s)zPython's pyconfig.h doesn't seem to support your compiler. Reason: %s. Compiling may fail because of undefined preprocessor macros.z: gcc %s, ld %s, dllwrap %s
z2.10.90gccdllwrapz2.13z-sharedz-mdll -staticzgcc -mcygwin -O -Wallzgcc -mcygwin -mdll -O -Wallzg++ -mcygwin -O -Wallzgcc -mcygwinz%s -mcygwin %s)compilercompiler_socompiler_cxx
linker_exe	linker_soz2.91.57msvcrtz,Consider upgrading to a newer version of gcc)r   __init__check_config_hdebug_printCONFIG_H_OKwarnget_versionsgcc_version
ld_versionZdllwrap_versioncompiler_type
linker_dllset_executablesdll_librariesr   )selfverbosedry_runforcestatusdetailsshared_optionr   r   r   r$   d   s<    




zCygwinCCompiler.__init__c          
   C   s   |dks|dkrVy|  dd|d|g W q tk
rR } zt|W dd}~X Y qX nNy"|  | j| |d|g |  W n* tk
r } zt|W dd}~X Y nX dS )z:Compiles the source by spawning GCC and windres if needed.z.rcz.resZwindresz-iz-oN)spawnr	   r   r   )r0   objsrcextcc_argsextra_postargspp_optsmsgr   r   r   _compile   s    zCygwinCCompiler._compileNc             C   sT  t  |
p
g }
t  |pg }t  |p&g }|| j |dk	r|| jksV| jdkrtj|d }tjtj	|\}}tj
||d }tj
|d| d }dtj	| dg}x|D ]}|| qW | t||fd	|  | jd
kr|
d|g |
d|g n
|| |	s,|
d t| |||||||d|	|
||| dS )zLink the objects.Nr   r   z.deflibz.az
LIBRARY %sEXPORTSz
writing %sr   z--output-libz--defz-s)copyextendr/   
EXECUTABLEr-   ospathdirnamesplitextbasenamejoinappendexecuter   r   link)r0   target_descobjectsoutput_filename
output_dir	librarieslibrary_dirsruntime_library_dirsexport_symbolsdebugextra_preargsr<   
build_temptarget_langtemp_dirZdll_nameZdll_extensiondef_filelib_filecontentssymr   r   r   rM      s:    
	



zCygwinCCompiler.link c             C   s   |dkrd}g }x|D ]}t jt j|\}}|| jddg krTtd||f |rdt j|}|dkr|t j||| | j	  q|t j||| j	  qW |S )z#Adds supports for rc and res files.Nr_   z.rcz.resz"unknown file type '%s' (from '%s'))z.resz.rc)
rE   rF   rH   normcasesrc_extensionsr   rI   rK   rJ   obj_extension)r0   source_filenames	strip_dirrQ   	obj_namessrc_namebaser:   r   r   r   object_filenames   s     
z CygwinCCompiler.object_filenames)r   r   r   )
NNNNNr   NNNN)r   r_   )__name__
__module____qualname____doc__r,   rb   static_lib_extensionshared_lib_extensionstatic_lib_formatshared_lib_formatexe_extensionr$   r?   rM   rh   r   r   r   r   r   Y   s   
;   
Kr   c               @   s   e Zd ZdZdZdddZdS )Mingw32CCompilerz@ Handles the Mingw32 port of the GNU C compiler to Windows.
    mingw32r   c          	   C   sx   t | ||| | jdkr d}nd}| jdkr4d}nd}t rFtd| jdd	d
dd| j||f d g | _t	 | _d S )Nz2.13z-sharedz-mdll -staticz2.91.57z--entry _DllMain@12r_   z1Cygwin gcc cannot be used with --compiler=mingw32zgcc -O -Wallzgcc -mdll -O -Wallzg++ -O -Wallr   z%s %s %s)r   r   r    r!   r"   )
r   r$   r+   r*   is_cygwingccr
   r.   r-   r/   r   )r0   r1   r2   r3   r6   Zentry_pointr   r   r   r$     s&    

zMingw32CCompiler.__init__N)r   r   r   )ri   rj   rk   rl   r,   r$   r   r   r   r   rr     s   rr   okznot okZ	uncertainc           
   C   s   ddl m}  dtjkrtdfS |  }y@t|}z(d| krJtd| fS td| fS W d|	  X W n0 t
k
r } ztd	||jf fS d}~X Y nX dS )
aw  Check if the current Python installation appears amenable to building
    extensions with GCC.

    Returns a tuple (status, details), where 'status' is one of the following
    constants:

    - CONFIG_H_OK: all is well, go ahead and compile
    - CONFIG_H_NOTOK: doesn't look good
    - CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h

    'details' is a human-readable string explaining the situation.

    Note there are two ways to conclude "OK": either 'sys.version' contains
    the string "GCC" (implying that this Python was built with GCC), or the
    installed "pyconfig.h" contains the string "__GNUC__".
    r   )	sysconfigZGCCzsys.version mentions 'GCC'Z__GNUC__z'%s' mentions '__GNUC__'z '%s' does not mention '__GNUC__'Nzcouldn't read '%s': %s)	distutilsrv   r   r   r'   get_config_h_filenameopenreadCONFIG_H_NOTOKcloseOSErrorCONFIG_H_UNCERTAINstrerror)rv   fnconfig_hexcr   r   r   r%   H  s    
r%   s   (\d+\.\d+(\.\d+)*)c             C   sl   |   d }t|dkrdS t| dtdj}z| }W d|  X t|}|dkrZdS t	|
d S )zFind the version of an executable by running `cmd` in the shell.

    If the command is not found, or the output does not match
    `RE_VERSION`, returns None.
    r   NT)shellstdout   )splitr   r   r   r   rz   r|   
RE_VERSIONsearchr   groupdecode)cmd
executableout
out_stringresultr   r   r   _find_exe_versionu  s    

r   c              C   s   dddg} t dd | D S )zg Try to find out the versions of gcc, ld and dllwrap.

    If not possible it returns None for it.
    zgcc -dumpversionzld -vzdllwrap --versionc             S   s   g | ]}t |qS r   )r   ).0r   r   r   r   
<listcomp>  s    z get_versions.<locals>.<listcomp>)tuple)commandsr   r   r   r)     s    
r)   c              C   s   t ddg} |  dS )z>Try to determine if the gcc that would be used is from cygwin.r   z-dumpmachines   cygwin)r   stripendswith)r   r   r   r   rt     s    rt   )'rl   rE   r   rB   
subprocessr   r   r   redistutils.ccompilerr   r   distutils.unixccompilerr   distutils.file_utilr   distutils.errorsr	   r
   r   r   rw   r   Zdistutils.versionr   distutils.spawnr   r   r   rr   r'   r{   r~   r%   compiler   r   r)   rt   r   r   r   r   <module>   s0   ) ;1+
