
    d`@                        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
 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	 Z G d
 de
          Z G d de          ZdZdZdZd Z ej        d          Zd Z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)PopenPIPEcheck_output)UnixCCompiler)
write_file)DistutilsExecErrorCCompilerErrorCompileErrorUnknownFileError)LooseVersion)find_executablec                  .   t           j                            d          } | dk    rot           j        | dz   | dz            }|dk    rdgS |dk    rdgS |d	k    rd
gS |dk    rdgS |dk    rdgS t          |          dk    rdgS t	          d|z            dS )zaInclude the appropriate MSVC runtime library if Python was built
    with MSVC 7.0 or later.
    zMSC v.   
   1300msvcr701310msvcr711400msvcr801500msvcr901600msvcr100il  msvcr140zUnknown MS Compiler version %s N)sysversionfindint
ValueError)msc_posmsc_vers     +lib/python3.11/distutils/cygwinccompiler.py	get_msvcrr%   =   s     kx((G"}}+gai
23f;;;;<\\T!!<>HIII+ }    c                   T    e Zd ZdZdZdZdZdZdZdZ	dZ
dd
Zd Z	 	 	 	 ddZddZdS )CygwinCCompilerz? Handles the Cygwin port of the GNU C compiler to Windows.
    cygwinz.o.az.dllzlib%s%sz%s%sz.exer   c           
         t          j        | |||           t                      \  }}|                     d|d|d           |t          ur|                     d|z             t                      \  | _        | _        | _	        |                     | j
        d| j        d| j        d| j	        dz              | j        d	k    rd
| _        nd| _        | j        dk    rd}nd}|                     dddd| j        d|           | j        dk    rdg| _        |                     d           d S t                      | _        d S )NzPython's GCC status: z (details: )zPython's pyconfig.h doesn't seem to support your compiler. Reason: %s. Compiling may fail because of undefined preprocessor macros.z: gcc z, ld z
, dllwrap 
z2.10.90gccdllwrap2.13-shared-mdll -staticzgcc -mcygwin -O -Wallzgcc -mcygwin -mdll -O -Wallzg++ -mcygwin -O -Wallzgcc -mcygwinz
 -mcygwin compilercompiler_socompiler_cxx
linker_exe	linker_so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_versiondllwrap_versioncompiler_type
linker_dllset_executablesdll_librariesr%   )selfverbosedry_runforcestatusdetailsshared_options          r$   r;   zCygwinCCompiler.__init__e   s   tWgu===(** &&'''+ 	, 	, 	,$$IIO    NN 	@$/4+?++***///.../0 0 	2 	2 	2 ?i''#DOO'DO ?f$$%MM+M 	&=)F*A(6)---)I	 	 	K 	K 	K y(( !)zDII>@ @ @ @ @
 "+Dr&   c                 *   |dk    s|dk    r>	 |                      dd|d|g           dS # t          $ r}t          |          d}~ww xY w	 |                      | j        |z   |d|gz   |z              dS # t          $ r}t          |          d}~ww xY w)z:Compiles the source by spawning GCC and windres if needed..rc.reswindresz-iz-oN)spawnr   r
   r5   )rH   objsrcextcc_argsextra_postargspp_optsmsgs           r$   _compilezCygwinCCompiler._compile   s    %<<3&==(

ItS$<=====% ( ( ("3'''((

4+g5dC8HH)* + + + + +% ( ( ("3'''(s,   * 
AAA&A4 4
B>BBNc                    t          j         |
pg           }
t          j         |pg           }t          j         |pg           }|                    | j                   |r|| j        k    s| j        dk    r[t
          j                            |d                   }t
          j                            t
          j        	                    |                    \  }}t
          j        
                    ||dz             }t
          j        
                    |d|z   dz             }dt
          j        	                    |          z  dg}|D ]}|                    |           |                     t          ||fd	|z             | j        d
k    r/|
                    d|g           |
                    d|g           n|                    |           |	s|
                    d           t          j        | |||||||d|	|
|||           dS )zLink the objects.Nr.   r   z.deflibr*   z
LIBRARY %sEXPORTSz
writing %sr/   z--output-libz--defz-s)copyextendrG   
EXECUTABLErE   ospathdirnamesplitextbasenamejoinappendexecuter   r   link)rH   target_descobjectsoutput_filename
output_dir	librarieslibrary_dirsruntime_library_dirsexport_symbolsdebugextra_preargsrX   
build_temptarget_langtemp_dirdll_namedll_extensiondef_filelib_filecontentssyms                        r$   rj   zCygwinCCompiler.link   s"    	-"5266Iio2..	)GMr** 	+,,, 'DO++t%/G/G wwqz22H(*(8(8  11)3 )3%X} w||Hh.?@@Hw||Heh.>.EFFH rw//@@@H & % %$$$$LLh%9%02 2 2 )++$$nh%?@@@$$gx%89999 x(((  	'  &&&4g%y,/ -&	( 	( 	( 	( 	(r&    c                 $   |d}g }|D ]}t           j                            t           j                            |                    \  }}|| j        ddgz   vrt          d|d|d          |rt           j                            |          }|dv r?|                    t           j                            |||z   | j	        z                        |                    t           j                            ||| j	        z                        |S )	z#Adds supports for rc and res files.Nr~   rP   rQ   zunknown file type 'z	' (from 'z'))rQ   rP   )
rb   rc   re   normcasesrc_extensionsr   rf   rh   rg   obj_extension)rH   source_filenames	strip_dirrn   	obj_namessrc_namebaserV   s           r$   object_filenamesz CygwinCCompiler.object_filenames   sB   J	( 	K 	KH(()9)9()C)CDDID#4.%?@@&&ssHHH(& ' ' ' /w''..o%%  "',,z.2Sj4;M.M#O #O P P P P   "',,z/3d6H/H#J #J K K K Kr&   r   r   r   )
NNNNNr   NNNN)r   r~   )__name__
__module____qualname____doc__rD   r   static_lib_extensionshared_lib_extensionstatic_lib_formatshared_lib_formatexe_extensionr;   r[   rj   r    r&   r$   r(   r(   Z   s         MM!!M9- 9- 9- 9-v( ( ( FJEI9=?CJ( J( J( J(\     r&   r(   c                       e Zd ZdZdZddZdS )Mingw32CCompilerz@ Handles the Mingw32 port of the GNU C compiler to Windows.
    mingw32r   c                 <   t                               | |||           | j        dk    rd}nd}| j        dk    rd}nd}t	                      rt          d          |                     dd	d
d| j        d|d|           g | _        t                      | _        d S )Nr0   r1   r2   r9   z--entry _DllMain@12r~   z1Cygwin gcc cannot be used with --compiler=mingw32zgcc -O -Wallzgcc -mdll -O -Wallzg++ -O -Wallr.    r3   )
r(   r;   rB   rA   is_cygwingccr	   rF   rE   rG   r%   )rH   rI   rJ   rK   rN   entry_points         r$   r;   zMingw32CCompiler.__init__  s      $%@@@ ?f$$%MM+M y((/KKK>> 	E CE E E 	n)=*8(-+/???MMM+6;(8	 	 	9 	9 	9  '[[r&   Nr   )r   r   r   r   rD   r;   r   r&   r$   r   r     s7         M&) &) &) &) &) &)r&   r   okznot ok	uncertainc                     ddl m}  dt          j        v r	t          dfS |                                 }	 t          |          }	 d|                                v r t          d|z  f|                                 S t          d|z  f|                                 S # |                                 w xY w# t          $ r}t          d|d	|j        fcY d
}~S d
}~ww xY w)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   )	sysconfigGCCzsys.version mentions 'GCC'__GNUC__z'%s' mentions '__GNUC__'z '%s' does not mention '__GNUC__'zcouldn't read 'z': N)	distutilsr   r   r   r>   get_config_h_filenameopenreadcloseCONFIG_H_NOTOKOSErrorCONFIG_H_UNCERTAINstrerror)r   fnconfig_hexcs       r$   r<   r<   I  s    * $##### 888 
	(	(	*	*B?88	X]]__,,"$>$CC NN &'IB'NNNNHNN ? ? ?"",.BB=? 	? 	? 	? 	? 	? 	??sA   B2 !B $B2 9B B2 B//B2 2
C<CCCs   (\d+\.\d+(\.\d+)*)c                    |                                  d         }t          |          dS t          | dt                    j        }	 |                                }|                                 n# |                                 w xY wt                              |          }|d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   r   r   
RE_VERSIONsearchr   groupdecode)cmd
executableout
out_stringresults        r$   _find_exe_versionr   v  s     QJz""*t
4
-
-
-
4CXXZZ
				z**F~t Q..00111s   	A2 2Bc                  <    g d} t          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                 ,    g | ]}t          |          S r   )r   ).0r   s     r$   
<listcomp>z get_versions.<locals>.<listcomp>  s!    ===S#C((===r&   )tuple)commandss    r$   r@   r@     s-    
 BAAH==H===>>>r&   c                  r    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   s    r$   r   r     s4    un566J&&y111r&   )"r   rb   r   r_   
subprocessr   r   r   redistutils.unixccompilerr   distutils.file_utilr   distutils.errorsr   r	   r
   r   distutils.versionr   distutils.spawnr   r%   r(   r   r>   r   r   r<   compiler   r   r@   r   r   r&   r$   <module>r      s   ^ 
			 



  0 0 0 0 0 0 0 0 0 0 				 1 1 1 1 1 1 * * * * * *( ( ( ( ( ( ( ( ( ( ( ( * * * * * * + + + + + +J J J:w w w w wm w w wt+) +) +) +) +) +) +) +)b   )? )? )?V RZ.//
2 2 2*? ? ?2 2 2 2 2r&   