o
    Ƌ|c.:                     @   sp   d 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 G dd	 d	e	ZdS )
zdistutils.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)logc                   @   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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dS )"BCPPCompilerzConcrete class that implements an interface to the Borland C/C++
    compiler, as defined by the CCompiler abstract class.
    Zbcppz.c)z.ccz.cppz.cxxz.objz.libz.dllz%s%sz.exer   c                 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)r   __init__cclinkerlibZpreprocess_optionscompile_optionscompile_options_debugldflags_sharedldflags_shared_debugZldflags_staticldflags_exeldflags_exe_debug)selfverbosedry_runforce r    (lib/python3.10/distutils/bcppcompiler.pyr   5   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 rd}n
|| jv rd}nd}d| }z| | jg| |
 ||g | |g  W q) ty } zt|d }~ww |	S )	Nz-c.res.rcZbrcc32z-fo z-P-o)Z_setup_compileappendextendr   r   KeyErrorospathnormpathmkpathdirnamespawnr   r   _c_extensions_cpp_extensionsr   )r   Zsources
output_dirmacrosinclude_dirsdebugextra_preargsextra_postargsZdependsobjectspp_optsZbuildZcompile_optsobjsrcextmsgZ	input_optZ
output_optr    r    r!   compileQ   s^   



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)r1   z/uskipping %s (up-to-date))	_fix_object_argslibrary_filename
_need_linkr.   r   r   r   r   r4   )	r   r7   Zoutput_libnamer1   r4   target_langoutput_filenameZlib_argsr<   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}|pg D ]}|d||f  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': %sZc0w32Zc0d32r$   r   z%s.defZEXPORTSz  %s=_%sz
writing %sr"   z/L%sz/L.,z,,Zimport32Zcw32mtr>   ) r?   Z_fix_lib_argsr   warnstrr)   r*   joinrA   r   Z
EXECUTABLEr   r   r   r   splitsplitextr-   r&   Zexecuter	   mapr+   normcaser'   find_library_filer,   r.   r   r   r   r4   ) r   Ztarget_descr7   rC   r1   Z	librariesZlibrary_dirsZruntime_library_dirsZexport_symbolsr4   r5   r6   Z
build_temprB   Zstartup_objZld_argsZdef_fileheadtailmodnamer;   Ztemp_dircontentsZsymZobjects2Z	resourcesfilebaselr   libfiler<   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 )NZ_dZ_bcpp)r)   r*   rH   r@   exists)	r   dirsr   r4   ZdlibZ	try_namesdirnamerU   r    r    r!   rM   4  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||f |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 '%s' (from '%s'))
r)   r*   rJ   rL   src_extensionsr   basenamer&   rH   obj_extension)r   Zsource_filenamesZ	strip_dirr1   Z	obj_namesZsrc_namerS   r;   r    r    r!   object_filenamesN  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   )Z_fix_compile_argsr   r&   r'   r   r
   r,   r)   r*   r-   r.   r   printr   )r   sourceZoutput_filer2   r3   r5   r6   _r8   Zpp_argsr<   r    r    r!   
preprocessi  s,   	



zBCPPCompiler.preprocess)r   r   r   )NNNr   NNN)Nr   N)
NNNNNr   NNNN)r   )r   r$   )NNNNN)__name__
__module____qualname____doc__Zcompiler_typeZexecutablesr/   r0   r[   r]   Zstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZexe_extensionr   r=   rD   rV   rM   r^   rb   r    r    r    r!   r      sZ    

D

 


r   )rf   r)   Zdistutils.errorsr   r   r   r   r   Zdistutils.ccompilerr   r   Zdistutils.file_utilr	   Zdistutils.dep_utilr
   Z	distutilsr   r   r    r    r    r!   <module>   s    