o
    Š�bc<  ã                   @   s’   d 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	m
Z
mZ ddlmZmZmZmZ ddlmZ ejdkr?ddlZG d	d
„ d
e	ƒZdS )a9  distutils.unixccompiler

Contains the UnixCCompiler class, a subclass of CCompiler that handles
the "typical" Unix-style command-line C compiler:
  * macros defined with -Dname[=value]
  * macros undefined with -Uname
  * include search directories specified with -Idir
  * libraries specified with -lllib
  * library search directories specified with -Ldir
  * compile handled by 'cc' (or similar) executable with -c option:
    compiles .c to .o
  * link static library handled by 'ar' command (possibly with 'ranlib')
  * link shared library handled by 'cc -shared'
é    N)Ú	sysconfig)Únewer)Ú	CCompilerÚgen_preprocess_optionsÚgen_lib_options)ÚDistutilsExecErrorÚCompileErrorÚLibErrorÚ	LinkError)ÚlogÚdarwinc                	   @   sê   e Zd ZdZddgdgdgddgdgddgddœZejdd… d	kr'd
ged
< g d¢ZdZdZ	dZ
dZdZd Z ZZeZejdkrDdZ		d'dd„Zdd„ Z	d(dd„Z				d)dd„Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd*d%d&„ZdS )+ÚUnixCCompilerÚunixNÚccz-sharedÚarz-cr)ÚpreprocessorÚcompilerÚcompiler_soÚcompiler_cxxÚ	linker_soÚ
linker_exeÚarchiverÚranlibé   r   r   )z.cz.Cz.ccz.cxxz.cppz.mz.oz.az.soz.dylibz.tbdzlib%s%sÚcygwinz.exec              
   C   sÊ   |   d ||¡}|\}}}t||ƒ}	| j|	 }
|r|
 d|g¡ |r'||
d d…< |r.|
 |¡ |
 |¡ | js?|d u s?t||ƒrc|rJ|  tj	 
|¡¡ z|  |
¡ W d S  tyb } zt|ƒ‚d }~ww d S )Nú-or   )Ú_fix_compile_argsr   r   ÚextendÚappendÚforcer   ÚmkpathÚosÚpathÚdirnameÚspawnr   r   )ÚselfÚsourceÚoutput_fileÚmacrosÚinclude_dirsÚextra_preargsÚextra_postargsÚ
fixed_argsÚignoreÚpp_optsÚpp_argsÚmsg© r1   ú./usr/lib/python3.10/distutils/unixccompiler.pyÚ
preprocessU   s*   




€ÿûzUnixCCompiler.preprocessc           	   
   C   sd   | j }tjdkrt ||| ¡}z|  || |d|g | ¡ W d S  ty1 } zt|ƒ‚d }~ww )Nr   r   )r   ÚsysÚplatformÚ_osx_supportÚcompiler_fixupr$   r   r   )	r%   ÚobjÚsrcÚextÚcc_argsr+   r.   r   r0   r1   r1   r2   Ú_compileo   s   
ÿÿ€ÿzUnixCCompiler._compiler   c              
   C   s¬   |   ||¡\}}| j||d�}|  ||¡rN|  tj |¡¡ |  | j|g | | j	 ¡ | j
rLz|  | j
|g ¡ W d S  tyK } zt|ƒ‚d }~ww d S t d|¡ d S )N)Ú
output_dirúskipping %s (up-to-date))Ú_fix_object_argsÚlibrary_filenameÚ
_need_linkr    r!   r"   r#   r$   r   Úobjectsr   r   r	   r   Údebug)r%   rB   Úoutput_libnamer=   rC   Útarget_langÚoutput_filenamer0   r1   r1   r2   Úcreate_static_libz   s*   ÿÿþþ	€ÿýzUnixCCompiler.create_static_libc              
      s  |   ||¡\}}|  |||¡}|\}}}g d¢‰ t d¡}|r*ˆ  d| d| g¡ ‡ fdd„|D ƒ}‡ fdd„|D ƒ}t| |||ƒ}t|ttd ƒfƒsPt	dƒ‚|d ur[t
j ||¡}|  ||¡�r|| j | d	|g }|	rvd
g|d d…< |
r~|
|d d…< |r…| |¡ |  t
j |¡¡ zf|tjkrœ| jd d … }n| jd d … }|dkrà| jràd}t
j |d ¡dkrÈd}d|| v rÈ|d7 }d|| v s¾t
j || ¡dkrÕd}nd}| j| ||| < tjdkrët ||¡}|  || ¡ W d S  t�y } zt|ƒ‚d }~ww t d|¡ d S )N)z/libz/lib64z/usr/libz
/usr/lib64Ú	MULTIARCHz/lib/%sz/usr/lib/%sc                    ó   g | ]}|ˆ vr|‘qS r1   r1   ©Ú.0Údir©Úsystem_libdirsr1   r2   Ú
<listcomp>¤   ó    ÿz&UnixCCompiler.link.<locals>.<listcomp>c                    rI   r1   r1   rJ   rM   r1   r2   rO   ¦   rP   z%'output_dir' must be a string or Noner   z-gr   zc++Úenvé   ú=Ú	ld_so_aixr   r>   ) r?   Ú_fix_lib_argsr   Úget_config_varr   r   Ú
isinstanceÚstrÚtypeÚ	TypeErrorr!   r"   ÚjoinrA   rB   r    r#   r   Ú
EXECUTABLEr   r   r   Úbasenamer4   r5   r6   r7   r$   r   r
   r   rC   )r%   Útarget_descrB   rF   r=   Ú	librariesÚlibrary_dirsÚruntime_library_dirsÚexport_symbolsrC   r*   r+   Ú
build_temprE   r,   Ú	multiarchÚlib_optsÚld_argsÚlinkerÚiÚoffsetr0   r1   rM   r2   Úlink”   sl   ÿ

ÿÿÿ

ÿ
€ÿzUnixCCompiler.linkc                 C   ó   d| S )Nú-Lr1   )r%   rL   r1   r1   r2   Úlibrary_dir_optioná   ó   z UnixCCompiler.library_dir_optionc                    s   t ‡ fdd„dD ƒƒS )Nc                 3   s   � | ]}|ˆ v V  qd S )Nr1   )rK   Úname©Úcompiler_namer1   r2   Ú	<genexpr>æ   s   € z(UnixCCompiler._is_gcc.<locals>.<genexpr>)Úgcczg++Úclang)Úany)r%   rq   r1   rp   r2   Ú_is_gccä   s   zUnixCCompiler._is_gccc                 C   sª   t j t d¡¡}tjd d… dkrd| S tjd d… dkr#d| S tjd d… d	kr=|  |¡r7d
d| gS dd| gS |  |¡rQt d¡dkrMd| S d| S d| S )NÚCCr   r   rl   é   Úfreebsdz-Wl,-rpath=é   zhp-uxz-Wl,+sz+sÚGNULDÚyesz-Wl,--enable-new-dtags,-Rz-Wl,-Rz-R)r!   r"   r]   r   rV   r4   r5   rv   )r%   rL   r   r1   r1   r2   Úruntime_library_dir_optionè   s   

z(UnixCCompiler.runtime_library_dir_optionc                 C   rk   )Nz-lr1   )r%   Úlibr1   r1   r2   Úlibrary_option  rn   zUnixCCompiler.library_optionc                 C   sš  | j |dd�}| j |dd�}| j |dd�}| j |dd�}tjdkr>t d¡}t d|¡}	|	d u r9t t d	¡¡}
n|	 	d
¡}
|D ]Š}t
j ||¡}t
j ||¡}t
j ||¡}t
j ||¡}tjdkr¢| d¡sr| d¡r¢| d¡s¢t
j |
|d
d … |¡}t
j |
|d
d … |¡}t
j |
|d
d … |¡}t
j |
|d
d … |¡}t
j |¡r¬|  S t
j |¡r¶|  S t
j |¡rÀ|  S t
j |¡rÊ|  S q@d S )NÚshared)Úlib_typeÚdylibÚ
xcode_stubÚstaticr   ÚCFLAGSz-isysroot\s*(\S+)rw   rR   z/System/z/usr/z/usr/local/)r@   r4   r5   r   rV   ÚreÚsearchr6   Ú_default_sysrootÚgroupr!   r"   r[   Ú
startswithÚexists)r%   Údirsr~   rC   Úshared_fÚdylib_fÚxcode_stub_fÚstatic_fÚcflagsÚmÚsysrootrL   r€   r‚   r„   rƒ   r1   r1   r2   Úfind_library_file  sH   



ÿþþÿzUnixCCompiler.find_library_file)NNNNN)Nr   N)
NNNNNr   NNNN)r   )Ú__name__Ú
__module__Ú__qualname__Úcompiler_typeÚexecutablesr4   r5   Úsrc_extensionsÚobj_extensionÚstatic_lib_extensionÚshared_lib_extensionÚdylib_lib_extensionÚxcode_stub_lib_extensionÚstatic_lib_formatÚshared_lib_formatÚdylib_lib_formatÚxcode_stub_lib_formatÚexe_extensionr3   r<   rG   rj   rm   rv   r}   r   r”   r1   r1   r1   r2   r   -   sN    ù



ÿ
ÿ
üM*r   )Ú__doc__r!   r4   r†   Ú	distutilsr   Údistutils.dep_utilr   Údistutils.ccompilerr   r   r   Údistutils.errorsr   r   r	   r
   r   r5   r6   r   r1   r1   r1   r2   Ú<module>   s    
