3
eåU^è5  ã               @   sö   d Z ddlmZmZm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mZ e
jZxJeeeƒƒD ]:Zee d dkr¤ee d d fee dd…  ee< q¤W G dd„ de
ƒZ	dS )zC Modified version of build_clib that handles fortran source files.
é    )ÚdivisionÚabsolute_importÚprint_functionN)Úglob)Ú
build_clib)ÚDistutilsSetupErrorÚDistutilsErrorÚDistutilsFileError)Úlog)Únewer_group)Úfilter_sourcesÚhas_f_sourcesÚhas_cxx_sourcesÚall_stringsÚget_lib_source_filesÚis_sequenceÚget_numpy_include_dirsú
build-clibú
build-tempú=é   c               @   sp   e Zd ZdZejdddd g Zejddg 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ú
fcompiler=Nú!specify the Fortran compiler typeÚinplaceÚiúBuild in-placeú	parallel=Újúnumber of parallel jobsú
warn-errorú'turn all warnings into errors (-Werror)c             C   s&   t j| ƒ d | _d| _d | _d | _d S )Nr   )Úold_build_clibÚinitialize_optionsÚ	fcompilerr   ÚparallelÚ
warn_error)Úself© r'   úC/tmp/pip-build-fou5mlat/numpy/numpy/distutils/command/build_clib.pyr"   *   s
    
zbuild_clib.initialize_optionsc             C   sP   | j r4yt| j ƒ| _ W n tk
r2   tdƒ‚Y nX tj| ƒ | jdddƒ d S )Nz)--parallel/-j argument must be an integerÚbuildr$   r%   )r$   r$   )r%   r%   )r$   ÚintÚ
ValueErrorr!   Úfinalize_optionsÚset_undefined_options)r&   r'   r'   r(   r,   1   s    
zbuild_clib.finalize_optionsc             C   s,   x&| j D ]\}}t|jdg ƒƒrdS qW dS )NÚsourcesTF)Ú	librariesr   Úget)r&   Úlib_nameÚ
build_infor'   r'   r(   Úhave_f_sources=   s    zbuild_clib.have_f_sourcesc             C   s,   x&| j D ]\}}t|jdg ƒƒrdS qW dS )Nr.   TF)r/   r   r0   )r&   r1   r2   r'   r'   r(   Úhave_cxx_sourcesC   s    zbuild_clib.have_cxx_sourcesc             C   sÆ  | j s
d S g }| jdƒ x4| j D ]*\}}|jdd ƒ}|r ||kr |j|ƒ q W ddlm} || j| j| jd�| _| jj	| j
| jƒ d� | jr¨| jjjdƒ | jjjdƒ | j }d | _ | jj| ƒ || _ | jjƒ  | jƒ �rNddlm} || j| j| j| jd	|k| jd
�| _| jd k	�rT| jj	| j
ƒ | j }d | _ | jj| ƒ || _ | jjƒ  nd | _| j| j ƒ | j�rÂxX| j
jD ]L}| jj|jƒ}tjj| j|ƒ}	tjj|j|ƒ}
| j |jƒ t!j"|	|
ƒ �qrW d S )NZ	build_srcÚlanguager   )Únew_compiler)ÚcompilerÚdry_runÚforce)Zneed_cxxz-Werror)Únew_fcompilerÚf90)r7   Úverboser8   r9   Ú
requiref90Ú
c_compiler)#r/   Úrun_commandr0   ÚappendÚdistutils.ccompilerr6   r7   r8   r9   Ú	customizeÚdistributionr4   r%   Úcompiler_soZcustomize_cmdZshow_customizationr3   Únumpy.distutils.fcompilerr:   r#   r<   Ú_f_compilerÚbuild_librariesr   Zinstalled_librariesÚlibrary_filenameÚnameÚosÚpathÚjoinr   Ú
target_dirÚmkpathÚshutilÚcopy)r&   Ú	languagesr1   r2   Úlr6   r/   r:   ÚlibnameÚsourceÚtargetr'   r'   r(   ÚrunI   s\    



zbuild_clib.runc             C   s2   | j | jƒ g }x| jD ]}|jt|ƒƒ qW |S )N)Zcheck_library_listr/   Úextendr   )r&   Ú	filenamesÚlibr'   r'   r(   Úget_source_filesˆ   s
    zbuild_clib.get_source_filesc             C   s$   x|D ]\}}| j |||ƒ qW d S )N)Úbuild_a_library)r&   r/   r1   r2   r'   r'   r(   rG   �   s    zbuild_clib.build_librariesc       $      C   sH  | j }| j}|jdƒ}|d ks(t|ƒ r4td/| ƒ‚t|ƒ}t|ƒ\}}}	}
|
  pb|jddƒdk}g }|rv|jdƒ |r„|jdƒ |r”|jdƒ n|	r¢|jd	ƒ ||d
< |j|| j	d�}||jdg ƒ }| j
pÚt||dƒsìtjd|ƒ d S tjd|ƒ |jdi ƒ}|d k	�r€|�r€tjd|f ƒ ddlm} ||j| j| j| j
|| j d�}|d k	�r€| j}|jdƒjƒ }|j|ƒ |j|ƒ |	�sŒ|
�r¢|d k�r¢td| ƒ‚|d k	�rÐ|jdƒ�pºg |_|jdƒ�pÌg |_|jdƒ}|jdƒ}|d k�ròg }|jdƒ�p g }|jtƒ ƒ |jdƒ�pg }tjj |ƒ}|�r:| j!|ƒ |jdk�rR||7 }g }g }|�r€tjdƒ |j"|| j#||| j|d�}|�r¼tjdƒ |j$ƒ }|j"|| j#||| j|d�}|j|ƒ |	�sÈ|
�rg }g }|�rú|j%d k�rêt&d ƒ}||j'||ƒ7 }|
�r(tjd!ƒ ||j"|
| j#||| j|d�7 }|�rÜ| jj%d k�rÜxžt&d ƒD ]’}||k�rX�qFtjj(||ƒ}tjj)|ƒtjj)|ƒk�r„�qFtjj*|ƒ�rœtj+|ƒ y| j,||ƒ W n( t-k
�rÔ   tj.d"||f ƒ Y nX �qFW |	�rtjd#ƒ ||j"|	| j#||| j|d�7 }ng }|�rÚ|j/|ƒ �rÚtjj(| j	|d$ ƒ}t0|d%ƒ� }|j1d&j(d'd(„ |D ƒƒƒ W d Q R X tjj(| j	|d) ƒ}t0|d%ƒ� }|j1d&j(d*d(„ |D ƒƒƒ W d Q R X tjj(| j	||j2 ƒ} t0| d+ƒ�}W d Q R X n |j|ƒ |j3||| j	| jd,� |jd-g ƒ}!x.|D ]&\}"}#|"|!k�r|!j|#jd-g ƒƒ �qW |!�rD|!|d-< d S )0Nr.   z&in 'libraries' option (library '%s'), z&'sources' must be present and must be za list of source filenamesr5   Úcr;   zc++Zf77Úsource_languages)Ú
output_dirÚdependsÚnewerz"skipping '%s' library (up-to-date)zbuilding '%s' libraryÚ	config_fczEusing additional config_fc from setup script for fortran compiler: %sr   )r:   )r7   r<   r8   r9   r=   r>   z<library %s has Fortran sources but no Fortran compiler foundÚextra_f77_compile_argsÚextra_f90_compile_argsÚmacrosÚinclude_dirsZextra_compiler_argsÚmodule_dirsZmsvczcompiling C sources)r^   rd   re   ÚdebugÚextra_postargszcompiling C++ sourcesz*.modz#compiling Fortran 90 module sourceszfailed to move %r to %rzcompiling Fortran sourcesz	.fobjectsÚwÚ
c             s   s   | ]}t jj|ƒV  qd S )N)rJ   rK   Úabspath)Ú.0Úobjr'   r'   r(   ú	<genexpr>3  s    z-build_clib.build_a_library.<locals>.<genexpr>z	.cobjectsc             s   s   | ]}t jj|ƒV  qd S )N)rJ   rK   rk   )rl   rm   r'   r'   r(   rn   8  s    Úwb)r^   rg   r/   zLin 'libraries' option (library '%s'), 'sources' must be present and must be zfin 'libraries' option (library '%s'), 'sources' must be present and must be a list of source filenames)4r7   rF   r0   r   r   Úlistr   r@   rH   r   r9   r   r
   rg   ÚinforE   r:   Úcompiler_typer<   r8   rC   Úget_option_dictrP   ÚupdaterB   r   rb   rc   rW   r   rJ   rK   ÚdirnamerN   ÚcompileÚ
build_tempÚcxx_compilerZmodule_dir_switchr   Zmodule_optionsrL   rk   ÚisfileÚremoveÚ	move_filer	   ÚwarnZcan_ccompiler_linkÚopenÚwriteZstatic_lib_extensionZcreate_static_lib)$r&   r2   r1   r/   r7   r#   r.   Z	c_sourcesZcxx_sourcesZ	f_sourcesZfmodule_sourcesr=   r]   Zlib_filer_   ra   r:   ÚdistZbase_config_fcrd   re   rh   rf   Zmodule_build_dirZobjectsrx   Zcxx_objectsZ	f_objectsZexisting_modulesÚfÚtZlistfnZ	lib_fnameZclib_librariesÚlnameZbinfor'   r'   r(   r[   “   s$   
 

























$

$



zbuild_clib.build_a_library)r   Nr   )r   r   r   )r   r   r   )r   Nr    )Ú__name__Ú
__module__Ú__qualname__Údescriptionr!   Úuser_optionsÚboolean_optionsr"   r,   r3   r4   rV   rZ   rG   r[   r'   r'   r'   r(   r      s$      ?r   )r   r   ) Ú__doc__Ú
__future__r   r   r   rJ   r   rO   Zdistutils.command.build_clibr   r!   Zdistutils.errorsr   r   r	   Znumpy.distutilsr
   Údistutils.dep_utilr   Znumpy.distutils.misc_utilr   r   r   r   r   r   r   r‡   Z_lÚrangeÚlenZ_ir'   r'   r'   r(   Ú<module>   s   $*