U
    ËAš`ß;  ã                   @   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
< ddddddgZdZdZ	dZ
dZdZd Z ZZeZejdkrd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 )0ÚUnixCCompilerZunixNZccz-sharedZ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¡ |rN||
d d…< |r\|
 |¡ |
 |¡ | js~|d ks~t||ƒrÎ|r”|  tj	 
|¡¡ z|  |
¡ W n* tk
rÌ } zt|ƒ‚W 5 d }~X Y nX d S )Nú-or   )Z_fix_compile_argsr   r   ÚextendÚappendZforcer   ÚmkpathÚosÚpathÚdirnameÚspawnr   r   )ÚselfÚsourceZoutput_fileZmacrosZinclude_dirsÚextra_preargsÚextra_postargsÚ
fixed_argsÚignoreÚpp_optsZpp_argsÚmsg© r(   ú-/usr/lib/python3.8/distutils/unixccompiler.pyÚ
preprocessU   s$    




zUnixCCompiler.preprocessc           	   
   C   sp   | j }tjdkr t ||| ¡}z |  || |d|g | ¡ W n* tk
rj } zt|ƒ‚W 5 d }~X Y nX d S )Nr   r   )r   ÚsysÚplatformÚ_osx_supportÚcompiler_fixupr   r   r   )	r    ÚobjÚsrcZextZcc_argsr#   r&   r   r'   r(   r(   r)   Ú_compileo   s    
ÿÿ
zUnixCCompiler._compiler   c              
   C   s²   |   ||¡\}}| j||d}|  ||¡r¢|  tj |¡¡ |  | j|g | | j	 ¡ | j
r®z|  | j
|g ¡ W q® tk
rž } zt|ƒ‚W 5 d }~X Y q®X 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    r7   Zoutput_libnamer2   r8   Útarget_langÚoutput_filenamer'   r(   r(   r)   Úcreate_static_libz   s$    ÿÿþþ	zUnixCCompiler.create_static_libc              
      s4  |   ||¡\}}|  |||¡}|\}}}ddddg‰ t d¡}|rXˆ  d| d| g¡ ‡ fdd	„|D ƒ}‡ fd
d	„|D ƒ}t| |||ƒ}t|ttd ƒfƒs¤t	dƒ‚|d k	rºt
j ||¡}|  ||¡r$|| j | d|g }|	rðdg|d d…< |
r|
|d d…< |r| |¡ |  t
j |¡¡ zÐ|tjkrB| jd d … }n| jd d … }|dkrÌ| jrÌd}t
j |d ¡dkršd}d|| krš|d7 }q€t
j || ¡dkr¶d}nd}| j| ||| < tjdkrät ||¡}|  || ¡ W n, tk
r  } zt|ƒ‚W 5 d }~X Y nX nt d|¡ d S )Nz/libz/lib64z/usr/libz
/usr/lib64Z	MULTIARCHz/lib/%sz/usr/lib/%sc                    s   g | ]}|ˆ kr|‘qS r(   r(   ©Ú.0Údir©Zsystem_libdirsr(   r)   Ú
<listcomp>¤   s    ÿz&UnixCCompiler.link.<locals>.<listcomp>c                    s   g | ]}|ˆ kr|‘qS r(   r(   r<   r?   r(   r)   r@   ¦   s    ÿz%'output_dir' must be a string or Noner   z-gr   zc++Úenvé   ú=Z	ld_so_aixr   r3   ) r4   Z_fix_lib_argsr   Úget_config_varr   r   Ú
isinstanceÚstrÚtypeÚ	TypeErrorr   r   Újoinr6   r7   r   r   r   Z
EXECUTABLEr   r   r   Úbasenamer+   r,   r-   r.   r   r   r
   r   r8   )r    Ztarget_descr7   r:   r2   Z	librariesZlibrary_dirsZruntime_library_dirsZexport_symbolsr8   r"   r#   Z
build_tempr9   r$   Z	multiarchZlib_optsZld_argsZlinkerÚiÚoffsetr'   r(   r?   r)   Úlink”   sf    ÿ

ÿÿÿ
zUnixCCompiler.linkc                 C   s   d| S )Nú-Lr(   )r    r>   r(   r(   r)   Úlibrary_dir_optioná   s    z UnixCCompiler.library_dir_optionc                 C   s   d|kpd|kS )NZgcczg++r(   )r    Zcompiler_namer(   r(   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   rN   é   Zfreebsdz-Wl,-rpath=é   zhp-uxz-Wl,+sz+sZGNULDZyesz-Wl,--enable-new-dtags,-Rz-Wl,-Rz-R)r   r   rJ   r   rD   r+   r,   rP   )r    r>   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 k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+)rQ   rB   z/System/z/usr/z/usr/local/)r5   r+   r,   r   rD   ÚreÚsearchr-   Z_default_sysrootÚgroupr   r   rI   Ú
startswithÚexists)r    ÚdirsrU   r8   Zshared_fZdylib_fZxcode_stub_fZstatic_fZcflagsÚmZsysrootr>   rW   rX   rZ   rY   r(   r(   r)   Úfind_library_file  sF    



ÿþþ
zUnixCCompiler.find_library_file)NNNNN)Nr   N)
NNNNNr   NNNN)r   )Ú__name__Ú
__module__Ú__qualname__Zcompiler_typeZexecutablesr+   r,   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*   r1   r;   rM   rO   rP   rT   rV   rb   r(   r(   r(   r)   r   -   s`   ù


      ÿ
     ÿ
                ü
M*r   )Ú__doc__r   r+   r[   Z	distutilsr   Zdistutils.dep_utilr   Zdistutils.ccompilerr   r   r   Zdistutils.errorsr   r   r	   r
   r   r,   r-   r   r(   r(   r(   r)   Ú<module>   s   
