o
    bWIcÅ9  ã                   @   s„   d Z ddlZddlZddlmZmZmZmZmZ ddl	m
Z
mZ ddlmZ ddlmZ ddlmZ e de¡ G d	d
„ d
e
ƒZdS )zƒdistutils.bcppcompiler

Contains BorlandCCompiler, an implementation of the abstract CCompiler class
for the Borland C++ compiler.
é    N)ÚDistutilsExecErrorÚCompileErrorÚLibErrorÚ	LinkErrorÚUnknownFileError)Ú	CCompilerÚgen_preprocess_options)Ú
write_file)Únewer)Úlogz˜bcppcompiler is deprecated and slated to be removed in the future. Please discontinue use or file an issue with pypa/distutils describing your use case.c                       sÂ   e Zd ZdZdZi ZdgZg d¢Zee ZdZ	dZ
dZd ZZd	Zd‡ fdd„	Z				
			ddd„Z	ddd„Z						
				ddd„Zddd„Zd dd„Z					d!dd„Z‡  ZS )"ÚBCPPCompilerzConcrete class that implements an interface to the Borland C/C++
    compiler, as defined by the CCompiler abstract class.
    Úbcppz.c)z.ccz.cppz.cxxz.objz.libz.dllz%s%sz.exer   c                    sn   t ƒ  |||¡ d| _d| _d| _d | _g d¢| _g d¢| _g d¢| _g d¢| _	g | _
g d¢| _g d¢| _d S )	Nz	bcc32.exezilink32.exeztlib.exe)ú/tWMz/O2ú/qú/g0)r   z/Odr   r   )z/Tpdú/Gnr   ú/x)r   r   r   )r   r   r   z/r)ÚsuperÚ__init__ÚccÚlinkerÚlibÚpreprocess_optionsÚcompile_optionsÚcompile_options_debugÚldflags_sharedÚldflags_shared_debugÚldflags_staticÚldflags_exeÚldflags_exe_debug)ÚselfÚverboseÚdry_runÚforce©Ú	__class__© úD/usr/lib/python3/dist-packages/setuptools/_distutils/bcppcompiler.pyr   B   s   




zBCPPCompiler.__init__Nc	                 C   sn  |   ||||||¡\}}	}}
}|pg }| d¡ |r!| | j¡ n| | j¡ |	D ]‹}z|| \}}W n	 ty<   Y q)w tj |¡}tj |¡}|  	tj 
|¡¡ |dkrWq)|dkrxz|  dd||g¡ W n tyv } zt|ƒ‚d }~ww q)|| jv r€d}n
|| jv rˆd}nd}d| }z|  | jg| |
 ||g | |g ¡ W q) ty´ } zt|ƒ‚d }~ww |	S )	Nz-cú.resú.rcÚbrcc32z-foÚ z-Pú-o)Ú_setup_compileÚappendÚextendr   r   ÚKeyErrorÚosÚpathÚnormpathÚmkpathÚdirnameÚspawnr   r   Ú_c_extensionsÚ_cpp_extensionsr   )r    ÚsourcesÚ
output_dirÚmacrosÚinclude_dirsÚdebugÚextra_preargsÚextra_postargsÚdependsÚobjectsÚpp_optsÚbuildÚcompile_optsÚobjÚsrcÚextÚmsgÚ	input_optÚ
output_optr&   r&   r'   ÚcompileZ   sh   ÿ
ÿ€ÿ

ÿþýüûÿ€ÿzBCPPCompiler.compilec           	   
   C   s†   |   ||¡\}}| j||d}|  ||¡r;|dg| }|r	 z|  | jg| ¡ W d S  ty: } zt|ƒ‚d }~ww t d|¡ d S )N)r:   z/uúskipping %s (up-to-date))	Ú_fix_object_argsÚlibrary_filenameÚ
_need_linkr6   r   r   r   r   r=   )	r    rA   Úoutput_libnamer:   r=   Útarget_langÚoutput_filenameÚlib_argsrH   r&   r&   r'   Úcreate_static_lib§   s   €ÿzBCPPCompiler.create_static_libc               
   C   sÒ  |   ||¡\}}|  |||¡\}}}|rt dt|ƒ¡ |d ur'tj ||¡}|  ||¡ra|t	j
krGd}|	r?| jd d … }n| jd d … }nd}|	rS| jd d … }n| jd d … }|d u rad}n?tj |¡\}}tj |¡\}}tj |d ¡}tj |d| ¡}dg}|pˆg D ]}| d ||¡¡ q‰|  t||fd	| ¡ ttjj|ƒ}|g}g }|D ]}tj tj |¡¡\}}|d
krÆ| |¡ q®| |¡ q®|D ]}| dtj |¡ ¡ qÎ| d¡ | |¡ | d|g¡ | d¡ |D ]}|  |||	¡}|d u r| |¡ qô| |¡ qô| d¡ | d¡ | d|g¡ | d¡ | |¡ |
r2|
|d d…< |r:| |¡ |  tj |¡¡ z|  | jg| ¡ W d S  ty` } zt|ƒ‚d }~ww t  d|¡ d S )Nz7I don't know what to do with 'runtime_library_dirs': %sÚc0w32Úc0d32r+   r   z%s.defÚEXPORTSz  {}=_{}z
writing %sr(   z/L%sz/L.ú,z,,Úimport32Úcw32mtrL   )!rM   Ú_fix_lib_argsr   ÚwarnÚstrr1   r2   ÚjoinrO   r   Ú
EXECUTABLEr   r   r   r   ÚsplitÚsplitextr5   r.   ÚformatÚexecuter	   Úmapr3   Únormcaser/   Úfind_library_filer4   r6   r   r   r   r=   ) r    Útarget_descrA   rR   r:   Ú	librariesÚlibrary_dirsÚruntime_library_dirsÚexport_symbolsr=   r>   r?   Ú
build_temprQ   Ústartup_objÚld_argsÚdef_fileÚheadÚtailÚmodnamerG   Útemp_dirÚcontentsÚsymÚobjects2Ú	resourcesÚfileÚbaseÚellr   ÚlibfilerH   r&   r&   r'   Úlink»   s†   
ÿþ









€ÿzBCPPCompiler.linkc           	      C   sr   |r|d }|d |d ||f}n|d |f}|D ]}|D ]}t j ||  |¡¡}t j |¡r5|    S qqd S )NÚ_dÚ_bcpp)r1   r2   r^   rN   Úexists)	r    Údirsr   r=   ÚdlibÚ	try_namesÚdirÚnamer{   r&   r&   r'   rf   D  s   
ÿþzBCPPCompiler.find_library_filer+   c                 C   sÆ   |d u rd}g }|D ]V}t j t j |¡¡\}}|| jddg vr)td ||¡ƒ‚|r1t j |¡}|dkrB| t j 	||| ¡¡ q
|dkrS| t j 	||d ¡¡ q
| t j 	||| j
 ¡¡ q
|S )Nr+   r)   r(   z"unknown file type '{}' (from '{}'))r1   r2   ra   re   Úsrc_extensionsr   rb   Úbasenamer.   r^   Úobj_extension)r    Úsource_filenamesÚ	strip_dirr:   Ú	obj_namesÚsrc_namery   rG   r&   r&   r'   Úobject_filenames^  s"   
ÿzBCPPCompiler.object_filenamesc              
   C   sÒ   |   d ||¡\}}}t||ƒ}dg| }	|d ur|	 d| ¡ |r'||	d d…< |r.|	 |¡ |	 |¡ | js?|d u s?t||ƒrg|rJ|  tj 	|¡¡ z|  
|	¡ W d S  tyf }
 zt|
ƒ t|
ƒ‚d }
~
ww d S )Nz	cpp32.exer,   r   )Ú_fix_compile_argsr   r.   r/   r#   r
   r4   r1   r2   r5   r6   r   Úprintr   )r    ÚsourceÚoutput_filer;   r<   r>   r?   Ú_rB   Úpp_argsrH   r&   r&   r'   Ú
preprocessw  s*   




€þûzBCPPCompiler.preprocess)r   r   r   )NNNr   NNN)Nr   N)
NNNNNr   NNNN)r   )r   r+   )NNNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úcompiler_typeÚexecutablesr7   r8   r…   r‡   Ústatic_lib_extensionÚshared_lib_extensionÚstatic_lib_formatÚshared_lib_formatÚexe_extensionr   rK   rT   r|   rf   rŒ   r“   Ú__classcell__r&   r&   r$   r'   r   '   sV    
÷N
ÿ
ò 


ùr   )r—   r1   ÚwarningsÚdistutils.errorsr   r   r   r   r   Údistutils.ccompilerr   r   Údistutils.file_utilr	   Údistutils.dep_utilr
   Ú	distutilsr   r\   ÚDeprecationWarningr   r&   r&   r&   r'   Ú<module>   s    ü