ó
ØÆ÷Xc           @` sV  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 d d l m Z m Z m Z m Z m Z m Z m  Z  m! Z! d d l" m# Z# y e$ Wn! e% k
 r;d d l& m' Z$ n Xd 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   exec_command(   t   combine_paths(   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_compilers(   t   SetR   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 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@   /tmp/pip-build-X4mzal/numpy/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   (   s   parallels   parallel(   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@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_ext.pyR)   3   s    	
c         C` s  |  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 ƒ  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 pg  D]( \ } } | | k r*qn  | | | <q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Wqv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$ ƒ rô|
 j d ƒ n  |	 j& p|  j j' |	 j$ ƒ } | r(|
 j | ƒ n  d |
 k r=d } n0 d |
 k rRd } n d |
 k rgd } n d } | r¨| | k r¨|	 j& r¨t j d |	 j! | | f ƒ n  | |	 _& | j( |
 ƒ qKWd | k } d | k } d | k } | ra| d | d	 |  j d
 |  j d |  j ƒ |  _) |  j) } | j |  j d | ƒ| j |  ƒ | j ƒ  | j* ƒ  |  _) n	 d  |  _) | r,|  j+ } | d |  j+ d	 |  j d
 |  j d |  j d t, d |  j ƒ |  _- |  j- } | rã| j. } | j |  j ƒ n  | r| j/ ƒ  r| j |  ƒ | j ƒ  q5|  j d | ƒ d  |  _- n	 d  |  _- | r÷|  j+ } | d |  j+ d	 |  j d
 |  j d |  j d t0 d |  j ƒ |  _1 |  j1 } | r®| j. } | j |  j ƒ n  | rÚ| j/ ƒ  rÚ| j |  ƒ | j ƒ  q |  j d | ƒ d  |  _1 n	 d  |  _1 |  j2 ƒ  d  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   forcesK   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.(3   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_customizationR4   t   reprt   sett   addt   infot   namet   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_extensions(   R   R-   R.   R/   R]   t   clibst   libnamet
   build_infot   all_languagest   extt   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   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_ext.pyRG   M   s   			

				,		
%											
																	c         C` s   | S(   N(    (   R   RU   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_ext.pyt   swig_sources  s    c   #      C` sG  | 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  | | } | j5 rF| j6 | j5 ƒ n  | j7 pRg  } |  j8 | ƒ }  | j9 }! |  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$ |  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 filenamest   .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_symbolst
   build_tempt   target_lang(   s   f77s   f90(   s   msvcR~   R   (   s   f77s   f90(>   RU   R   R   R   RS   t   listt   get_ext_fullnameRA   R$   t   joinRH   t   get_package_dirR%   t   patht   get_ext_filenamet	   build_libRz   R3   R   R
   R|   RR   t   extra_compile_argsRT   t   undef_macrosRI   R   R0   R]   RV   R`   R\   t   hasattrRx   Ry   RY   R   RD   R‚   R"   R   t   compilet   module_dirst   dirnamet   mkpatht   module_dir_switchR   t   module_optionst   abspatht   isfilet   removet	   move_fileR   t   extra_objectsR(   t   extra_link_argst   get_librariesR5   t   link_shared_objectt   _libs_with_msvc_and_fortranR€   t   get_export_symbols(#   R   Rf   RU   t   fullnamet   modpatht   packaget   baseRu   t   package_dirt   ext_filenameRz   t
   extra_argsR6   t   undeft	   c_sourcest   cxx_sourcest	   f_sourcest   fmodule_sourcesR   RZ   t   kwsR{   R"   t	   c_objectsR}   t	   f_objectsR   t   module_build_dirt   existing_modulest   ft   tt   objectsR4   R5   t   linker(    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_ext.pyt   build_extension  s   		


	'*						
				$			
	
			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|   (   RH   R,   R-   R0   RŽ   R%   Rˆ   R†   R‚   t   create_static_libR|   (   R   R¦   R,   R-   R±   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_ext.pyt   _add_dummy_mingwex_sym»  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  }	 x` | j D]U }
 |
 j d ƒ r¦t d d |
 g d	 t ƒ\ } } | s¦| }
 q¦n  |	 j
 |
 ƒ q^W| j |	 ƒ x´ | j D]© } | j d ƒ sÎ| j
 | ƒ t |	 d
 | d ƒ } | rwt j j |  j | d ƒ } t j j | ƒ sOt	 | d | ƒ n  |  j | k rt| j
 |  j ƒ qtqwqÎqÎWd  S(   NRw   s   %s.libs   lib%s.as   .libs+   could not find library %r in directories %ss   /usr/libt   cygpaths   -wt   use_teet   libs   .ai    (   R   t
   startswithR[   R%   Rˆ   R†   R•   R_   R‚   R	   RI   R
   RD   R5   R   R(   R4   R   (   R   R   t   c_librariest   c_library_dirsRc   t
   fileexistst   libdirt   libfilet   libfile2t
   f_lib_dirst   dirt   st   oR¹   t   pt   dst_name(    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_ext.pyRœ   Ã  sZ        	!c         C` sA   |  j  |  j ƒ g  } x$ |  j D] } | j t | ƒ ƒ q  W| S(   N(   t   check_extensions_listR>   R(   R   (   R   t	   filenamesRf   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_ext.pyt   get_source_filesù  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Ç   R>   RU   R…   RS   RI   R%   Rˆ   R†   RŠ   R‰   (   R   t   outputsRf   Rž   (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_ext.pyt   get_outputs   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)   RG   Rs   R³   R¶   Rœ   RÉ   RË   (    (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_ext.pyR      s$     
				·		³		6	((   t   __doc__t
   __future__R    R   R   R%   t   sysR   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   t   numpy.distutils.misc_utilR   R   R   R   R   R   R   R   t'   numpy.distutils.command.config_compilerR   RP   t	   NameErrort   setsR   (    (    (    s@   /tmp/pip-build-X4mzal/numpy/numpy/distutils/command/build_ext.pyt   <module>   s$   :