U
    O8ÚcÓ  ã                   @   sš   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ dgZG dd„ deƒZedkr–d d	lmZ e d
¡ eedd ¡ ƒ dS )é    N)Ú	FCompiler)Úfind_executable)Úmake_temp_file)ÚlogÚIBMFCompilerc                   @   sh   e Zd ZdZdZdZddgdgddgdgd	gd
dgdgdœZdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )r   ÚibmzIBM XL Fortran Compilerzo(xlf\(1\)\s*|)IBM XL Fortran ((Advanced Edition |)Version |Enterprise Edition V|for AIX, V)(?P<version>[^\s*]*)z<F77>z	-qversionÚxlfZxlf90z-qfixedZxlf95Úarz-crÚranlib)Zversion_cmdZcompiler_f77Zcompiler_fixZcompiler_f90Ú	linker_soÚarchiverr
   c           
   	      sþ   t j| f|ž|Ž}|d kr˜tj d¡r˜tdƒ}tdƒ}tj |¡r˜tj |¡r˜zt	 
|ddg¡}W n tt	jfk
r|   Y nX t d|¡}|r˜| d¡}d‰ |d krútj ˆ ¡rútt ˆ ¡ƒ}| ¡  ‡ fd	d
„|D ƒ}|rúddlm}	 |	|d ƒ | _}|S )NÚaixÚlslppr   z-LcZxlfcmpz xlfcmp:(?P<version>\d+([.]\d+)+)Úversionz/etc/opt/ibmcmp/xlfc              	      s(   g | ] }t j t j ˆ |d ¡¡r|‘qS )zxlf.cfg)ÚosÚpathÚisfileÚjoin)Ú.0Úd©Zxlf_dir© úA/tmp/pip-unpacked-wheel-fd_gsd75/numpy/distutils/fcompiler/ibm.pyÚ
<listcomp>5   s      z,IBMFCompiler.get_version.<locals>.<listcomp>r   )ÚLooseVersion)r   Úget_versionÚsysÚplatformÚ
startswithr   r   r   ÚexistsÚ
subprocessÚcheck_outputÚOSErrorÚCalledProcessErrorÚreÚsearchÚgroupÚisdirÚsortedÚlistdirÚreverseZdistutils.versionr   r   )
ÚselfÚargsÚkwdsr   r   r   ÚoÚmÚlr   r   r   r   r      s*     
zIBMFCompiler.get_versionc                 C   s   dgS )Nz	-qextnamer   ©r+   r   r   r   Ú	get_flags;   s    zIBMFCompiler.get_flagsc                 C   s   dgS )Nz-gr   r1   r   r   r   Úget_flags_debug>   s    zIBMFCompiler.get_flags_debugc           
   	   C   sä   g }t jdkr| d¡ n
| d¡ | jddgd}|d k	ràt j d¡rNd}nd	| }td
d\}}t d| ¡ t|dƒH}t	 
d¡j}|D ]0}||ƒ}	|	r´| d|	 d¡ ¡ qŽ| |¡ qŽW 5 Q R X | ¡  | d| ¡ |S )NÚdarwinz/-Wl,-bundle,-flat_namespace,-undefined,suppressz-bsharedr   é(   )Z	ok_statusr   z/etc/xlf.cfgz/etc/opt/ibmcmp/xlf/%s/xlf.cfgz_xlf.cfg)Úsuffixz	Creating Úrz \s*crt\s*=\s*(?P<path>.*)/crt1.ozcrt = %s/bundle1.o
r   z-F)r   r   Úappendr   r   r   r   ÚinfoÚopenr$   ÚcompileÚmatchÚwriter&   Úclose)
r+   Úoptr   Zxlf_cfgÚfoZnew_cfgÚfiZ
crt1_matchÚliner/   r   r   r   Úget_flags_linker_soA   s*    

z IBMFCompiler.get_flags_linker_soc                 C   s   dgS )Nz-O3r   r1   r   r   r   Úget_flags_opt[   s    zIBMFCompiler.get_flags_optN)Ú__name__Ú
__module__Ú__qualname__Úcompiler_typeÚdescriptionZversion_patternZexecutablesr   r2   r3   rC   rD   r   r   r   r   r      s    ù
Ú__main__)Úcustomized_fcompileré   r   )Úcompiler)r   r$   r   r    Znumpy.distutils.fcompilerr   Znumpy.distutils.exec_commandr   Znumpy.distutils.misc_utilr   Ú	distutilsr   Z	compilersr   rE   Znumpy.distutilsrK   Úset_verbosityÚprintr   r   r   r   r   Ú<module>   s   Q
