a
    sBMbU9                     @   s   d 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	 ddl
mZ ddlmZmZmZmZ ddlmZ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dd Z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)check_output)UnixCCompiler)
write_file)DistutilsExecErrorCCompilerErrorCompileErrorUnknownFileError)LooseVersionsuppress_known_deprecationc                  C   s   t jd} | dkrt 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 |dkr~dgS |dkrdgS dt|  krdk rn ndd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1700Zmsvcr110Z1800Zmsvcr120il  i  ZucrtZvcruntime140zUnknown MS Compiler version %s N)sysversionfindint
ValueError)Zmsc_posZmsc_ver r   Dlib/python3.9/site-packages/setuptools/_distutils/cygwinccompiler.py	get_msvcr?   s(    r   c                
       sf   e Zd ZdZdZdZdZdZdZdZ	dZ
d fd
d	Zedd Zdd ZdddZdddZ  ZS )CygwinCCompilerz? Handles the Cygwin port of the GNU C compiler to Windows.
    cygwinz.o.az.dllzlib%s%sz%s%sz.exer   c                    s   t  ||| t \}}| d||f  |turB| d|  tjdd| _	tjdd| _
| j	| _d}| jd| j	 d	| j	 d| j
 d
| j	 d| j|f d 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CCgccZCXXzg++-sharedz%s -mcygwin -O -Wallz%s -mcygwin -mdll -O -Wallz%s -mcygwinz%s -mcygwin %sZcompilercompiler_soZcompiler_cxxZ
linker_exeZ	linker_so)super__init__check_config_hZdebug_printCONFIG_H_OKwarnosenvirongetcccxx
linker_dllset_executablesr   dll_libraries)selfverbosedry_runforceZstatusZdetailsshared_option	__class__r   r   r   m   s0    
	zCygwinCCompiler.__init__c                 C   sB   t jdtdd t  tdW  d    S 1 s40    Y  d S )Nzgcc_version attribute of CygwinCCompiler is deprecated. Instead of returning actual gcc version a fixed value 11.2.0 is returned.   )
stacklevelz11.2.0)warningsr!   DeprecationWarningr
   r	   )r*   r   r   r   gcc_version   s    zCygwinCCompiler.gcc_versionc              
   C   s   |dks|dkrXz|  dd|d|g W q tyT } zt|W Y d}~qd}~0 0 nPz"|  | j| |d|g |  W n, ty } zt|W Y d}~n
d}~0 0 dS )z:Compiles the source by spawning GCC and windres if needed..rc.resZwindresz-iz-oN)Zspawnr   r   r   )r*   objsrcextZcc_argsextra_postargsZpp_optsmsgr   r   r   _compile   s     
zCygwinCCompiler._compileNc                 C   s   t  |
p
g }
t  |pg }t  |p&g }|| j |dur|| jksR| jdkrtj|d }tjtj	|\}}tj
||d }tj
|d| d }dtj	| dg}|D ]}|| q| t||fd	|  || |	s|
d
 t| |||||||d|	|
||| dS )zLink the objects.Nr   r   z.deflibr   z
LIBRARY %sZEXPORTSz
writing %sz-s)copyextendr)   Z
EXECUTABLEr'   r"   pathdirnamesplitextbasenamejoinappendZexecuter   r   link)r*   Ztarget_descZobjectsZoutput_filename
output_dirZ	librariesZlibrary_dirsZruntime_library_dirsZexport_symbolsdebugZextra_preargsr;   Z
build_tempZtarget_langZtemp_dirZdll_nameZdll_extensionZdef_fileZlib_filecontentsZsymr   r   r   rG      sB    



zCygwinCCompiler.link c                 C   s   |du rd}g }|D ]}t jt j|\}}|| jddg vrRtd||f |rbt j|}|dv r|t j||| | j	  q|t j||| j	  q|S )z#Adds supports for rc and res files.NrK   r6   r7   z"unknown file type '%s' (from '%s'))r7   r6   )
r"   rA   rC   normcaseZsrc_extensionsr   rD   rF   rE   obj_extension)r*   Zsource_filenamesZ	strip_dirrH   Z	obj_namesZsrc_namebaser:   r   r   r   object_filenames   s&    z CygwinCCompiler.object_filenames)r   r   r   )
NNNNNr   NNNN)r   rK   )__name__
__module____qualname____doc__compiler_typerM   Zstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZexe_extensionr   propertyr5   r=   rG   rO   __classcell__r   r   r/   r   r   b   s$   
    
Gr   c                       s&   e Zd ZdZdZd fdd	Z  ZS )Mingw32CCompilerz@ Handles the Mingw32 port of the GNU C compiler to Windows.
    Zmingw32r   c                    s   t  ||| d}t| jr&tdtjdkr6d}nd}| jd| j|f d| j|f d| j|f d| j d	| j	|f d
 g | _
t | _
d S )Nr   z1Cygwin gcc cannot be used with --compiler=mingw32iz -DMS_WIN32z -DMS_WIN64z%s -O -Wall %sz%s -mdll -O -Wall %sz%sz%s %sr   )r   r   is_cygwinccr%   r   r   maxsizer(   r&   r'   r)   r   )r*   r+   r,   r-   r.   Zms_winr/   r   r   r     s&    

zMingw32CCompiler.__init__)r   r   r   )rP   rQ   rR   rS   rT   r   rV   r   r   r/   r   rW     s   rW   okznot okZ	uncertainc               
   C   s   ddl m}  dtjv rtdfS dtjv r0tdfS |  }z`t|}zHd| v rhtd| fW |  W S t	d	| fW |  W S W |  n
|  0 W n6 t
y } ztd
||jf fW  Y d}~S d}~0 0 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Clangzsys.version mentions 'Clang'Z__GNUC__z'%s' mentions '__GNUC__'z '%s' does not mention '__GNUC__'zcouldn't read '%s': %sN)	distutilsr[   r   r   r    Zget_config_h_filenameopenreadcloseCONFIG_H_NOTOKOSErrorCONFIG_H_UNCERTAINstrerror)r[   fnZconfig_hexcr   r   r   r   5  s*    

r   c                 C   s"   t t| dg }| dS )zCTry to determine if the compiler that would be used is from cygwin.z-dumpmachines   cygwin)r   shlexsplitstripendswith)r%   Z
out_stringr   r   r   rX   d  s    rX   )rS   r"   r   r?   rf   r3   
subprocessr   Zdistutils.unixccompilerr   Zdistutils.file_utilr   Zdistutils.errorsr   r   r   r   Zdistutils.versionr	   r
   r   r   rW   r    r`   rb   r   rX   Zget_versionsr   r   r   r   <module>   s*   1# ')/