a X�Zg�;�@s�ddlZddlZddlZddlmZddlmZddlmZm Z m Z ddl m Z m Z mZmZddlmZejdkrzddlZGdd �d e�ZdS) �N)� sysconfig)�newer)� CCompiler�gen_preprocess_options�gen_lib_options)�DistutilsExecError� CompileError�LibError� LinkError)�log�darwinc s�eZdZdZddgdgdgddgdgddgdd�Zejdd�d krNd ged <gd �Zd Zd Z dZ dZ dZ dZ ZZeZejdkr�dZ�fdd�Zd)dd�Zdd�Zd*dd�Zd+dd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd,d'd(�Z�ZS)-� UnixCCompilerZunixNZccz-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.tbdzlib%s%s�cygwinz.execs@t��|||�\}}}t�d�}|r6||vr6|�|�|||fS)NZLIBDIR)�super� _fix_lib_argsr�get_config_var�remove)�self� libraries� library_dirs�runtime_library_dirs�libdir�� __class__��//usr/lib64/python3.9/distutils/unixccompiler.pyrUs�    zUnixCCompiler._fix_lib_argsc Cs�|�d||�}|\}}}t||�} |j| } |r>| �d|g�|rN|| dd�<|r\| �|�| �|�|js~|dus~t||�r�|r�|�tj � |��z|� | �Wn,t y�} zt | ��WYd} ~ n d} ~ 00dS)N�-or)Z_fix_compile_argsrr�extend�append�forcer�mkpath�os�path�dirname�spawnrr) r�sourceZ output_fileZmacrosZ include_dirs� extra_preargs�extra_postargs� fixed_args�ignore�pp_optsZpp_args�msgr$r$r%� preprocess^s$      zUnixCCompiler.preprocessc Csr|j}tjdkr t�|||�}z |�|||d|g|�Wn,tyl}zt|��WYd}~n d}~00dS)Nr r&)r�sys�platform� _osx_support�compiler_fixupr.rr) r�obj�src�extZcc_argsr1r4rr5r$r$r%�_compilexs �� zUnixCCompiler._compilerc Cs�|�||�\}}|j||d�}|�||�r�|�tj�|��|�|j|g||j �|j r�z|�|j |g�Wq�t y�}zt |��WYd}~q�d}~00n t �d|�dS)N)� output_dir�skipping %s (up-to-date))�_fix_object_args�library_filename� _need_linkr*r+r,r-r.r�objectsrrr r �debug)rrDZoutput_libnamer?rE� target_lang�output_filenamer5r$r$r%�create_static_lib�s$ � ���  zUnixCCompiler.create_static_libc Cs�|�||�\}}|�|||�}|\}}}t||||�}t|ttd�f�sPtd��|durftj� ||�}|� ||��r�||j |d|g}| r�dg|dd�<| r�| |dd�<| r�|� | �|� tj�|��z�|tjkr�|jdd�}n|jdd�}| dk�rr|j�rrd}tj�|d�dk�r@d}d||v�r@|d7}�q&tj�||�d k�r\d}nd}|j||||<tjd k�r�t�||�}|�||�Wn.t�y�}zt|��WYd}~n d}~00n t�d |�dS) Nz%'output_dir' must be a string or Noner&z-grzc++�env��=Z ld_so_aixr r@)rArr� isinstance�str�type� TypeErrorr+r,�joinrCrDr'r*r-rZ EXECUTABLErrr�basenamer7r8r9r:r.rr r rE)rZ target_descrDrGr?rrr Zexport_symbolsrEr0r1Z build_temprFr2Zlib_optsZld_argsZlinker�i�offsetr5r$r$r%�link�sZ� ���       zUnixCCompiler.linkcCsd|S)N�-Lr$)r�dirr$r$r%�library_dir_option�sz UnixCCompiler.library_dir_optioncst�fdd�dD��S)Nc3s|]}|�vVqdS)Nr$)�.0�name�� compiler_namer$r%� ��z(UnixCCompiler._is_gcc..)Zgcczg++Zclang)�any)rr[r$rZr%�_is_gcc�szUnixCCompiler._is_gcccCs�tj�t�d��}tjdd�dkr,d|Stjdd�dkrFd|Stjdd�d krz|�|�rnd d|gSd d|gS|�|�r�t�d �d kr�d|Sd|Snd|SdS)N�CCrr rU�Zfreebsdz -Wl,-rpath=�zhp-uxz-Wl,+sz+sZGNULDZyesz-Wl,--enable-new-dtags,-Rz-Wl,-Rz-R)r+r,rQrrr7r8r_)rrVrr$r$r%�runtime_library_dir_option�s     z(UnixCCompiler.runtime_library_dir_optioncCsd|S)Nz-lr$)r�libr$r$r%�library_optionszUnixCCompiler.library_optioncCs�|j|dd�}|j|dd�}|j|dd�}|j|dd�}tjdkr|t�d�}t�d|�} | durrt�t�d ��} n | � d �} |D�] } t j � | |�} t j � | |�} t j � | |�}t j � | |�}tjdk�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| St j �|��rx|St j �| ��r�| St j �|�r�|Sq�dS)N�shared)Zlib_type�dylib� xcode_stub�staticr ZCFLAGSz-isysroot\s*(\S+)r`rJz/System/z/usr/z /usr/local/)rBr7r8rr�re�searchr9Z_default_sysroot�groupr+r,rP� startswith�exists)r�dirsrdrEZshared_fZdylib_fZ xcode_stub_fZstatic_fZcflags�mZsysrootrVrfrgrirhr$r$r%�find_library_filesF      ���  zUnixCCompiler.find_library_file)NNNNN)NrN) NNNNNrNNNN)r)�__name__� __module__� __qualname__Z compiler_typeZ executablesr7r8Zsrc_extensionsZ obj_extensionZstatic_lib_extensionZshared_lib_extensionZdylib_lib_extensionZxcode_stub_lib_extensionZstatic_lib_formatZshared_lib_formatZdylib_lib_formatZxcode_stub_lib_formatZ exe_extensionrr6r>rHrTrWr_rcrerq� __classcell__r$r$r"r%r -sN�     �  � � B*r )r+r7rjZ distutilsrZdistutils.dep_utilrZdistutils.ccompilerrrrZdistutils.errorsrrr r r r8r9r r$r$r$r%�s