o 6aP{@sdZddlZddlZddlmZddlmZddlmZddl m Z m Z m Z ddl mZddlmZdd lmZdd lmZdd lmZmZmZmZmZmZdd lmZdd lmZm Z GdddeZdS)zC Modified version of build_ext that handles fortran source files. N)glob) newer_group) build_ext)DistutilsFileErrorDistutilsSetupErrorDistutilsError) copy_file)log)filepath_from_subprocess_output) combine_paths)filter_sourcesget_ext_source_filesget_numpy_include_dirshas_cxx_sources has_f_sources is_sequence)show_fortran_compilers)new_ccompiler_opt CCompilerOptc@seZdZdZejgdZejdddefgZejddgZdd Z d d Z d d Z dddZ ddZ ddZddZddZddZddZdS)rz:build C/C++/F extensions (compile/link to build directory)))z fcompiler=Nz!specify the Fortran compiler type)z parallel=jznumber 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 interfacezhelp-fcompilerNz list available Fortran compilersrrcCs8t|d|_d|_d|_d|_d|_d|_d|_dSN) old_build_extinitialize_options fcompilerparallel warn_error cpu_baseline cpu_dispatchdisable_optimization simd_testselfr$C/usr/lib/python3/dist-packages/numpy/distutils/command/build_ext.pyr4s  zbuild_ext.initialize_optionsc Cs|jrzt|j|_Wnty}ztd|d}~wwt|jtr+|jtj|_|jp/g}|j jdur:g|j _|j j|_|j |t || ddddddd|jtjd <dS) Nz)--parallel/-j argument must be an integerbuild)rr)rr)rr)rr)r r )r!r!r!)rint ValueError isinstance include_dirsstrsplitospathsep distributionextendrfinalize_optionsset_undefined_optionsr!rconf_target_groups)r#e incl_dirsr$r$r%r1>s0       zbuild_ext.finalize_optionsc" sjsdSdjrOjr=jjdr%tdj d}n"j d}d|_| | djjd<n d d}j |jnd}ddlm}ddlm}j}||jjjd_jjjjrjjd jjd jjstj d d d d }tj dj!|}tj"tj j#d}t$drj%&t'j|j(j)|d_%dd}ddl*}|+|j%tj j#d_,tj-j,st.j,i} |dur'|j/pgD],\} } | | vr"| | | kr"td| t0| | ddt0| ddf| | | <qjj/p-gD]\} } | | vr9q.| | | <q.t1} jD]} t1}g}g}g}| j/D]C} | | vr| | }||dg7}||dg7}|dgD] }||vr||qt| | idgD]}|2|qqS|r| j/|}t3d| j4| j/|f|| _/| j || _ |rt3d| j4|f| j5|| _5t6| j7r|2dt8| j7r|2d| j9pj:| j7}|r|2|d|vrd}nd|vrd}n d|vrd}nd}|r!||kr!| j9r!td | j4||f|| _9| ;|qEd| v}d| v}d| v}|r`||jjjd_<j<}|jj|d!|||=_}|j>jjjd"jd#_?j?}|r|j@}|j|r|Ar||nd$|d_?nd_?|rj>}|j>jjjd%jd#_BjB}|r|j@}|j|r|Ar||nd&|d_Bnd_BCfd'd(jD}|D]C}tj |d}jstj jD|}tEj,D]&} tj-|s&t.|| FGd)s0qtj j,| }!tH|!|qqdS)*N build_src build_clibzMbuild_clib already run, it is too late to ensure in-place build of build_clibr) new_compiler) new_fcompiler)compilerverbosedry_runforcez-Werrornumpy distutilsincludeznpy_cpu_dispatch_config.hzccompiler_opt_cache_ext.py compiler_opt)r;dispatch_hpathrr cache_pathcSs tdt|jdddS)Nz2 ########### EXT COMPILER OPTIMIZATION ###########T)full)r inforeport)coptr$r$r%rGs zbuild_ext.run..reportz.libszKlibrary %r defined more than once, overwriting build_info %s... with %s...i, libraries library_dirsmacrossource_languagesz-updating extension %r libraries from %r to %rz-extending extension %r defined_macros with %rf77c++f90cz.resetting extension %r language from %r to %r.)need_cxxF)r;r<r=r> requiref90 c_compilerz!f77_compiler=%s is not available.Tz!f90_compiler=%s is not available.cs"h|] }|jddqS).r)get_ext_fullnamenamer,).0extr"r$r% Bsz build_ext.run..z.dll)I extensions run_commandr/has_c_librariesinplacehave_rungetr warnget_command_objensure_finalizedrunget_finalized_commandrJappendr7distutils.ccompilerr9numpy.distutils.fcompilerr:r;r<r=r> customize customize_cmdr compiler_soshow_customizationr r-pathjoinr6abspath build_temphasattrrB cache_flushrrratexitregister extra_dll_dirisdirmakedirsrIreprsetaddrFrV define_macrosrsourcesrlanguagedetect_languageupdate _cxx_compiler cxx_compilerr _f77_compiler compiler_type get_version _f90_compilerbuild_extensions build_liblistdirlowerendswithr)"r#r7r9r:rrCopt_cache_pathrGrrclibslibname build_info all_languagesrX ext_languagesc_libs c_lib_dirsrKbinfoml new_c_libs ext_languageneed_f90_compilerneed_f77_compilerneed_cxx_compilerr;ctyper pkg_rootspkg_rootshared_lib_dirfn runtime_libr$r"r%rc`s|             $                               z build_ext.runcCs|Srr$)r#r{rZr$r$r% swig_sourcesRszbuild_ext.swig_sourcesc. s|j}|dus t|std|jt|}|sdS||j}|jrJ|d}d|dd}|d}| d}| |}t j || |} n t j |j| |} ||j} |j} |jsl|jsltdd} | s}t| | ds}td |jdStd |j|jpg} |jdd} |jD]}| |fqt|j\}}}}|jjd kr|r| d ||7}g}|jd kr|j }n|jdkr|j!}n|j p|j!}|durt"|dr|j#pgng|_#t"|dr|j$pgng|_$|j%}|r|durt&d|j|s|r|durt&d|j|jdvr#|dur#|'d|j|jdkr6|dur6|'d|jd|ji}|j(}|j)t*}g}g}g}g}|js| dj+}t j ddd}t j ||}|||jrpdn|}|f|df||f|dffD]\}} |D]| fddddD7} qq|j,}n|d g}!|rtd!|!|jj-|f||| |||j| |d"|7}!|rtd#|!|jj-|f||| |||j| d$|7}!|rtd%|!|jj.|f|| |||j| |d&|7}!|r#td'|!|j.|f|| |||j| |d&|7}!g}"g}#|rtd(|j/dd}$t j |j(t j 0| |}%|1|%|j2durTt3d)}&|"|4|$|%7}"|#|j.||j(| ||j|"|jd*7}#|j2durt3d)D]H}'|'|&vrqwt j |%|'}(t j 5|'t j 5|(krqwt j 6|(rt 7|(z |8|'|%Wqwt9yt'd+|'|%fYqww|rtd,|#|j.||j(| ||j|"|jd*7}#|#r|:|js|#})|!}*ng})|!|#}*|j;r|*<|j;|j=pg} |>|dd}+|j?dd},|jj@}-|jjd-vr!|A||+|,n|jdvr/|dur/|j@}-|jdkr=|dur=|j@}-|durM|B|*|+||,|)\}*}+|-|*| |+|,|jC| |D||j|j(|jd. dS)/Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesrTrbuild_pyz*Detected changes on compiler optimizationsTnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extensionmsvcz/Zm1000rOrMextra_f77_compile_argsextra_f90_compile_argsz5extension %r has C++ sourcesbut no C++ compiler foundz>extension %r has Fortran sources but no Fortran compiler found)rMrOzTextension %r has Fortran libraries but no Fortran linker found, using default linkerrNzLextension %r has C++ libraries but no C++ linker found, using default linkerdependsr6r?r@rA)z .dispatch.c)z .dispatch.cppz .dispatch.cxxcs&g|]}|r|qSr$)rpopindex)rWs_ext_srcr$r% s  z-build_ext.build_extension..)NPY_DISABLE_OPTIMIZATIONr8z#compiling C++ dispatch-able sources) output_dirsrc_dirrKr*debugextra_postargs ccompilerz!compiling C dispatch-able sources)rrrKr*rrzcompiling C sources)rrKr*rrzcompiling C++ sourcesz#compiling Fortran 90 module sourcesz*.mod)rrKr*rrrzfailed to move %r to %rzcompiling Fortran sources)rintelwintelemw)rIrJruntime_library_dirsrexport_symbolsrro target_lang)Er{rrrVlistrUr]r,rmrdget_package_dirr-rlget_ext_filenamerrr>r rB is_cachedr rrrFextra_compile_argsrz undef_macrosrer r;rr|rrrprrrrr`ror*rr6cpu_baseline_flags try_dispatchcompile module_dirsdirnamemkpathmodule_dir_switchrmodule_optionsrnisfileremove move_filercan_ccompiler_link extra_objectsr0extra_link_args get_librariesrJlink_shared_object_libs_with_msvc_and_fortran_process_unlinkable_fobjectsrget_export_symbols).r#rXr{fullnamemodpathpackagebaser package_dir ext_filenamer force_rebuild extra_argsrKundef c_sources cxx_sources f_sourcesfmodule_sourcesrrkwsrr*copt_c_sourcescopt_cxx_sourcescopt_baseline_flags copt_macrosbsrc_dirrCcopt_build_src_srcs_dst c_objectsr f_objectsrmodule_build_direxisting_modulesftunlinkable_fobjectsobjectsrIrJlinkerr$rr%build_extensionVs                                                zbuild_ext.build_extensioncCsP|dj}|dj}|jjtj|dg|jd}|jj |d||j ddS)Nr6r7zgfortran_vs2003_hack.c)r_gfortran_workaround)rr) rdr6r7r;rr-rlrmrocreate_static_libr)r#rr6r7rr$r$r%_add_dummy_mingwex_symJs    z build_ext._add_dummy_mingwex_symc Cst|}t|}t|}|ddD]`}|D][}tj||d}tj|rq||t|d} ||  Wdn1sEwYtj||d} t| d} ||  Wdn1slwYqq|rdd|D} |j | |j |j d} || ||fS)Nz .fobjectsrz .cobjectscSsg|]}tj|qSr$)r-rlrn)rWobjr$r$r%rnsz:build_ext._process_unlinkable_fobjects..)rrt) rr-rlrmrropenr0read splitlineswrap_unlinkable_objectsrort) r#rrIrrJrliblibdirfake_librc_libfobjectswrappedr$r$r%rSs2     z&build_ext._process_unlinkable_fobjectsc Cs|durdS|D]g}|drqd}|pgD]}tj|d|}tj|r+d}nq|r/qd}|D]/}tj|d|}tj|rbtj|j|d}t|||j|vr^||jd}nq3|rfqt d||fqg} |j D]'} | drz t d d | g} Wn t t jfyYnwt| } | | qu|| |jD]9} | ds|| t| d | d } | rtj|j| d} tj| st| d | |j|vr||jqdS)NrFz%s.libTzlib%s.az.libz+could not find library %r in directories %sz/usr/libcygpathz-wrz.ar) startswithr-rlrmrrorrer r`rJ subprocess check_outputOSErrorCalledProcessErrorr r0rIr )r#r c_librariesc_library_dirsr fileexistsrlibfilelibfile2 f_lib_dirsdirrpdst_namer$r$r%rvsj                  z%build_ext._libs_with_msvc_and_fortrancCs.||jg}|jD] }|t|q |Sr)check_extensions_listrZr0r )r# filenamesrXr$r$r%get_source_filess  zbuild_ext.get_source_filesc CsP||jg}|jD]}|jsq ||j}|tj|j | |q |Sr) rrZr{rUrVrer-rlrmrr)r#outputsrXrr$r$r% get_outputss   zbuild_ext.get_outputsr)__name__ __module__ __qualname__ descriptionr user_options help_optionsrboolean_optionsrr1rcrrrrrrrr$r$r$r%rs* " su #= r)!__doc__r-rrdistutils.dep_utilrdistutils.command.build_extrrdistutils.errorsrrrdistutils.file_utilrnumpy.distutilsr numpy.distutils.exec_commandr numpy.distutils.system_infor numpy.distutils.misc_utilr r rrrr'numpy.distutils.command.config_compilerrnumpy.distutils.ccompiler_optrrr$r$r$r%s