o
    ʩZh׀                     @   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$   X/var/www/html/lang_env/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st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,st. j, i }	|d ur'|j/pg 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| |_|rt3d|j4|f  |j5| |_5t6|j7r|2d t8|j7r|2d |j9p j:|j7}|r|2| d|v rd}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pg }t|dd pg }t|dd pg }|jd d  }|jD ]}||f qt|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$pg 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 }#|rtd# |#| jj.|f|| || || j|| |d$|7 }#|rt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 }%|rtd* |j0d d  }&tj| j)tj1| |}'| 2|' |j3d u rot4d+}(|$|5|&|'7 }$|%|j/|| j)||| j|$|jd,7 }%|j3d u rt4d+D ]H})|)|(v rqtj|'|)}*tj6|)tj6|*krqtj7|*rt8|* z	| 9|)|' W q t:y   t(d-|)|'f  Y qw |rt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|rd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rz
td	d
|
g}
W n ttjfy   Y nw t|
}
|	|
 qu||	 |jD ]9}| ds|| t|	d| d }|rtj| j|d }tj|st|d | | j|vr|| j qd 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     