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rd}t
j|d dkrd}d|| v r|d7 }d|| v st
j|| dkrd}nd}| j| ||| < tjdkrt||}| ||  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st
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    
