a
    )°BiÖ;  ã                   @   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rNd
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rˆdZ‡ fdd„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‡  ZS )-ÚUnixCCompilerZunixNZ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                    s@   t ƒ  |||¡\}}}t d¡}|r6||v r6| |¡ |||fS )z'Remove standard library path from rpathZLIBDIR)ÚsuperÚ_fix_lib_argsr   Úget_config_varÚremove)ÚselfÚ	librariesÚlibrary_dirsÚruntime_library_dirsÚlibdir©Ú	__class__© ú//usr/lib64/python3.9/distutils/unixccompiler.pyr   U   s    ÿ


zUnixCCompiler._fix_lib_argsc              
   C   sÔ   |   d ||¡}|\}}}t||ƒ}	| j|	 }
|r>|
 d|g¡ |rN||
d d…< |r\|
 |¡ |
 |¡ | js~|d u s~t||ƒrÐ|r”|  tj	 
|¡¡ z|  |
¡ W n, tyÎ } zt|ƒ‚W Y d }~n
d }~0 0 d S )Nú-or   )Z_fix_compile_argsr   r   ÚextendÚappendÚforcer   ÚmkpathÚosÚpathÚdirnameÚspawnr   r   )r   ÚsourceZoutput_fileZmacrosZinclude_dirsÚextra_preargsÚextra_postargsÚ
fixed_argsÚignoreÚpp_optsZpp_argsÚmsgr$   r$   r%   Ú
preprocess^   s$    




zUnixCCompiler.preprocessc           	   
   C   sr   | j }tjdkr t ||| ¡}z |  || |d|g | ¡ W n, tyl } zt|ƒ‚W Y d }~n
d }~0 0 d S )Nr   r&   )r   ÚsysÚplatformÚ_osx_supportÚcompiler_fixupr.   r   r   )	r   ÚobjÚsrcÚextZcc_argsr1   r4   r   r5   r$   r$   r%   Ú_compilex   s    
ÿÿ
zUnixCCompiler._compiler   c              
   C   s´   |   ||¡\}}| j||d}|  ||¡r¤|  tj |¡¡ |  | j|g | | j	 ¡ | j
r°z|  | j
|g ¡ W q° ty  } zt|ƒ‚W Y d }~q°d }~0 0 n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   rD   Zoutput_libnamer?   rE   Útarget_langÚoutput_filenamer5   r$   r$   r%   Úcreate_static_libƒ   s$    ÿÿþþ	 zUnixCCompiler.create_static_libc              
   C   sÜ  |   ||¡\}}|  |||¡}|\}}}t| |||ƒ}t|ttd ƒfƒsPtdƒ‚|d urftj 	||¡}|  
||¡rÌ|| j | d|g }|	rœdg|d d…< |
r¬|
|d d…< |rº| |¡ |  tj |¡¡ zÎ|tjkrè| jd d … }n| jd d … }|dkrr| jrrd}tj |d ¡dkr@d}d|| v r@|d7 }q&tj || ¡d	kr\d}nd}| j| ||| < tjd
krŠt ||¡}|  || ¡ W n. tyÈ } zt|ƒ‚W Y d }~n
d }~0 0 nt d|¡ d S )Nz%'output_dir' must be a string or Noner&   z-gr   zc++Úenvé   ú=Z	ld_so_aixr   r@   )rA   r   r   Ú
isinstanceÚstrÚtypeÚ	TypeErrorr+   r,   ÚjoinrC   rD   r'   r*   r-   r   Z
EXECUTABLEr   r   r   Úbasenamer7   r8   r9   r:   r.   r   r
   r   rE   )r   Ztarget_descrD   rG   r?   r   r   r    Zexport_symbolsrE   r0   r1   Z
build_temprF   r2   Zlib_optsZld_argsZlinkerÚiÚoffsetr5   r$   r$   r%   Úlink   sZ    ÿ
ÿÿÿ

 zUnixCCompiler.linkc                 C   s   d| S )Nú-Lr$   )r   Údirr$   r$   r%   Úlibrary_dir_optionß   s    z UnixCCompiler.library_dir_optionc                    s   t ‡ fdd„dD ƒƒS )Nc                 3   s   | ]}|ˆ v V  qd S )Nr$   )Ú.0Úname©Úcompiler_namer$   r%   Ú	<genexpr>ä   ó    z(UnixCCompiler._is_gcc.<locals>.<genexpr>)Zgcczg++Zclang)Úany)r   r[   r$   rZ   r%   Ú_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rFd| S tjd d… d	krz|  |¡rnd
d| gS dd| gS |  |¡r¤t d¡dkršd| S d| S nd| S d S )NÚCCr   r   rU   é   Zfreebsdz-Wl,-rpath=é   zhp-uxz-Wl,+sz+sZGNULDZyesz-Wl,--enable-new-dtags,-Rz-Wl,-Rz-R)r+   r,   rQ   r   r   r7   r8   r_   )r   rV   r   r$   r$   r%   Úruntime_library_dir_optionæ   s    


z(UnixCCompiler.runtime_library_dir_optionc                 C   s   d| S )Nz-lr$   )r   Úlibr$   r$   r%   Úlibrary_option  s    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 rrt t d	¡¡}
n
|	 	d
¡}
|D ] }t
j ||¡}t
j ||¡}t
j ||¡}t
j ||¡}tjdkrL| d¡sì| d¡rL| d¡sLt
j |
|d
d … |¡}t
j |
|d
d … |¡}t
j |
|d
d … |¡}t
j |
|d
d … |¡}t
j |¡rb|  S t
j |¡rx|  S t
j |¡rŽ|  S t
j |¡r€|  S q€d S )NÚshared)Zlib_typeÚdylibÚ
xcode_stubÚstaticr   ZCFLAGSz-isysroot\s*(\S+)r`   rJ   z/System/z/usr/z/usr/local/)rB   r7   r8   r   r   ÚreÚsearchr9   Z_default_sysrootÚgroupr+   r,   rP   Ú
startswithÚexists)r   Údirsrd   rE   Zshared_fZdylib_fZxcode_stub_fZstatic_fZcflagsÚmZsysrootrV   rf   rg   ri   rh   r$   r$   r%   Úfind_library_file  sF    



ÿþþ
zUnixCCompiler.find_library_file)NNNNN)Nr   N)
NNNNNr   NNNN)r   )Ú__name__Ú
__module__Ú__qualname__Zcompiler_typeZexecutablesr7   r8   Zsrc_extensionsZobj_extensionZstatic_lib_extensionZshared_lib_extensionZdylib_lib_extensionZxcode_stub_lib_extensionZstatic_lib_formatZshared_lib_formatZdylib_lib_formatZxcode_stub_lib_formatZexe_extensionr   r6   r>   rH   rT   rW   r_   rc   re   rq   Ú__classcell__r$   r$   r"   r%   r   -   sN   ù


	  ÿ
 ÿ
    ü
B*r   )Ú__doc__r+   r7   rj   Z	distutilsr   Zdistutils.dep_utilr   Zdistutils.ccompilerr   r   r   Zdistutils.errorsr   r   r	   r
   r   r8   r9   r   r$   r$   r$   r%   Ú<module>   s   
