o
    [ZŽh×€  ã                   @   sÌ   d Z 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
mZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZmZmZmZmZ ddlmZ ddlmZm Z  G dd„ deƒZdS )zC Modified version of build_ext that handles fortran source files.

é    N)Úglob)Únewer_group)Ú	build_ext)ÚDistutilsFileErrorÚDistutilsSetupErrorÚDistutilsError)Ú	copy_file)Úlog)Úfilepath_from_subprocess_output)Úcombine_paths)Úfilter_sourcesÚget_ext_source_filesÚget_numpy_include_dirsÚhas_cxx_sourcesÚhas_f_sourcesÚis_sequence)Úshow_fortran_compilers)Únew_ccompiler_optÚCCompilerOptc                   @   s’   e Zd ZdZejg d¢ Zejdddefg Zejddg Zdd	„ Z	d
d„ Z
dd„ Zddd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r   z:build C/C++/F extensions (compile/link to build directory)))z
fcompiler=Nz!specify the Fortran compiler type)z	parallel=Újznumber of parallel jobs)ú
warn-errorNz'turn all warnings into errors (-Werror))zcpu-baseline=Nz4specify a list of enabled baseline CPU optimizations)zcpu-dispatch=Nz.specify a list of dispatched CPU optimizations)údisable-optimizationNz1disable CPU optimized code(dispatch,simd,fast...))z
simd-test=NzMspecify a list of CPU optimizations to be tested against NumPy SIMD interfacezhelp-fcompilerNz list available Fortran compilersr   r   c                 C   s8   t  | ¡ d | _d | _d | _d | _d | _d | _d | _d S ©N)	Úold_build_extÚinitialize_optionsÚ	fcompilerÚparallelÚ
warn_errorÚcpu_baselineÚcpu_dispatchÚdisable_optimizationÚ	simd_test©Úself© r$   úP/var/www/auris/lib/python3.10/site-packages/numpy/distutils/command/build_ext.pyr   4   s   

zbuild_ext.initialize_optionsc              
   C   sº   | j rzt| j ƒ| _ W n ty } ztdƒ|‚d }~ww t| jtƒr+| j tj¡| _| jp/g }| j	jd u r:g | j	_| j	j| _| j 
|¡ t | ¡ |  ddddddd¡ | jtjd	< d S )
Nz)--parallel/-j argument must be an integerÚbuild)r   r   )r   r   )r   r   )r   r   )r    r    )r!   r!   r!   )r   ÚintÚ
ValueErrorÚ
isinstanceÚinclude_dirsÚstrÚsplitÚosÚpathsepÚdistributionÚextendr   Úfinalize_optionsZset_undefined_optionsr!   r   Zconf_target_groups)r#   ÚeZ	incl_dirsr$   r$   r%   r1   >   s0   
€ÿ


úzbuild_ext.finalize_optionsc           #   	      sž  ˆ j sd S ˆ  d¡ ˆ j ¡ rOˆ jr=ˆ jj d¡r%t d¡ ˆ j 	d¡}n"ˆ j 	d¡}d|_| 
¡  | ¡  dˆ jjd< n
ˆ  d¡ ˆ  d¡}ˆ j |j¡ nd }ddlm} ddlm} ˆ j}||ˆ jˆ jˆ jdˆ _ˆ j ˆ j¡ ˆ j ˆ ¡ ˆ jrŠˆ jj d	¡ ˆ jj d	¡ ˆ j ¡  ˆ jsØtj  d
ddd¡}tj  ˆ  d¡j!|¡}tj "tj  ˆ j#d¡¡}t$ˆ dƒr¼ˆ j% &¡  t'ˆ j|ˆ j(ˆ j)|dˆ _%dd„ }dd l*}| +|ˆ j%¡ tj  ˆ j#d¡ˆ _,tj -ˆ j,¡sît .ˆ j,¡ i }	|d ur'|j/pùg D ],\}
}|
|	v r"|	|
 |kr"t d|
t0|	|
 ƒd d… t0|ƒd d… f ¡ ||	|
< qúˆ jj/p-g D ]\}
}|
|	v r9q.||	|
< q.t1ƒ }ˆ j D ]ñ}t1ƒ }g }g }g }|j/D ]C}
|
|	v r‚|	|
 }|| dg ¡7 }|| dg ¡7 }| dg ¡D ]}||vr€| |¡ qt|	 |
i ¡ dg ¡D ]}| 2|¡ qŒqS|r´|j/| }t 3d|j4|j/|f ¡ ||_/|j| |_|rÇt 3d|j4|f ¡ |j5| |_5t6|j7ƒrÒ| 2d¡ t8|j7ƒrÝ| 2d¡ |j9pçˆ j :|j7¡}|rð| 2|¡ d|v rød}nd}d}d |v rd }d!}n	d|v rd}d!}|j9r|r-|r-||kr-|j9r-t d"|j4||f ¡ ||_9| ;|¡ qEd |v }d|v }d|v }|rl||ˆ jˆ jˆ jdˆ _<ˆ j<}|jˆ j|d# | ˆ ¡ | ¡  | =¡ ˆ _<nd ˆ _<|r±ˆ j>}|ˆ j>ˆ jˆ jˆ jdˆ jd$ˆ _?ˆ j?}|r”|j@}| ˆ j¡ |r¦| A¡ r¦| ˆ ¡ | ¡  nˆ  d%| ¡ d ˆ _?nd ˆ _?|röˆ j>}|ˆ j>ˆ jˆ jˆ jd!ˆ jd$ˆ _Bˆ jB}|rÙ|j@}| ˆ j¡ |rë| A¡ rë| ˆ ¡ | ¡  nˆ  d&| ¡ d ˆ _Bnd ˆ _Bˆ  C¡  ‡ fd'd(„ˆ j D ƒ}|D ]C}tj  |d¡} ˆ jstj  ˆ jD| ¡} t Eˆ j,¡D ]&}!tj -| ¡s2t .| ¡ |! F¡  Gd)¡s<q$tj  ˆ j,|!¡}"tH|"| ƒ q$q	d S )*NÚ	build_srcÚ
build_clibzMbuild_clib already run, it is too late to ensure in-place build of build_clibé   r   )Únew_compiler)Únew_fcompiler)ÚcompilerÚverboseÚdry_runÚforcez-WerrorÚnumpyÚ	distutilsÚincludeznpy_cpu_dispatch_config.hzccompiler_opt_cache_ext.pyÚcompiler_opt)r8   Údispatch_hpathr   r   Ú
cache_pathc                 S   s    t  d¡ t  | jdd¡ d S )Nz2
########### EXT COMPILER OPTIMIZATION ###########T)Úfull)r	   ÚinfoÚreport)Zcoptr$   r$   r%   rD   ¨   s   
zbuild_ext.run.<locals>.reportz.libszKlibrary %r defined more than once, overwriting build_info
%s... 
with
%s...i,  Ú	librariesÚlibrary_dirsÚmacrosZsource_languagesz-updating extension %r libraries from %r to %rz-extending extension %r defined_macros with %rÚf77úc++ÚcFÚf90Tz.resetting extension %r language from %r to %r.)Zneed_cxx)r8   r9   r:   r;   Z
requiref90Z
c_compilerz!f77_compiler=%s is not available.z!f90_compiler=%s is not available.c                    s"   h | ]}ˆ   |j¡ d ¡d ’qS )Ú.r   )Úget_ext_fullnameÚnamer,   )Ú.0Úextr"   r$   r%   Ú	<setcomp>S  s    ÿÿz build_ext.run.<locals>.<setcomp>z.dll)IÚ
extensionsÚrun_commandr/   Zhas_c_librariesÚinplaceZhave_runÚgetr	   ÚwarnZget_command_objZensure_finalizedÚrunÚget_finalized_commandrF   Úappendr4   Zdistutils.ccompilerr6   Znumpy.distutils.fcompilerr7   r8   r9   r:   r;   Z	customizeZcustomize_cmdr   Zcompiler_soZshow_customizationr    r-   ÚpathÚjoinr3   ÚabspathÚ
build_tempÚhasattrr?   Zcache_flushr   r   r   ÚatexitÚregisterÚextra_dll_dirÚisdirÚmakedirsrE   ÚreprÚsetÚaddrC   rN   Údefine_macrosr   Úsourcesr   ÚlanguageZdetect_languageÚupdateÚ_cxx_compilerÚcxx_compilerr   Ú_f77_compilerÚcompiler_typeÚget_versionÚ_f90_compilerZbuild_extensionsÚ	build_libÚlistdirÚlowerÚendswithr   )#r#   r4   r6   r7   rn   r@   Zopt_cache_pathrD   r_   ZclibsÚlibnameZ
build_infoZall_languagesrP   Zext_languagesZc_libsZ
c_lib_dirsrG   ZbinfoÚmÚlZ
new_c_libsZext_languageZhas_fortranZneed_f90_compilerZneed_f77_compilerZneed_cxx_compilerr8   Úctyper   Z	pkg_rootsZpkg_rootZshared_lib_dirÚfnZruntime_libr$   r"   r%   rW   `   s„  


ÿÿ

ý
ÿ

ý
$þ






€ÿ
ÿÿ






ÿý
û

ÿû

ÿ
þ
úüzbuild_ext.runc                 C   s   |S r   r$   )r#   rh   rR   r$   r$   r%   Úswig_sourcesc  s   zbuild_ext.swig_sourcesc           1         s:  |j }|d u st|ƒstd|j ƒ‚t|ƒ}|sd S |  |j¡}| jrJ| d¡}d |dd… ¡}|d }|  	d¡}| 
|¡}tj ||  |¡¡}	ntj | j|  |¡¡}	||j }
| j}| jsl| j ¡ slt d¡ d}|s}t|
|	dƒs}t d	|j¡ d S t d
|j¡ |jpˆg }t|dd ƒpg }t|dd ƒp˜g }|jd d … }|jD ]}| |f¡ q£t|j ƒ\}}}}| jjdkrÌ|rÆ| d¡ ||7 }||7 }g }|j dkrÕ| j!}n|j dkrÞ| j"}n| j!pã| j"}|d urt#|dƒró|j$pòg ng |_$t#|dƒr|j%pg ng |_%| j&}|r|d u rt'd|j ƒ‚|s|r)|d u r)t'd|j ƒ‚|j dv r<|d u r<|  (d|j ¡ |j dkrO|d u rO|  (d|j ¡ d|ji}| j)}|j*t+ƒ  }g }g }g }g }| jsµ|  	d¡j,}tj ddd¡}tj ||¡}| |¡ |} |f|df||f|dffD ]\}!}"‰ |!D ]‰|"‡ ‡fd d!„ˆd d … D ƒ7 }"q™q’| j -¡ }n| d"¡ g }#|rÝt d#¡ |#| jj.|f|| || || j|| |d$œ|¤Ž7 }#|rýt d%¡ |#| jj.|f|| || || j|| d&œ|¤Ž7 }#|rt d'¡ |#| jj/|f||| || j|| | d(œ|¤Ž7 }#|r>t d)¡ |#|j/|f||| || j|| | d(œ|¤Ž7 }#g }$g }%|rÛt d*¡ |j0d d … }&tj | j)tj 1|  |¡¡¡}'|  2|'¡ |j3d u rot4d+ƒ}(|$| 5|&|'¡7 }$|%|j/|| j)||| j|$|jd,7 }%|j3d u rÛt4d+ƒD ]H})|)|(v r›q’tj |'|)¡}*tj 6|)¡tj 6|*¡kr±q’tj 7|*¡r½t 8|*¡ z	|  9|)|'¡ W q’ t:yÚ   t (d-|)|'f ¡ Y q’w |rôt d.¡ |%|j/|| j)||| j|$|jd,7 }%|%r| ;| j¡s|%}+|#},ng }+|#|% },|j<r|, =|j<¡ |j>pg }|  ?|¡d d … }-|j@d d … }.| jjA}/| jjd/v rZ|  B||-|.¡ |jCrY|jCD ]}0t4|0d0 ƒD ]	})tD|)| jEƒ qJqBg |_Cn|j dv rh|d urh|jA}/|j dkrv|d urv|jA}/|d ur†|  F|,|-||.|+¡\},}-|/|,|	|-|.|jC||  G|¡| j| j)|j d1
 d S )2Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesrL   r   éÿÿÿÿÚbuild_pyz*Detected changes on compiler optimizationsTÚnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extensionZextra_c_compile_argsZextra_cxx_compile_argsÚmsvcz/Zm1000rK   rH   Úextra_f77_compile_argsÚextra_f90_compile_argsz5extension %r has C++ sourcesbut no C++ compiler foundz>extension %r has Fortran sources but no Fortran compiler found)rH   rK   zTextension %r has Fortran libraries but no Fortran linker found, using default linkerrI   zLextension %r has C++ libraries but no C++ linker found, using default linkerÚdependsr3   r<   r=   r>   )z.dispatch.c)z.dispatch.cppz.dispatch.cxxc                    s&   g | ]}|  ˆ ¡rˆ ˆ |¡¡‘qS r$   )rt   ÚpopÚindex)rO   Ús©Z_extZ_srcr$   r%   Ú
<listcomp>ß  s
    
þÿz-build_ext.build_extension.<locals>.<listcomp>)ZNPY_DISABLE_OPTIMIZATIONr5   z#compiling C++ dispatch-able sources)Ú
output_dirÚsrc_dirrG   r*   ÚdebugÚextra_postargsZ	ccompilerz!compiling C dispatch-able sources)r‡   rˆ   rG   r*   r‰   rŠ   zcompiling C sources)r‡   rG   r*   r‰   rŠ   zcompiling C++ sourcesz#compiling Fortran 90 module sourcesz*.mod)r‡   rG   r*   r‰   rŠ   r   zfailed to move %r to %rzcompiling Fortran sources)r~   ZintelwZintelemwz/*.dll)rE   rF   Úruntime_library_dirsrŠ   Zexport_symbolsr‰   r]   Ztarget_lang)Hrh   r   r   rN   ÚlistrM   rT   r,   r[   rX   Zget_package_dirr-   rZ   Úget_ext_filenamerq   r   r;   r    r?   Z	is_cachedr	   r‰   r   rC   Zextra_compile_argsÚgetattrrg   Zundef_macrosrY   r   r8   rn   ri   rp   rm   r^   r   r€   rk   r   rV   r]   r*   r   r3   Zcpu_baseline_flagsZtry_dispatchÚcompileÚmodule_dirsÚdirnameZmkpathZmodule_dir_switchr   Zmodule_optionsr\   ÚisfileÚremoveZ	move_filer   Zcan_ccompiler_linkZextra_objectsr0   Zextra_link_argsZget_librariesrF   Zlink_shared_objectÚ_libs_with_msvc_and_fortranr‹   r   ra   Ú_process_unlinkable_fobjectsZget_export_symbols)1r#   rP   rh   ÚfullnameÚmodpathÚpackageÚbaser|   Zpackage_dirZext_filenamer   Zforce_rebuildÚ
extra_argsZextra_cflagsZextra_cxxflagsrG   ZundefÚ	c_sourcesZcxx_sourcesZ	f_sourcesZfmodule_sourcesr   rl   Úkwsr‡   r*   Zcopt_c_sourcesZcopt_cxx_sourcesZcopt_baseline_flagsZcopt_macrosZbsrc_dirr@   Zcopt_build_srcZ_srcsZ_dstZ	c_objectsrŠ   Z	f_objectsr   Zmodule_build_dirZexisting_modulesÚfÚtÚunlinkable_fobjectsÚobjectsrE   rF   ZlinkerÚdr$   r…   r%   Úbuild_extensiong  s  þÿ


ÿ
ÿ




ÿ



ÿ€ÿÿ€ÿÿÿÿÿ


ÿþ
þÿ

ÿø	÷
ÿùø	
ÿÿúø	
ÿÿúø


ÿÿ
ÿú

ÿÿ
úÿ
ÿ€
ý
øzbuild_ext.build_extensionc                 C   sP   |   d¡j}|   d¡j}| jjtj |d¡g| jd}| jj	|d|| j
d d S )Nr3   r4   zgfortran_vs2003_hack.c)r‡   Z_gfortran_workaround)r‡   r‰   )rX   r3   r4   r8   r   r-   rZ   r[   r]   Zcreate_static_libr‰   )r#   r›   r3   r4   r    r$   r$   r%   Ú_add_dummy_mingwex_symv  s   ÿþ

ÿz build_ext._add_dummy_mingwex_symc              
   C   s  t |ƒ}t |ƒ}t |ƒ}|d d … D ]^}|D ]Y}tj ||d ¡}tj |¡ro| |¡ t|ƒ}	| |	 ¡  	¡ ¡ W d   ƒ n1 sDw   Y  tj ||d ¡}
t|
ƒ}	| |	 ¡  	¡ ¡ W d   ƒ n1 sjw   Y  qq|r‰dd„ |D ƒ}|j
|| j| jd}| |¡ ||fS )Nz	.fobjectsz	.cobjectsc                 S   s   g | ]}t j |¡‘qS r$   )r-   rZ   r\   )rO   Úobjr$   r$   r%   r†   š  s    z:build_ext._process_unlinkable_fobjects.<locals>.<listcomp>)r‡   ra   )rŒ   r-   rZ   r[   r’   r“   Úopenr0   ÚreadÚ
splitlinesZwrap_unlinkable_objectsr]   ra   )r#   r    rE   r   rF   rŸ   ÚlibÚlibdirZfake_libr   Zc_libZfobjectsÚwrappedr$   r$   r%   r•     s2   

ÿ
ÿ€öþ
z&build_ext._process_unlinkable_fobjectsc              
   C   sÂ  |d u rd S |D ]g}|  d¡rqd}|pg D ]}tj |d| ¡}tj |¡r+d} nq|r/qd}|D ]/}tj |d| ¡}tj |¡rbtj | j|d ¡}t||ƒ | j|vr^| | j¡ d} nq3|rfqt 	d||f ¡ qg }	|j
D ]'}
|
  d¡r—z
t d	d
|
g¡}
W n ttjfy’   Y nw t|
ƒ}
|	 |
¡ qu| |	¡ |jD ]9}|  d¡sÞ| |¡ t|	d| d ƒ}|rÞtj | j|d ¡}tj |¡sÓt|d |ƒ | j|vrÞ| | j¡ q¥d S )Nr~   Fz%s.libTzlib%s.az.libz+could not find library %r in directories %sz/usr/libZcygpathz-wr¨   z.ar   )Ú
startswithr-   rZ   r[   r’   r]   r   rY   r	   rV   rF   Ú
subprocessÚcheck_outputÚOSErrorÚCalledProcessErrorr
   r0   rE   r   )r#   r   Zc_librariesZc_library_dirsru   Z
fileexistsr©   ZlibfileZlibfile2Z
f_lib_dirsÚdirr¨   ÚpZdst_namer$   r$   r%   r”   ¢  sj   
þ

ø	ÿ

ÿ




€÷z%build_ext._libs_with_msvc_and_fortranc                 C   s.   |   | j¡ g }| jD ]	}| t|ƒ¡ q|S r   )Úcheck_extensions_listrR   r0   r   )r#   Ú	filenamesrP   r$   r$   r%   Úget_source_filesß  s
   
zbuild_ext.get_source_filesc              	   C   sP   |   | j¡ g }| jD ]}|jsq|  |j¡}| tj | j	|  
|¡¡¡ q|S r   )r²   rR   rh   rM   rN   rY   r-   rZ   r[   rq   r   )r#   ZoutputsrP   r–   r$   r$   r%   Úget_outputsæ  s   
ÿzbuild_ext.get_outputsr   )Ú__name__Ú
__module__Ú__qualname__Údescriptionr   Zuser_optionsZhelp_optionsr   Zboolean_optionsr   r1   rW   rz   r¢   r£   r•   r”   r´   rµ   r$   r$   r$   r%   r      s.    ÿÿ
"  
  	#=r   )!Ú__doc__r-   r¬   r   Zdistutils.dep_utilr   Zdistutils.command.build_extr   r   Zdistutils.errorsr   r   r   Zdistutils.file_utilr   Znumpy.distutilsr	   Znumpy.distutils.exec_commandr
   Znumpy.distutils.system_infor   Znumpy.distutils.misc_utilr   r   r   r   r   r   Z'numpy.distutils.command.config_compilerr   Znumpy.distutils.ccompiler_optr   r   r$   r$   r$   r%   Ú<module>   s     