a
    ӗa9                     @   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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 )+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 |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   )_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_optsZpp_argsmsg r0   :/home/manager/Python-3.9.10/Lib/distutils/unixccompiler.py
preprocessU   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extcc_argsr+   r.   r   r/   r0   r0   r1   _compileo   s    

zUnixCCompiler._compiler   c              
   C   s   |  ||\}}| j||d}| ||r| tj| | | j|g | | j	  | j
rz| | j
|g  W q ty } zt|W Y d }~qd }~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%   rA   output_libnamer<   rB   target_langoutput_filenamer/   r0   r0   r1   create_static_libz   s$    	 zUnixCCompiler.create_static_libc              
   C   s  |  ||\}}| |||}|\}}}t| |||}t|ttd fsPtd|d urftj	||}| 
||r|| j | d|g }|	rd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rt||}| ||  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=   )r>   _fix_lib_argsr   
isinstancestrtype	TypeErrorr!   r"   joinr@   rA   r   r    r#   r   
EXECUTABLEr   r   r   basenamer3   r4   r5   r6   r$   r   r
   r   rB   )r%   target_descrA   rE   r<   	librarieslibrary_dirsruntime_library_dirsexport_symbolsrB   r*   r+   
build_temprD   r,   lib_optsZld_argsZlinkerioffsetr/   r0   r0   r1   link   sZ    


 zUnixCCompiler.linkc                 C   s   d| S )N-Lr0   )r%   dirr0   r0   r1   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 )Nr0   ).0namecompiler_namer0   r1   	<genexpr>       z(UnixCCompiler._is_gcc.<locals>.<genexpr>)gcczg++clang)any)r%   rb   r0   ra   r1   _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 | |rtddkrd| S d| S nd| S d S )NCCr   r   r\      freebsdz-Wl,-rpath=   zhp-uxz-Wl,+sz+sGNULDyesz-Wl,--enable-new-dtags,-Rz-Wl,-Rz-R)r!   r"   rQ   r   get_config_varr3   r4   rh   )r%   r]   r   r0   r0   r1   runtime_library_dir_option   s    


z(UnixCCompiler.runtime_library_dir_optionc                 C   s   d| S )Nz-lr0   )r%   libr0   r0   r1   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 qd S )Nshared)lib_typedylib
xcode_stubstaticr   CFLAGSz-isysroot\s*(\S+)ri   rH   z/System/z/usr/z/usr/local/)r?   r3   r4   r   ro   researchr5   _default_sysrootgroupr!   r"   rO   
startswithexists)r%   dirsrq   rB   Zshared_fZdylib_fZxcode_stub_fZstatic_fcflagsmsysrootr]   rs   ru   rw   rv   r0   r0   r1   find_library_file
  sF    




zUnixCCompiler.find_library_file)NNNNN)Nr   N)
NNNNNr   NNNN)r   )__name__
__module____qualname__compiler_typeexecutablesr3   r4   src_extensionsobj_extensionstatic_lib_extensionshared_lib_extensionZdylib_lib_extensionZxcode_stub_lib_extensionstatic_lib_formatshared_lib_formatZdylib_lib_formatZxcode_stub_lib_formatexe_extensionr2   r;   rF   r[   r^   rh   rp   rr   r   r0   r0   r0   r1   r   -   sL   


  
 
    
B*r   )__doc__r!   r3   ry   	distutilsr   distutils.dep_utilr   distutils.ccompilerr   r   r   distutils.errorsr   r   r	   r
   r   r4   r5   r   r0   r0   r0   r1   <module>   s   
