ó
ÐEe]c           @` s0  d  Z  d d l m Z m Z m 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 m Z m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z m Z d d l m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" d d l# m$ Z$ d e f d „  ƒ  YZ d S(   sC    Modified version of build_ext that handles fortran source files.

i    (   t   divisiont   absolute_importt   print_functionN(   t   glob(   t   newer_group(   t	   build_ext(   t   DistutilsFileErrort   DistutilsSetupErrort   DistutilsError(   t	   copy_file(   t   log(   t   filepath_from_subprocess_output(   t   combine_pathst   system_info(   t   filter_sourcest   has_f_sourcest   has_cxx_sourcest   get_ext_source_filest   get_numpy_include_dirst   is_sequencet   get_build_architecturet   msvc_version(   t   show_fortran_compilersR   c           B` s—   e  Z d  Z e j d d g Z e j d d d e f g Z d „  Z d	 „  Z	 d
 „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s:   build C/C++/F extensions (compile/link to build directory)s
   fcompiler=s!   specify the Fortran compiler types	   parallel=t   js   number of parallel jobss   help-fcompilers    list available Fortran compilersc         C` s#   t  j |  ƒ d  |  _ d  |  _ d  S(   N(   t   old_build_extt   initialize_optionst   Nonet	   fcompilert   parallel(   t   self(    (    s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pyR   +   s    	c         C` sß   |  j  rB y t |  j  ƒ |  _  WqB t k
 r> t d ƒ ‚ qB Xn  t |  j t ƒ ro |  j j t j ƒ |  _ n  |  j p{ g  } |  j	 j d  k rŸ g  |  j	 _ n  |  j	 j |  _ |  j j | ƒ t j |  ƒ |  j d d ƒ d  S(   Ns)   --parallel/-j argument must be an integert   buildR   (   R   R   (   R   t   intt
   ValueErrort
   isinstancet   include_dirst   strt   splitt   ost   pathsept   distributionR   t   extendR   t   finalize_optionst   set_undefined_options(   R   t	   incl_dirs(    (    s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pyR)   0   s    	
c         ` s3  ˆ  j  s d  Sˆ  j d ƒ ˆ  j j ƒ  rÝ ˆ  j r« ˆ  j j j d ƒ ri t j d ƒ ˆ  j j	 d ƒ } qÇ ˆ  j j	 d ƒ } d | _ | j
 ƒ  | j ƒ  d ˆ  j j d <n ˆ  j d ƒ ˆ  j d ƒ } ˆ  j j | j ƒ n d  } d d l m } d d l m } ˆ  j } | d | d	 ˆ  j d
 ˆ  j d ˆ  j ƒ ˆ  _ ˆ  j j ˆ  j ƒ ˆ  j j ˆ  ƒ ˆ  j j ƒ  t j j ˆ  j d ƒ ˆ  _  t j j! ˆ  j  ƒ s¬t j" ˆ  j  ƒ n  i  } | d  k	 r<x{ | j# pÍg  D]g \ } } | | k r+| | | k r+t j d | t$ | | ƒ d  t$ | ƒ d  f ƒ n  | | | <qÎWn  x< ˆ  j j# pNg  D]( \ } } | | k rmqOn  | | | <qOWt% ƒ  } x~ˆ  j  D]s}	 t% ƒ  }
 g  } g  } g  } xÅ |	 j# D]º } | | k r=| | } | | j d g  ƒ 7} | | j d g  ƒ 7} x9 | j d g  ƒ D]" } | | k r| j | ƒ qqWn  x3 | j | i  ƒ j d g  ƒ D] } |
 j& | ƒ q\Wq¹W| rÆ|	 j# | } t j' d |	 j( |	 j# | f ƒ | |	 _# |	 j | |	 _ n  | rùt j' d |	 j( | f ƒ |	 j) | |	 _) n  t* |	 j+ ƒ r|
 j& d ƒ n  t, |	 j+ ƒ r7|
 j& d ƒ n  |	 j- pRˆ  j j. |	 j+ ƒ } | rk|
 j& | ƒ n  d |
 k r€d } n0 d |
 k r•d } n d |
 k rªd } n d } | rë| | k rë|	 j- rët j d |	 j( | | f ƒ n  | |	 _- | j/ |
 ƒ qŽWd | k } d | k } d | k } | r¤| d | d	 ˆ  j d
 ˆ  j d ˆ  j ƒ ˆ  _0 ˆ  j0 } | j ˆ  j d | ƒ| j ˆ  ƒ | j ƒ  | j1 ƒ  ˆ  _0 n	 d  ˆ  _0 | roˆ  j2 } | d ˆ  j2 d	 ˆ  j d
 ˆ  j d ˆ  j d t3 d ˆ  j ƒ ˆ  _4 ˆ  j4 } | r&| j5 } | j ˆ  j ƒ n  | rR| j6 ƒ  rR| j ˆ  ƒ | j ƒ  qxˆ  j d | ƒ d  ˆ  _4 n	 d  ˆ  _4 | r:ˆ  j2 } | d ˆ  j2 d	 ˆ  j d
 ˆ  j d ˆ  j d t7 d ˆ  j ƒ ˆ  _8 ˆ  j8 } | rñ| j5 } | j ˆ  j ƒ n  | r| j6 ƒ  r| j ˆ  ƒ | j ƒ  qCˆ  j d | ƒ d  ˆ  _8 n	 d  ˆ  _8 ˆ  j9 ƒ  ‡  f d †  ˆ  j  Dƒ } xÆ | D]¾ } t j j | d ƒ } ˆ  j s¬t j j ˆ  j: | ƒ } n  x| t j; ˆ  j  ƒ D]h } t j j! | ƒ sçt j" | ƒ n  | j< ƒ  j= d  ƒ sq¿n  t j j ˆ  j  | ƒ } t> | | ƒ q¿WqmWd  S(!   Nt	   build_srct
   build_clibsM   build_clib already run, it is too late to ensure in-place build of build_clibi   i    (   t   new_compiler(   t   new_fcompilert   compilert   verboset   dry_runt   forces   .libssK   library %r defined more than once, overwriting build_info
%s... 
with
%s...i,  t	   librariest   library_dirst   macrost   source_languagess-   updating extension %r libraries from %r to %rs-   extending extension %r defined_macros with %rt   f77s   c++t   f90t   cs.   resetting extension %r language from %r to %r.t   need_cxxt
   requiref90t
   c_compilers!   f77_compiler=%s is not available.s!   f90_compiler=%s is not available.c         ` s/   h  |  ]% } ˆ  j  | j ƒ j d  ƒ d ’ q S(   t   .i    (   t   get_ext_fullnamet   nameR$   (   t   .0t   ext(   R   (    s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pys	   <setcomp>  s   	s   .dll(?   t
   extensionst   run_commandR'   t   has_c_librariest   inplacet   have_runt   getR
   t   warnt   get_command_objt   ensure_finalizedt   runt   get_finalized_commandR5   t   appendR-   R   t   distutils.ccompilerR.   t   numpy.distutils.fcompilerR/   R0   R1   R2   R3   t	   customizet   customize_cmdt   show_customizationR%   t   patht   joint
   build_tempt   extra_dll_dirt   isdirt   makedirsR4   t   reprt   sett   addt   infoR@   t   define_macrosR   t   sourcesR   t   languaget   detect_languaget   updatet   _cxx_compilert   cxx_compilerR   t   Falset   _f77_compilert   compiler_typet   get_versiont   Truet   _f90_compilert   build_extensionst	   build_libt   listdirt   lowert   endswithR	   (   R   R-   R.   R/   Rg   t   clibst   libnamet
   build_infot   all_languagesRB   t   ext_languagest   c_libst
   c_lib_dirsR6   t   binfot   mt   lt
   new_c_libst   ext_languaget   need_f90_compilert   need_f77_compilert   need_cxx_compilerR0   t   ctypeR   t	   pkg_rootst   pkg_roott   shared_lib_dirt   fnt   runtime_lib(    (   R   s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pyRL   J   s4   						

				,		
%											
																	
	c         C` s   | S(   N(    (   R   R_   (    (    s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pyt   swig_sources  s    c   $      C` s¥  | j  } | d  k s" t | ƒ r@ t d d d | j ƒ ‚ n  t | ƒ } | sV d  S|  j | j ƒ } |  j rß | j d ƒ } d j	 | d d !ƒ } | d } |  j
 d ƒ } | j | ƒ } t j j	 | |  j | ƒ ƒ }	 n! t j j	 |  j |  j | ƒ ƒ }	 | | j }
 |  j p%t |
 |	 d ƒ s?t j d	 | j ƒ d  St j d
 | j ƒ | j p^g  } | j } x! | j D] } | j | f ƒ quWt | j  ƒ \ } } } } |  j j d k rå| rÒ| j d ƒ n  | | 7} g  } n  | j d k r |  j } n- | j d k r|  j } n |  j p*|  j } | d  k	 rŠt  | d ƒ rW| j! pZg  n g  | _! t  | d ƒ r~| j" pg  n g  | _" n  |  j# } | r»| d  k r»t$ d | j ƒ ‚ n  | sÇ| ré| d  k rét$ d | j ƒ ‚ n  | j d* k r| d  k r|  j% d | j ƒ n  | j d k rM| d  k rM|  j% d | j ƒ n  i | j d 6} |  j& } | j' t( ƒ  } g  } | rÈt j d ƒ |  j j) | d | d | d | d |  j d | | } n  | rt j d ƒ | | j) | d | d | d | d |  j d | | 7} n  g  } g  } | rÊt j d ƒ | j* } t j j	 |  j& t j j+ |  j | ƒ ƒ ƒ } |  j, | ƒ | j- d  k r–t. d ƒ } n  | | j/ | | ƒ 7} | | j) | d |  j& d | d | d |  j d | d | j ƒ7} | j- d  k rÊxÉ t. d ƒ D]¸ } | | k r qn  t j j	 | | ƒ } t j j0 | ƒ t j j0 | ƒ k r_qn  t j j1 | ƒ rt j2 | ƒ n  y |  j3 | | ƒ Wqt4 k
 r¿t j% d  | | f ƒ qXqWqÊn  | r t j d! ƒ | | j) | d |  j& d | d | d |  j d | d | j ƒ7} n  | rH| j5 |  j ƒ rH| } | }  n g  } | | }  | j6 rt|  j7 | j6 ƒ n  | j8 p€g  } |  j9 | ƒ }! | j: }" |  j j; }# |  j j d+ k rÑ|  j< | |! |" ƒ n' | j d, k rø| d  k	 rø| j; }# n  | j d k r| d  k	 r| j; }# n  | d  k	 rO|  j= |  |! | |" | ƒ \ }  }! n  |# |  |	 d$ |! d% |" d& | j> d | d' |  j? | ƒ d |  j d( |  j& d) | j ƒd  S(-   Ns*   in 'ext_modules' option (extension '%s'), s&   'sources' must be present and must be s   a list of source filenamesR>   i    iÿÿÿÿt   build_pyt   newers$   skipping '%s' extension (up-to-date)s   building '%s' extensiont   msvcs   /Zm1000R9   R8   t   extra_f77_compile_argst   extra_f90_compile_argss5   extension %r has C++ sourcesbut no C++ compiler founds>   extension %r has Fortran sources but no Fortran compiler foundsT   extension %r has Fortran libraries but no Fortran linker found, using default linkers   c++sL   extension %r has C++ libraries but no C++ linker found, using default linkert   dependss   compiling C sourcest
   output_dirR6   R"   t   debugt   extra_postargss   compiling C++ sourcess#   compiling Fortran 90 module sourcess   *.mods   failed to move %r to %rs   compiling Fortran sourcest   intelwt   intelemwR4   R5   t   runtime_library_dirst   export_symbolsRV   t   target_lang(   R8   R9   (   Rˆ   R   R   (   R8   R9   (@   R_   R   R   R   R@   t   listR?   RF   R$   RU   RM   t   get_package_dirR%   RT   t   get_ext_filenameRl   R‹   R3   R   R
   R   R]   t   extra_compile_argsR^   t   undef_macrosRN   R   R0   Rg   R`   Rj   Rf   t   hasattrR‰   RŠ   Rc   R   RI   RV   R"   R   t   compilet   module_dirst   dirnamet   mkpatht   module_dir_switchR   t   module_optionst   abspatht   isfilet   removet	   move_fileR   t   can_ccompiler_linkt   extra_objectsR(   t   extra_link_argst   get_librariesR5   t   link_shared_objectt   _libs_with_msvc_and_fortrant   _process_unlinkable_fobjectsR‘   t   get_export_symbols($   R   RB   R_   t   fullnamet   modpatht   packaget   baseR†   t   package_dirt   ext_filenameR‹   t
   extra_argsR6   t   undeft	   c_sourcest   cxx_sourcest	   f_sourcest   fmodule_sourcesR   Rd   t   kwsRŒ   R"   t	   c_objectsRŽ   t	   f_objectsR›   t   module_build_dirt   existing_modulest   ft   tt   unlinkable_fobjectst   objectsR4   R5   t   linker(    (    s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pyt   build_extension   s4   		


	$'						
				$				
	
			c         C` sw   |  j  d ƒ j } |  j  d ƒ j } |  j j t j j | d ƒ g d |  j ƒ} |  j j	 | d d | d |  j
 ƒd  S(   NR,   R-   s   gfortran_vs2003_hack.cRŒ   t   _gfortran_workaroundR   (   RM   R,   R-   R0   Rš   R%   RT   RU   RV   t   create_static_libR   (   R   R´   R,   R-   RÀ   (    (    s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pyt   _add_dummy_mingwex_symß  s    	c      	   C` sh  t  | ƒ } t  | ƒ } t  | ƒ } xÛ t  | ƒ D]Í } xÄ | D]¼ } t j j | | d ƒ } t j j | ƒ r> | j | ƒ t | d ƒ   }	 | j |	 j ƒ  j	 ƒ  ƒ Wd  QXt j j | | d ƒ }
 t |
 d ƒ   }	 | j |	 j ƒ  j	 ƒ  ƒ Wd  QXq> q> Wq1 W| r^g  | D] } t j j
 | ƒ ^ q} | j | d |  j d |  j ƒ} | j | ƒ n  | | f S(   Ns	   .fobjectst   rs	   .cobjectsRŒ   RW   (   R”   R%   RT   RU   R¡   R¢   t   openR(   t   readt
   splitlinest   relpatht   wrap_unlinkable_objectsRV   RW   (   R   RÀ   R4   R   R5   R¿   t   libt   libdirt   fake_libR½   t   c_libt   objt   fobjectst   wrapped(    (    s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pyRª   è  s(    *%c         C` s”  | d  k r d  Sx;| D]3} | j d ƒ r2 q n  t } xI | pD g  D]; } t j j | d | ƒ } t j j | ƒ rE t } PqE qE W| r q n  t } xŽ | D]† } t j j | d | ƒ } t j j | ƒ r t j j |  j | d ƒ } t	 | | ƒ |  j | k r| j
 |  j ƒ n  t } Pq q W| r3q n  t j d | | f ƒ q Wg  }	 xu | j D]j }
 |
 j d ƒ r»y t j d d |
 g ƒ }
 Wn t t j f k
 r«q»Xt |
 ƒ }
 n  |	 j
 |
 ƒ q^W| j |	 ƒ x´ | j D]© } | j d ƒ sã| j
 | ƒ t |	 d	 | d
 ƒ } | rŒt j j |  j | d ƒ } t j j | ƒ sdt	 | d | ƒ n  |  j | k r‰| j
 |  j ƒ q‰qŒqãqãWd  S(   NRˆ   s   %s.libs   lib%s.as   .libs+   could not find library %r in directories %ss   /usr/libt   cygpaths   -wRÌ   s   .ai    (   R   t
   startswithRe   R%   RT   RU   R¡   Ri   RV   R	   RN   R
   RI   R5   t
   subprocesst   check_outputt   OSErrort   CalledProcessErrorR   R(   R4   R   (   R   R   t   c_librariest   c_library_dirsRq   t
   fileexistsRÍ   t   libfilet   libfile2t
   f_lib_dirst   dirRÌ   t   pt   dst_name(    (    s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pyR©     s^    	c         C` sA   |  j  |  j ƒ g  } x$ |  j D] } | j t | ƒ ƒ q  W| S(   N(   t   check_extensions_listRC   R(   R   (   R   t	   filenamesRB   (    (    s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pyt   get_source_filesE  s
    c         C` sw   |  j  |  j ƒ g  } xZ |  j D]O } | j s5 q  n  |  j | j ƒ } | j t j j |  j	 |  j
 | ƒ ƒ ƒ q  W| S(   N(   Râ   RC   R_   R?   R@   RN   R%   RT   RU   Rl   R–   (   R   t   outputsRB   R¬   (    (    s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pyt   get_outputsL  s    	N(   s
   fcompiler=Ns!   specify the Fortran compiler type(   s	   parallel=R   s   number of parallel jobs(   t   __name__t
   __module__t   descriptionR   t   user_optionsR   t   help_optionsR   R   R)   RL   R…   RÂ   RÅ   Rª   R©   Rä   Ræ   (    (    (    s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pyR      s&     
				Ò		¿			 	=	(%   t   __doc__t
   __future__R    R   R   R%   RÕ   R   t   distutils.dep_utilR   t   distutils.command.build_extR   R   t   distutils.errorsR   R   R   t   distutils.file_utilR	   t   numpy.distutilsR
   t   numpy.distutils.exec_commandR   t   numpy.distutils.system_infoR   R   t   numpy.distutils.misc_utilR   R   R   R   R   R   R   R   t'   numpy.distutils.command.config_compilerR   (    (    (    s@   lib/python2.7/site-packages/numpy/distutils/command/build_ext.pyt   <module>   s   :