U C^Bg@sdZddlmZmZmZddlZddlZddlmZddlm Z ddl m Z ddl mZmZmZddlmZdd lmZdd lmZdd lmZmZdd lmZmZmZmZmZm Z m!Z!m"Z"dd l#m$Z$Gddde Z dS)zC Modified version of build_ext that handles fortran source files. )divisionabsolute_importprint_functionN)glob) newer_group) build_ext)DistutilsFileErrorDistutilsSetupErrorDistutilsError) copy_file)log)filepath_from_subprocess_output) combine_paths system_info)filter_sources has_f_sourceshas_cxx_sourcesget_ext_source_filesget_numpy_include_dirs is_sequenceget_build_architecture msvc_version)show_fortran_compilersc@seZdZdZejdddgZejdddefgZejdgZd d Z d d Z d dZ 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)zhelp-fcompilerNz list available Fortran compilersrcCs t|d|_d|_d|_dSN) old_build_extinitialize_options fcompilerparallel warn_errorselfr#D/tmp/pip-install-6_kvzl1k/numpy/numpy/distutils/command/build_ext.pyr/s zbuild_ext.initialize_optionscCs|jr4zt|j|_Wntk r2tdYnXt|jtrP|jtj|_|jpXg}|j jdkrng|j _|j j|_|j |t || ddddS)Nz)--parallel/-j argument must be an integerbuild)rr)r r )rint ValueError isinstance include_dirsstrsplitospathsep distributionextendrfinalize_optionsset_undefined_options)r"Z incl_dirsr#r#r$r05s"      zbuild_ext.finalize_optionsc sjs dSdjrjrzjjdrJtdj d}qj d}d|_| | djjd<nd d}j |jnd}ddlm}ddlm}j}||jjjd_jjjjrjjd jjd jtjj d _!tj"j!sNt#j!i}|dk r|j$pfgD]Z\}}||kr|||krtd |t%||dd t%|dd f|||<qhjj$pgD] \}}||krq|||<qt&}jD]} t&} g} g} g} | j$D]}||kr|||}| |d g7} | |dg7} |dgD]}|| kr`| |q`||idgD]}| '|qq| r| j$| }t(d| j)| j$|f|| _$| j | | _ | rt(d| j)| f| j*| | _*t+| j,r| 'dt-| j,r2| 'd| j.pFj/| j,}|rX| '|d| krhd}n$d| krxd}nd| krd}nd}|r||kr| j.rtd| j)||f|| _.|0| qd|k}d|k}d|k}|r8||jjjd_1j1}|jj|d|||2_1nd_1|rˆj3}|j3jjjdjd_4j4}|r|j5}|j|r|6r||nd|d_4nd_4|rLj3}|j3jjjdjd_7j7}|r|j5}|j|r6|6r6||nd|d_7nd_78fddjD}|D]}tj|d }jstjj9|}t:j!D]L}tj"|st#||;sz build_ext.run..z.dll)> extensions run_commandr.has_c_librariesinplacehave_rungetr warnget_command_objensure_finalizedrunget_finalized_commandr<appendr3distutils.ccompilerr5Znumpy.distutils.fcompilerr6r7r8r9r:Z customizeZ customize_cmdr compiler_soZshow_customizationr,pathjoin build_temp extra_dll_dirisdirmakedirsr;reprsetaddinforD define_macrosrsourcesrlanguageZdetect_languageupdate _cxx_compiler cxx_compilerr _f77_compiler compiler_type get_version _f90_compilerZbuild_extensions build_liblistdirlowerendswithr )r"r3r5r6rgZclibslibnameZ build_infoZ all_languagesrFZ ext_languagesZc_libsZ c_lib_dirsr=ZbinfomlZ new_c_libsZ ext_languageZneed_f90_compilerZneed_f77_compilerZneed_cxx_compilerr7ctyperZ pkg_rootsZpkg_rootZshared_lib_dirfnZ runtime_libr#r!r$rQRsT           $                              z build_ext.runcCs|Srr#)r"rarHr#r#r$ swig_sources)szbuild_ext.swig_sourcesc$ Csn|j}|dkst|s$td|jt|}|s4dS||j}|jr|d}d|dd}|d}| d}| |}t j || |} nt j |j| |} ||j} |jst| | dstd|jdStd|j|jpg} |jdd} |jD]} | | fqt|j\}}}}|jjd krT|rH| d ||7}g}|jd krh|j}n"|jd kr||j}n|jp|j}|dk rt|d r|j pgng|_ t|dr|j!pgng|_!|j"}|r|dkrt#d|j|s|r|dkrt#d|j|jdkr>|dkr>|$d|j|jdkrd|dkrd|$d|jd|ji}|j%}|j&t'}g}|rtd|jj(|f|| ||j| d|}|rtd||j(|f|| ||j| d|7}g}g}|r&td|j)dd}t j |j%t j *| |}|+||j,dkrLt-d}||.||7}||j(||j%| ||j||jd7}|j,dkr&t-dD]}||krqt j ||}t j /|t j /|krАqt j 0|rt 1|z|2||Wn(t3k r t$d||fYnXq|rXtd||j(||j%| ||j||jd7}|rv|4|jsv|}|} n g}||} |j5r| 6|j5|j7pg} |8|dd}!|j9dd}"|jj:}#|jjdkr|;||!|"n|jdkr|dk r|j:}#|jdkr |dk r |j:}#|dk r@|<| |!||"|\} }!|#| | |!|"|j=| |>||j|j%|jd dS) Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesrBrbuild_pynewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extensionmsvcz/Zm1000r@r>extra_f77_compile_argsextra_f90_compile_argsz5extension %r has C++ sourcesbut no C++ compiler foundz>extension %r has Fortran sources but no Fortran compiler found)r>r@zTextension %r has Fortran libraries but no Fortran linker found, using default linkerr?zLextension %r has C++ libraries but no C++ linker found, using default linkerdependszcompiling C sources) output_dirr=r)debugextra_postargszcompiling C++ sourcesz#compiling Fortran 90 module sourcesz*.mod)r{r=r)r|r}rzzfailed to move %r to %rzcompiling Fortran sources)rwZintelwZintelemw)r;r<runtime_library_dirsr}export_symbolsr|rXZ target_lang)?rarr rDlistrCrKr+rWrRZget_package_dirr,rVget_ext_filenamerjrzr:rr r|r_extra_compile_argsr` undef_macrosrSrr7rgrbrirfhasattrrxryrdr rNrXr)rcompile module_dirsdirnamemkpathZmodule_dir_switchrZmodule_optionsabspathisfileremove move_filerZcan_ccompiler_link extra_objectsr/extra_link_argsZ get_librariesr<Zlink_shared_object_libs_with_msvc_and_fortran_process_unlinkable_fobjectsr~Zget_export_symbols)$r"rFrafullnamemodpathpackagebaseru package_dirZ ext_filenamerz extra_argsr=Zundef c_sourcesZ cxx_sourcesZ f_sourcesZfmodule_sourcesrrekwsr{r)Z c_objectsr}Z f_objectsrZmodule_build_dirZexisting_modulesftunlinkable_fobjectsobjectsr;r<Zlinkerr#r#r$build_extension-s|                              zbuild_ext.build_extensioncCsP|dj}|dj}|jjtj|dg|jd}|jj |d||j ddS)Nr2r3zgfortran_vs2003_hack.c)r{Z_gfortran_workaround)r{r|) rRr2r3r7rr,rVrWrXZcreate_static_libr|)r"rr2r3rr#r#r$_add_dummy_mingwex_syms  z build_ext._add_dummy_mingwex_symc Cst|}t|}t|}t|D]}|D]}tj||d}tj|r(||t|d} ||  W5QRXtj||d} t| d} ||  W5QRXq(q |rdd|D} |j | |j |j d} || ||fS)Nz .fobjectsrz .cobjectscSsg|]}tj|qSr#)r,rVrelpath)rEobjr#r#r$ sz:build_ext._process_unlinkable_fobjects..)r{rY) rr,rVrWrropenr/read splitlinesZwrap_unlinkable_objectsrXrY) r"rr;rr<rliblibdirZfake_librZc_libZfobjectswrappedr#r#r$rs,       z&build_ext._process_unlinkable_fobjectsc Cs|dkr dS|D]}|dr qd}|p*gD]*}tj|d|}tj|r,d}qXq,|r^qd}|D]^}tj|d|}tj|rftj|j|d}t|||j|kr||jd}qqf|rqt d||fqg} |j D]T} | dr4zt d d | g} Wnt t jfk r*Yn Xt| } | | q|| |jD]|} | dsP|| t| d | d } | rPtj|j| d} tj| st| d | |j|krP||jqPdS)NrwFz%s.libTzlib%s.az.libz+could not find library %r in directories %sz/usr/libZcygpathz-wrz.ar) startswithr,rVrWrrXr rSr rNr< subprocess check_outputOSErrorCalledProcessErrorr r/r;r)r"rZ c_librariesZc_library_dirsrnZ fileexistsrZlibfileZlibfile2Z f_lib_dirsdirrpdst_namer#r#r$rs`               z%build_ext._libs_with_msvc_and_fortrancCs.||jg}|jD]}|t|q|Sr)check_extensions_listrHr/r)r" filenamesrFr#r#r$get_source_filesRs   zbuild_ext.get_source_filesc CsP||jg}|jD]4}|js"q||j}|tj|j | |q|Sr) rrHrarCrDrSr,rVrWrjr)r"outputsrFrr#r#r$ get_outputsYs   zbuild_ext.get_outputs)N)__name__ __module__ __qualname__ descriptionr user_options help_optionsrboolean_optionsrr0rQrsrrrrrrr#r#r#r$rs0  X @  =r)%__doc__ __future__rrrr,rrdistutils.dep_utilrZdistutils.command.build_extrrdistutils.errorsrr r distutils.file_utilr Znumpy.distutilsr Znumpy.distutils.exec_commandr Znumpy.distutils.system_inforrZnumpy.distutils.misc_utilrrrrrrrrZ'numpy.distutils.command.config_compilerrr#r#r#r$s      (