3
ßL]M4  ã               @   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               @   sl   e Zd ZdZejdddg Zej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 jobsc             C   s    t j| ƒ d | _d| _d | _d S )Nr   )Úold_build_clibÚinitialize_optionsÚ	fcompilerr   Úparallel)Úself© r$   úE/tmp/pip-install-q_7g0qgj/Numpy/numpy/distutils/command/build_clib.pyr    (   s    
zbuild_clib.initialize_optionsc             C   sN   | j r4yt| j ƒ| _ W n tk
r2   tdƒ‚Y nX tj| ƒ | jddƒ d S )Nz)--parallel/-j argument must be an integerÚbuildr"   )r"   r"   )r"   ÚintÚ
ValueErrorr   Úfinalize_optionsÚset_undefined_options)r#   r$   r$   r%   r)   .   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_sources7   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   r-   )r#   r.   r/   r$   r$   r%   Úhave_cxx_sources=   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 }d | _ | jj| ƒ || _ | jjƒ  | jƒ �r,ddlm} || j| j| j| jd|k| jd	�| _| jd k	�r2| 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 |	|
ƒ �qPW d S )
NZ	build_srcÚlanguager   )Únew_compiler)ÚcompilerÚdry_runÚforce)Zneed_cxx)Únew_fcompilerÚf90)r4   Úverboser5   r6   Ú
requiref90Ú
c_compiler)!r,   Úrun_commandr-   ÚappendÚdistutils.ccompilerr3   r4   r5   r6   Ú	customizeÚdistributionr1   Zcustomize_cmdZshow_customizationr0   Únumpy.distutils.fcompilerr7   r!   r9   Ú_f_compilerÚbuild_librariesr   Zinstalled_librariesÚlibrary_filenameÚnameÚosÚpathÚjoinr   Ú
target_dirÚmkpathÚshutilÚcopy)r#   Ú	languagesr.   r/   Úlr3   r,   r7   ZlibnameÚsourceÚtargetr$   r$   r%   ÚrunC   sV    



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,   r.   r/   r$   r$   r%   rC   …   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 filenamesr2   Úcr8   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   )r7   )r4   r9   r5   r6   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)rY   r_   r`   Ú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)rF   rG   Úabspath)Ú.0Úobjr$   r$   r%   ú	<genexpr>)  s    z-build_clib.build_a_library.<locals>.<genexpr>z	.cobjectsc             s   s   | ]}t jj|ƒV  qd S )N)rF   rG   rf   )rg   rh   r$   r$   r%   ri   .  s    Úwb)rY   rb   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)4r4   rB   r-   r   r   Úlistr   r=   rD   r   r6   r   r
   rb   ÚinforA   r7   Úcompiler_typer9   r5   r@   Úget_option_dictrL   Úupdater?   r   r]   r^   rR   r   rF   rG   ÚdirnamerJ   ÚcompileÚ
build_tempÚcxx_compilerZmodule_dir_switchr   Zmodule_optionsrH   rf   ÚisfileÚremoveÚ	move_filer	   ÚwarnZcan_ccompiler_linkÚopenÚwriteZstatic_lib_extensionZcreate_static_lib)$r#   r/   r.   r,   r4   r!   r+   Z	c_sourcesZcxx_sourcesZ	f_sourcesZfmodule_sourcesr:   rX   Zlib_filerZ   r\   r7   ÚdistZbase_config_fcr_   r`   rc   ra   Zmodule_build_dirZobjectsrs   Zcxx_objectsZ	f_objectsZexisting_modulesÚfÚtZlistfnZ	lib_fnameZclib_librariesÚlnameZbinfor$   r$   r%   rV   ‰   s$   
 

























$

$



zbuild_clib.build_a_library)r   Nr   )r   r   r   )r   r   r   )Ú__name__Ú
__module__Ú__qualname__Údescriptionr   Úuser_optionsÚboolean_optionsr    r)   r0   r1   rQ   rU   rC   rV   r$   r$   r$   r%   r      s      	;r   )r   r   ) Ú__doc__Ú
__future__r   r   r   rF   r   rK   Zdistutils.command.build_clibr   r   Ú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   $*