o
    >~#guK                     @   s   d Z ddlZddlmZ ddl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mZmZmZmZmZ dd	lmZ ejZeeeD ]Zee d d
v rhee d d fee dd  ee< qKG dd deZdS )zC Modified version of build_clib that handles fortran source files.
    N)glob)
build_clib)DistutilsSetupErrorDistutilsErrorDistutilsFileError)log)newer_group)filter_sourcesget_lib_source_filesget_numpy_include_dirshas_cxx_sourceshas_f_sourcesis_sequence)new_ccompiler_opt)z
build-clibz
build-temp=   c                   @   st   e Zd ZdZejg d Zejg d Zdd Zdd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd Zdd ZdS )r   z1build C/C++/F libraries used by Python extensions))z
fcompiler=Nz!specify the Fortran compiler type)inplaceizBuild in-place)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...))r   r   r   c                 C   s8   t |  d | _d| _d | _d | _d | _d | _d | _d S )Nr   )	old_build_clibinitialize_options	fcompilerr   parallel
warn_errorcpu_baselinecpu_dispatchdisable_optimization)self r    /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/numpy/distutils/command/build_clib.pyr   1   s   

zbuild_clib.initialize_optionsc              
   C   s\   | j rzt| j | _ W n ty } ztd|d }~ww t|  | dddddd d S )Nz)--parallel/-j argument must be an integerbuild)r   r   )r   r   )r   r   )r   r   )r   r   )r   int
ValueErrorr   finalize_optionsset_undefined_options)r   er    r    r!   r%   <   s   

zbuild_clib.finalize_optionsc                 C   *   | j D ]\}}t|dg r dS qdS NsourcesTF)	librariesr   getr   lib_name
build_infor    r    r!   have_f_sourcesK   
   zbuild_clib.have_f_sourcesc                 C   r(   r)   )r+   r   r,   r-   r    r    r!   have_cxx_sourcesQ   r1   zbuild_clib.have_cxx_sourcesc                 C   sN  | j sd S g }| d | j D ]\}}|dd }|r$||vr$|| qddlm} || j| j| jd| _| jj	| j
|  d | jrR| jjd | jjd | j }d | _ | j|  || _ | 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 |   rddl!m"} || j#| j$| j| jd|v | jd| _%| j%d ur| j%	| j
 | j }d | _ | j%|  || _ | j%  nd | _%| &| j  | j'r#| j
j(D ]'}| j)|j*}tj| j+|}tj|j,|}| -|j, t./|| qd S d S )N	build_srclanguager   )new_compiler)compilerdry_runforce)need_cxxz-Werrornumpy	distutilsincludeznpy_cpu_dispatch_config.hzccompiler_opt_cache_clib.pycompiler_opt)r6   dispatch_hpathr   r   
cache_pathc                 S   s    t d t | jdd d S )Nz3
########### CLIB COMPILER OPTIMIZATION ###########T)full)r   inforeport)coptr    r    r!   rB      s   
zbuild_clib.run.<locals>.reportnew_fcompilerf90r6   verboser7   r8   
requiref90
c_compiler)0r+   run_commandr,   appenddistutils.ccompilerr5   r6   r7   r8   	customizedistributionr2   r   compiler_socustomize_cmdshow_customizationr   ospathjoinget_finalized_commandr3   abspath
build_temphasattrr=   cache_flushr   r   r   atexitregisterr0   numpy.distutils.fcompilerrE   r   rH   _f_compilerbuild_librariesr   installed_librarieslibrary_filenamenamer   
target_dirmkpathshutilcopy)r   	languagesr.   r/   lr5   r+   r>   opt_cache_pathrB   r[   rE   libnamesourcetargetr    r    r!   runW   s   







zbuild_clib.runc                 C   s.   |  | j g }| jD ]	}|t| q|S N)check_library_listr+   extendr
   )r   	filenameslibr    r    r!   get_source_files   s
   
zbuild_clib.get_source_filesc                 C   s    |D ]\}}|  ||| qd S rn   )build_a_library)r   r+   r.   r/   r    r    r!   r_      s   zbuild_clib.build_librariesc                 C   s>   |du rg S g }|D ]}t |r||| 7 }q
|| q
|S )ah   Assemble flags from flag list

        Parameters
        ----------
        in_flags : None or sequence
            None corresponds to empty list.  Sequence elements can be strings
            or callables that return lists of strings. Callable takes `self` as
            single parameter.

        Returns
        -------
        out_flags : list
        N)callablerL   )r   in_flags	out_flagsin_flagr    r    r!   assemble_flags   s   zbuild_clib.assemble_flagsc           0         s  | j }| j}|d}|d u st|std| t|}t|\}}}	}
|
  p0|dddk}g }|r:|d |rA|d |rI|d n|	rP|d ||d< |j|| j	d	}||d
g  }| j
}| jsv| j svtd d}|st||dstd| d S td| |di }|d ur|rtd|f  ddlm} ||j| j| j| j
|| j d}|d ur| j}|d }|| || |	s|
r|d u rtd| |d ur|dpg |_|dpg |_|d}|d u rg }|d}|d u rg }| |d}| |d}| |d}| t!  |dp+g }t"j#$|}|r:| %| |jdkrJ||7 }g }||7 }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*|| j+|!|| || j|| |%d)7 }$|rtd* |$| jj*|| j+|!|| || j|| d+7 }$|rtd, |$|j,|| j+|| || j|| | d-7 }$|r%td. |- }%|%j,|| j+|| || j|| | d-}&|$ |& |	s+|
rg }g }'|rD|j.d u r<t/d/}(||0||7 }|
r[td0 |'|j,|
| j+||| j|d-7 }'|r| jj.d u rt/d/D ]H})|)|(v rrqit"j#(||)}*t"j#1|)t"j#1|*krqit"j#2|*rt"3|* z	| 4|)| W qi t5y   t6d1|)|f  Y qiw |	rtd2 |'|j,|	| j+||| j|d-7 }'ng }'|'rQ|7|sQt"j#(| j	|d3 }+t8|+d4})|)9d5(d6d7 |'D  W d    n	1 sw   Y  t"j#(| j	|d8 }+t8|+d4})|)9d5(d9d7 |$D  W d    n	1 s*w   Y  t"j#(| j	||j: },t8|,d:})W d    n	1 sKw   Y  n|$ |' |j;|$|| j	| jd; |d<g }-|D ]\}.}/|.|-v r{|- |/d<g  qi|-r|-|d<< d S d S )=Nr*   zfin 'libraries' option (library '%s'), 'sources' must be present and must be a list of source filenamesr4   crF   zc++f77source_languages)
output_dirdependsz*Detected changes on compiler optimizationsTnewerz"skipping '%s' library (up-to-date)zbuilding '%s' library	config_fczEusing additional config_fc from setup script for fortran compiler: %sr   rD   rG   z<library %s has Fortran sources but no Fortran compiler foundextra_f77_compile_argsextra_f90_compile_argsmacrosinclude_dirsextra_compiler_argsextra_cflagsextra_cxxflagsmodule_dirsmsvcr3   r:   r;   r<   )z.dispatch.c)z.dispatch.cppz.dispatch.cxxc                    s&   g | ]}|  r|qS r    )endswithpopindex).0s_ext_srcr    r!   
<listcomp>K  s
    
z.build_clib.build_a_library.<locals>.<listcomp>)NPY_DISABLE_OPTIMIZATIONr   z#compiling C++ dispatch-able sources)r}   src_dirr   r   debugextra_postargs	ccompilerz!compiling C dispatch-able sources)r}   r   r   r   r   r   zcompiling C sources)r}   r   r   r   r   zcompiling C++ sourcesz*.modz#compiling Fortran 90 module sourceszfailed to move %r to %rzcompiling Fortran sourcesz	.fobjectsw
c                 s       | ]	}t j|V  qd S rn   rS   rT   rW   r   objr    r    r!   	<genexpr>      z-build_clib.build_a_library.<locals>.<genexpr>z	.cobjectsc                 s   r   rn   r   r   r    r    r!   r     r   wb)r}   r   r+   )<r6   r^   r,   r   r   listr	   rL   ra   r   r8   r   r=   	is_cachedr   r   r   rA   r]   rE   compiler_typerH   r7   rO   get_option_dictrf   updaterN   r   r   r   ry   rp   r   rS   rT   dirnamerd   rV   r3   rU   cpu_baseline_flagstry_dispatchrX   compilecxx_compilermodule_dir_switchr   module_optionsrW   isfileremove	move_filer   warncan_ccompiler_linkopenwritestatic_lib_extensioncreate_static_lib)0r   r/   r.   r+   r6   r   r*   	c_sourcescxx_sources	f_sourcesfmodule_sourcesrI   r|   lib_filer~   force_rebuildr   rE   distbase_config_fcr   r   r   r   r   r   module_build_dircopt_c_sourcescopt_cxx_sourcescopt_baseline_flagscopt_macrosbsrc_dirr>   copt_build_src_srcs_dstobjectsr   cxx_objects	f_objectsexisting_modulesftlistfn	lib_fnameclib_librarieslnamebinfor    r   r!   rt      s  

















	



	








zbuild_clib.build_a_libraryN)__name__
__module____qualname__descriptionr   user_optionsboolean_optionsr   r%   r0   r2   rm   rs   r_   ry   rt   r    r    r    r!   r      s    Zr   )__doc__rS   r   re   distutils.command.build_clibr   r   distutils.errorsr   r   r   numpy.distutilsr   distutils.dep_utilr   numpy.distutils.misc_utilr	   r
   r   r   r   r   numpy.distutils.ccompiler_optr   r   _lrangelen_ir    r    r    r!   <module>   s      &