ó
Ê½÷Xc           @   s¤   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l m Z d d d d d g Z d „  Z d	 „  Z d
 „  Z	 d „  Z
 d „  Z d „  Z d „  Z d d „ Z d S(   iÿÿÿÿN(   t   newert   needs_g77_abi_wrappert   split_fortran_filest   get_g77_abi_wrapperst   needs_sgemv_fixt   get_sgemv_fixc         C   s\   t  j d k r t St j d ƒ } |  j d d ƒ } x! | D] } | j | ƒ r; t Sq; Wt S(   Nt   darwint   vecLibt   extra_link_argst    (   t   syst   platformt   Falset   ret   compilet   gett   searcht   True(   t   infot   r_accelerateR   t   arg(    (    s:   /tmp/pip-build-7oUkmx/scipy/scipy/_build_utils/_fortran.pyt   uses_veclib   s    c         C   s\   t  j d k r t St j d ƒ } |  j d d ƒ } x! | D] } | j | ƒ r; t Sq; Wt S(   NR   t
   AccelerateR   R	   (   R
   R   R   R   R   R   R   R   (   R   R   R   R   (    (    s:   /tmp/pip-build-7oUkmx/scipy/scipy/_build_utils/_fortran.pyt   uses_accelerate   s    c         C   sI   t  j d ƒ } |  j d d ƒ } x! | D] } | j | ƒ r( t Sq( Wt S(   Nt   mklt	   librariesR	   (   R   R   R   R   R   R   (   R   t   r_mklR   t   library(    (    s:   /tmp/pip-build-7oUkmx/scipy/scipy/_build_utils/_fortran.pyt   uses_mkl#   s    c         C   s4   t  |  ƒ s t |  ƒ r t St |  ƒ r, t St Sd S(   s-   Returns True if g77 ABI wrapper must be used.N(   R   R   R   R   R   (   R   (    (    s:   /tmp/pip-build-7oUkmx/scipy/scipy/_build_utils/_fortran.pyR   -   s
    c         C   s#  g  } t  j j t  j j t ƒ ƒ } t |  ƒ rë | t  j j | d d ƒ t  j j | d d ƒ g 7} t |  ƒ r§ | t  j j | d d ƒ t  j j | d d ƒ g 7} qt |  ƒ rÕ | t  j j | d d ƒ g 7} qt	 d |  f ƒ ‚ n4 | t  j j | d d ƒ t  j j | d d ƒ g 7} | S(	   sY   
    Returns file names of source files containing Fortran ABI wrapper
    routines.
    t   srcs   wrap_g77_abi_f.fs   wrap_g77_abi_c.cs   wrap_accelerate_c.cs   wrap_accelerate_f.fs   wrap_dummy_accelerate.fs/   Do not know how to handle LAPACK %s on mac os xs   wrap_dummy_g77_abi.f(
   t   ost   patht   abspatht   dirnamet   __file__R   t   joinR   R   t   NotImplementedError(   R   t   wrapper_sourcesR   (    (    s:   /tmp/pip-build-7oUkmx/scipy/scipy/_build_utils/_fortran.pyR   7   s$    c         C   s   t  |  ƒ r t St Sd S(   s$   Returns True if SGEMV must be fixed.N(   R   R   R   (   R   (    (    s:   /tmp/pip-build-7oUkmx/scipy/scipy/_build_utils/_fortran.pyR   W   s    c         C   sK   t  j j t  j j t ƒ ƒ } t |  ƒ rC t  j j | d d ƒ g Sg  Sd S(   s-    Returns source file needed to correct SGEMV R   s   apple_sgemv_fix.cN(   R   R   R    R!   R"   R   R#   (   R   R   (    (    s:   /tmp/pip-build-7oUkmx/scipy/scipy/_build_utils/_fortran.pyR   _   s    c            sø   ˆ  d k	 r. g  ˆ  D] } | j ƒ  ^ q ‰  n  ‡  f d †  } t j d ƒ } g  t j t j j |  d ƒ ƒ D]' } | j t j j	 | ƒ ƒ sk | ^ qk } g  } xS | D]K } | | ƒ }	 |	 d k	 r¥ x* |	 D] }
 | j
 t j j	 |
 ƒ ƒ qÊ Wq¥ q¥ W| S(   sÙ  Split each file in `source_dir` into separate files per subroutine.

    Parameters
    ----------
    source_dir : str
        Full path to directory in which sources to be split are located.
    subroutines : list of str, optional
        Subroutines to split. (Default: all)

    Returns
    -------
    fnames : list of str
        List of file names (not including any path) that were created
        in `source_dir`.

    Notes
    -----
    This function is useful for code that can't be compiled with g77 because of
    type casting errors which do work with gfortran.

    Created files are named: ``original_name + '_subr_i' + '.f'``, with ``i``
    starting at zero and ending at ``num_subroutines_in_file - 1``.

    c            sÃ  t  |  d ƒ ®} | j ƒ  } g  } t } x¬ t | ƒ D]ž \ } } t j d | t j ƒ } | r7 | d d k r7 ˆ  d  k	 rª | j d ƒ j	 d ƒ j
 ƒ  } | ˆ  k }	 n t }	 |	 s¼ | rÕ |	 } | j | ƒ qÕ q7 q7 Wt | ƒ d k rò |  g Sg  }
 t | ƒ } x² t | ƒ D]¤ } |  d  d t | ƒ d	 } |
 j | ƒ t |  | ƒ sUqn  t  | d
 ƒ O } | d | k r| j | | | ƒ n  | j | | | | | d !ƒ Wd  QXqWWd  QX|
 S(   Nt   rbs"   ^\s+subroutine\s+([a-z0-9_]+)\s*\(i    s   Cc!*i   t   asciiiþÿÿÿt   _subr_s   .ft   wb(   t   opent	   readlinesR   t	   enumerateR   t   matcht   It   Nonet   groupt   decodet   lowert   appendt   lent   ranget   strR    t
   writelines(   t   fnamet   ft   linest   subst   need_split_nextt   ixt   linet   mt	   subr_namet   subr_wantedt
   new_fnamest	   num_filest   nfilet	   new_fnamet   fn(   t   subroutines(    s:   /tmp/pip-build-7oUkmx/scipy/scipy/_build_utils/_fortran.pyt
   split_file…   s8    0s   _subr_[0-9]s   *.fN(   R/   R2   R   R   t   globR   R   R#   R   t   basenameR3   (   t
   source_dirRG   t   xRH   t   exclude_patternR9   t   source_fnamest   fnamest   source_fnamet   created_filest   cfile(    (   RG   s:   /tmp/pip-build-7oUkmx/scipy/scipy/_build_utils/_fortran.pyR   h   s    "'%'$(   R   R
   R   RI   t   distutils.dep_utilR    t   __all__R   R   R   R   R   R   R   R/   R   (    (    (    s:   /tmp/pip-build-7oUkmx/scipy/scipy/_build_utils/_fortran.pyt   <module>   s   			
	
	 			