
    ;e=3                     v    	 d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 dddZ
 G d	 d
e          ZddZdS )    N)Command)DistutilsExecError)customize_compiler)logz.cz.cxx)czc++c                       e Zd ZdZg dZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd ZddZ	 	 ddZddZ	 	 ddZ	 	 ddZ	 	 ddZdddg fdZ	 	 ddZdS )configzprepare to build)	)z	compiler=Nzspecify the compiler type)zcc=Nzspecify the compiler executable)zinclude-dirs=Iz.list of directories to search for header files)zdefine=DzC preprocessor macros to define)zundef=Uz!C preprocessor macros to undefine)z
libraries=lz!external C libraries to link with)zlibrary-dirs=Lz.directories to search for external C libraries)noisyNz1show every action (compile, link, run, ...) taken)zdump-sourceNz=dump generated source files before attempting to compile themc                 v    d | _         d | _        d | _        d | _        d | _        d| _        d| _        g | _        d S )N   )compilerccinclude_dirs	librarieslibrary_dirsr   dump_source
temp_filesselfs    //usr/lib/python3.11/distutils/command/config.pyinitialize_optionszconfig.initialize_options3   sE       
     c                    | j         | j        j         pg | _         nCt          | j         t                    r)| j                             t
          j                  | _         | j        g | _        n't          | j        t                    r| j        g| _        | j        	g | _        d S t          | j        t                    r+| j                            t
          j                  | _        d S d S N)	r   distribution
isinstancestrsplitospathsepr   r   r   s    r   finalize_optionszconfig.finalize_optionsB   s    $ $ 1 > D"D)3// 	D $ 1 7 7
 C CD>!DNN,, 	."n-DN$ "D)3// 	D $ 1 7 7
 C CD	D 	Dr   c                     d S r    r   s    r   runz
config.runR   s    r   c                    	 ddl m}m} t          | j        |          s || j        | j        d          | _        t          | j                   | j        r| j                            | j                   | j	        r| j        
                    | j	                   | j        r#| j                            | j                   d S d S d S )Nr   )	CCompilernew_compilerr   )r   dry_runforce)distutils.ccompilerr+   r,   r!   r   r-   r   r   set_include_dirsr   set_librariesr   set_library_dirs)r   r+   r,   s      r   _check_compilerzconfig._check_compilerY   s    	
 	@???????$-33 		B(L$-15QH H HDMt}---  B..t/@AAA~ <++DN;;;  B..t/@AAAAA		B 		BB Br   c                 J   dt           |         z   }t          |d          5 }|r2|D ]}|                    d|z             |                    d           |                    |           |d         dk    r|                    d           d d d            n# 1 swxY w Y   |S )N_configtestwz#include <%s>

)LANG_EXTopenwrite)r   bodyheaderslangfilenamefileheaders          r   _gen_temp_sourcefilezconfig._gen_temp_sourcefilek   s     8D>1(C   	!D !% ; ;FJJ069::::

4   JJtBx4

4   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! s   A+BBBc                     |                      |||          }d}| j                            ||g           | j                            |||           ||fS )Nz_configtest.ir   )rB   r   extendr   
preprocess)r   r<   r=   r   r>   srcouts          r   _preprocesszconfig._preprocessw   s_    ''gt<<Sz***  c EEESzr   c                    |                      |||          }| j        rt          |d|z             | j                            |g          \  }| j                            ||g           | j                            |g|           ||fS )Nzcompiling '%s':rD   )rB   r   	dump_filer   object_filenamesr   rE   compile)r   r<   r=   r   r>   rG   objs          r   _compilezconfig._compile~   s    ''gt<< 	4c,s2333//66Sz***se,???Szr   c                 p   |                      ||||          \  }}t          j                            t          j                            |                    d         }	| j                            |g|	|||           | j        j        |	| j        j        z   }	| j        	                    |	           |||	fS )Nr   )r   r   target_lang)
rO   r$   pathsplitextbasenamer   link_executableexe_extensionr   append)
r   r<   r=   r   r   r   r>   rG   rN   progs
             r   _linkzconfig._link   s    ]]4,EE
cw 0 0 5 566q9%%seT093?26 	& 	8 	8 	8
 =&2$-55Dt$$$S$r   c                     |s| j         }g | _         t          j        dd                    |                     |D ]'}	 t	          j        |           # t          $ r Y $w xY wd S )Nzremoving: %s )r   r   infojoinr$   removeOSError)r   	filenamesr?   s      r   _cleanzconfig._clean   s     	!I DO)!4!4555! 	 	H	(####   	 	s   A
A A Nr   c                     	 ddl m} |                                  d}	 |                     ||||           n# |$ r d}Y nw xY w|                                  |S )Nr   CompileErrorTF)r/   rd   r3   rI   ra   r   r<   r=   r   r>   rd   oks          r   try_cppzconfig.try_cpp   s    	 	544444	T7L$???? 	 	 	BBB	 		s   8 AAc                    	 |                                   |                     ||||          \  }}t          |t                    rt	          j        |          }t          |          5 }d}		 |                                }
|
dk    rn|                    |
          rd}	n4d d d            n# 1 swxY w Y   | 	                                 |	S )NFT )
r3   rI   r!   r"   rerM   r:   readlinesearchra   )r   patternr<   r=   r   r>   rG   rH   r@   matchlines              r   
search_cppzconfig.search_cpp   s   	 	##D'<FFSgs## 	*j))G#YY 	$E}}2::>>$''  E	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   )8B--B14B1c                     	 ddl m} |                                  	 |                     ||||           d}n# |$ r d}Y nw xY wt	          j        |rdpd           |                                  |S )Nr   rc   TFsuccess!failure.)r/   rd   r3   rO   r   r\   ra   re   s          r   try_compilezconfig.try_compile   s    	 	544444	MM$t<<<BB 	 	 	BBB	 	"
0j111	s   8 AAc                     	 ddl m}m} |                                  	 |                     ||||||           d}	n# ||f$ r d}	Y nw xY wt          j        |	rdpd           |                                  |	S Nr   )rd   	LinkErrorTFrr   rs   )r/   rd   rw   r3   rY   r   r\   ra   )
r   r<   r=   r   r   r   r>   rd   rw   rf   s
             r   try_linkzconfig.try_link   s    	 	@???????	JJtWl ,6 6 6BBi( 	 	 	BBB	 	"
0j111	s   < 	AAc                 2   	 ddl m}m} |                                  	 |                     ||||||          \  }	}
}|                     |g           d}n# ||t          f$ r d}Y nw xY wt          j        |rdpd           | 	                                 |S rv   )
r/   rd   rw   r3   rY   spawnr   r   r\   ra   )r   r<   r=   r   r   r   r>   rd   rw   rG   rN   exerf   s                r   try_runzconfig.try_run   s    	 	@???????	 JJtWl'0,F FMCcJJuBBi);< 	 	 	BBB	 	"
0j111	s   6A A('A(r   c                    	 |                                   g }|r|                    d|z             |                    d           |r|                    d|z             n|                    d|z             |                    d           d                    |          dz   }|                     |||||          S )Nz
int %s ();zint main () {z  %s();z  %s;}r7   )r3   rW   r]   rx   )	r   funcr=   r   r   r   declcallr<   s	            r   
check_funczconfig.check_func  s    	 	 	-KKt+,,,O$$$ 	(KK	D())))KK$'''Cyy%}}T7L&6 6 	6r   c                 f    	 |                                   |                     d|||g|z   |          S )Nzint main (void) { })r3   rx   )r   libraryr   r=   r   other_librariess         r   	check_libzconfig.check_lib4  sG    	 	}}2G\%Y8,H H 	Hr   c                 6    	 |                      d|g|          S )Nz/* No body */)r<   r=   r   )rg   )r   rA   r   r   r>   s        r   check_headerzconfig.check_headerB  s-    	 ||6()5  7 7 	7r   )NNNr   )NNr   )NNNNr   )NNNNr   r   )__name__
__module____qualname__descriptionuser_optionsr   r&   r)   r3   rB   rI   rO   rY   ra   rg   rp   rt   rx   r|   r   r   r   r(   r   r   r	   r	      s       $K
 
 
L4  D D D   B B B$
 
 
         	 	 	,   $ IM   8     IM),   & HL(+   2 ;?CD6 6 6 6< /3D#RH H H H DH7 7 7 7 7 7r   r	   c                 &   	 |t          j        d|            nt          j        |           t          |           }	 t          j        |                                           |                                 d S # |                                 w xY w)Nz%s)r   r\   r:   readclose)r?   headr@   s      r   rK   rK   K  s{     |x    >>D



s   &A: :Br   )r$   rj   distutils.corer   distutils.errorsr   distutils.sysconfigr   	distutilsr   r9   r	   rK   r(   r   r   <module>r      s   	  " " " " " " / / / / / / 2 2 2 2 2 2      f%%t7 t7 t7 t7 t7W t7 t7 t7l	     r   