a
    e:                     @   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 )+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 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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(   (lib/python3.9/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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
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    r7   Zoutput_libnamer2   r8   target_langoutput_filenamer'   r(   r(   r)   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   r3   )r4   Z_fix_lib_argsr   
isinstancestrtype	TypeErrorr   r   joinr6   r7   r   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lib_optsZld_argsZlinkerioffsetr'   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    rN   r(   rM   r)   _is_gcc   s    zUnixCCompiler._is_gccc                 C   s   dd l }tj|tdd }tjd d dkr>d| S tjd d dkrXd| S tjd d	 d
kr| 	|rdd| gS dd| gS | 	|rtddkrd| S d| S nd| S d S )Nr   CCr   r   rH      Zfreebsdz-Wl,-rpath=   zhp-uxz-Wl,+sz+sZGNULDZyesz-Wl,--enable-new-dtags,-Rz-Wl,-Rz-R)
shlexr   r   rD   splitr   get_config_varr+   r,   rR   )r    rI   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 qd S )Nshared)Zlib_typedylib
xcode_stubstaticr   ZCFLAGSz-isysroot\s*(\S+)rS   r=   z/System/z/usr/z/usr/local/)r5   r+   r,   r   rX   researchr-   Z_default_sysrootgroupr   r   rC   
startswithexists)r    dirsrZ   r8   Zshared_fZdylib_fZxcode_stub_fZstatic_fZcflagsmZsysrootrI   r\   r]   r_   r^   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;   rG   rJ   rR   rY   r[   rg   r(   r(   r(   r)   r   -   sL   


  
 
    
B+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   
