U C^5@sdZddlmZmZmZddlZddlmZddlZddlm Z ddl m Z m Z mZddlmZddlmZdd lmZmZmZmZmZmZmZe jZeeeD]:Zeedd kreedd feed dee<qGd dde Z dS)zC Modified version of build_clib that handles fortran source files. )divisionabsolute_importprint_functionN)glob) build_clib)DistutilsSetupErrorDistutilsErrorDistutilsFileError)log) newer_group)filter_sources has_f_sourceshas_cxx_sources all_stringsget_lib_source_files is_sequenceget_numpy_include_dirs)z build-clibz build-temp=c@speZdZdZejddddgZejddgZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZdS)rz1build C/C++/F libraries used by Python extensions)z fcompiler=Nz!specify the Fortran compiler type)inplaceizBuild in-place)z parallel=jznumber of parallel jobs) warn-errorNz'turn all warnings into errors (-Werror)rrcCs&t|d|_d|_d|_d|_dS)Nr)old_build_clibinitialize_options fcompilerrparallel warn_errorselfr E/tmp/pip-install-6_kvzl1k/numpy/numpy/distutils/command/build_clib.pyr*s  zbuild_clib.initialize_optionscCsP|jr4zt|j|_Wntk r2tdYnXt||ddddS)Nz)--parallel/-j argument must be an integerbuild)rr)rr)rint ValueErrorrfinalize_optionsset_undefined_optionsrr r r!r%1s zbuild_clib.finalize_optionscCs*|jD]\}}t|dgrdSqdSNsourcesTF) librariesr getrlib_name build_infor r r!have_f_sources=szbuild_clib.have_f_sourcescCs*|jD]\}}t|dgrdSqdSr')r)rr*r+r r r!have_cxx_sourcesCszbuild_clib.have_cxx_sourcesc Cs|js dSg}|d|jD]*\}}|dd}|r||kr||qddlm}||j|j|jd|_|jj |j | d|j r|jjd|jj d|j}d|_|j|||_|j|rJddlm}||j|j|j|jd |k|jd |_|jdk rP|j |j |j}d|_|j|||_|jnd|_||j|jr|j jD]L}|j|j}tj|j|} tj|j|} | |jt!"| | qldS) NZ build_srclanguager) new_compiler)compilerdry_runforce)Zneed_cxxz-Werror new_fcompilerf90r2verboser3r4 requiref90Z c_compiler)#r) run_commandr*appenddistutils.ccompilerr1r2r3r4 customize distributionr/r compiler_soZ customize_cmdZshow_customizationr.numpy.distutils.fcompilerr6rr9 _f_compilerbuild_librariesrZinstalled_librarieslibrary_filenamenameospathjoinr target_dirmkpathshutilcopy) r languagesr,r-lr1r)r6Zlibnamesourcetargetr r r!runIsb                zbuild_clib.runcCs.||jg}|jD]}|t|q|SN)Zcheck_library_listr)extendr)r filenameslibr r r!get_source_filess   zbuild_clib.get_source_filescCs |D]\}}||||qdSrR)build_a_library)rr)r,r-r r r!rCs zbuild_clib.build_librariesc$ Cs<|j}|j}|d}|dks&t|s2td|t|}t|\}}} } | p`|dddk} g} |rt| d|r| d| r| dn| r| d| |d<|j||j d } ||d g}|j st || d st d |dSt d ||di}|dk r~|r~t d|fddlm}||j|j|j|j | |jd}|dk r~|j}|d}||||| s| r|dkrtd||dk r|dpg|_|dpg|_|d}|d}|dkrg}|dpg}|t|dpg}tj | }| r8|!||jdkrP||7}g}g}|r~t d|j"||j#|||j |d}|rt d|$}|j"||j#|||j |d}||| s| rg}g}| r|j%dkrt&d}||'||7}| r&t d||j"| |j#|||j |d7}| r|jj%dkrt&dD]}||krTqBtj(||}tj)|tj)|krqBtj*|rt+|z|,||Wn(t-k rt .d ||fYnXqB| r t d!||j"| |j#|||j |d7}ng}|r|/|stj(|j |d"}t0|d# }|1d$(d%d&|DW5QRXtj(|j |d'}t0|d# }|1d$(d(d&|DW5QRXtj(|j ||j2} t0| d)}W5QRXn |||j3|||j |j d*|d+g}!|D]&\}"}#|"|!kr|!|#d+gq|!r8|!|d+<dS),Nr(zfin 'libraries' option (library '%s'), 'sources' must be present and must be a list of source filenamesr0cr7zc++Zf77source_languages) output_dirdependsnewerz"skipping '%s' library (up-to-date)zbuilding '%s' library config_fczEusing additional config_fc from setup script for fortran compiler: %srr5r8z3sz-build_clib.build_a_library..z .cobjectscss|]}tj|VqdSrRrgrir r r!rl8swb)rZrcr))4r2rBr*rrlistr r<rDrr4r r rcinforAr6 compiler_typer9r3r?get_option_dictrLupdater>rr^r_rSrrFrGdirnamerJcompile build_temp cxx_compilerZmodule_dir_switchrZmodule_optionsrHrhisfileremove move_filer warnZcan_ccompiler_linkopenwriteZstatic_lib_extensionZcreate_static_lib)$rr-r,r)r2rr(Z c_sourcesZ cxx_sourcesZ f_sourcesZfmodule_sourcesr:rYZlib_filer[r]r6distZbase_config_fcr`rardrbZmodule_build_dirZobjectsrvZ cxx_objectsZ f_objectsZexisting_modulesftZlistfnZ lib_fnameZclib_librarieslnameZbinfor r r!rWsR                                  $  $       zbuild_clib.build_a_libraryN)__name__ __module__ __qualname__ descriptionr user_optionsboolean_optionsrr%r.r/rQrVrCrWr r r r!rs   ?r) __doc__ __future__rrrrFrrKZdistutils.command.build_clibrrdistutils.errorsrrr Znumpy.distutilsr distutils.dep_utilr Znumpy.distutils.misc_utilr r rrrrrrZ_lrangelenZ_ir r r r!s    $(