ó
¨9Vc           @   s  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
 d  d l m Z d  d l Z d  d l Z d  d l Z d  d l m Z y d  d l m Z Wn e k
 rÁ e Z n Xy d  d	 l m Z Wn> e k
 rd  d
 l m Z e d ƒ [ d  d l m Z n Xe Z e Z d Z e j d k rAe Z nI e j d k rŠy# d  d l  Z  e! e  d ƒ Z Z WqŠe k
 r†qŠXn  d „  Z" d e f d „  ƒ  YZ e s¾e j d k rèd d d d d d d d d d d „
 Z$ n- d Z d d d d d d d d d d d „
 Z$ d S(   iÿÿÿÿ(   t	   build_ext(   t	   copy_file(   t   new_compiler(   t   customize_compiler(   t   DistutilsError(   t   logN(   t   Library(   t   _CONFIG_VARS(   t   get_config_vart   LDSHARED(   t   _config_varst   sharedt   darwint   ntt   RTLD_NOWc         C   s   t  r
 |  Sd S(   Nt    (   t	   have_rtld(   t   s(    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyt   <lambda>+   s    R    c           B   s€   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z e d „ Z RS(   c         C   s@   |  j  d } |  _  t j |  ƒ | |  _  | r< |  j ƒ  n  d S(   s;   Build extensions in build directory, then copy if --inplacei    N(   t   inplacet
   _build_extt   runt   copy_extensions_to_source(   t   selft   old_inplace(    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyR   .   s
    	c   
      C   sù   |  j  d ƒ } xã |  j D]Ø } |  j | j ƒ } |  j | ƒ } | j d ƒ } d j | d  ƒ } | j | ƒ } t j	 j | t j	 j
 | ƒ ƒ } t j	 j |  j | ƒ }	 t |	 | d |  j d |  j ƒ| j r |  j | pä t j | t ƒ q q Wd  S(   Nt   build_pyt   .iÿÿÿÿt   verboset   dry_run(   t   get_finalized_commandt
   extensionst   get_ext_fullnamet   namet   get_ext_filenamet   splitt   joint   get_package_dirt   ost   patht   basenamet	   build_libR   R   R   t   _needs_stubt
   write_stubt   curdirt   True(
   R   R   t   extt   fullnamet   filenamet   modpatht   packaget   package_dirt   dest_filenamet   src_filename(    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyR   6   s    
	c         C   s­   t  j |  | ƒ } | |  j k r© |  j | } t | t ƒ rh t j j | ƒ \ } } |  j j	 | t
 ƒ St r© | j r© t j j | ƒ \ } } t j j | d | ƒ Sn  | S(   Ns   dl-(   R   R!   t   ext_mapt
   isinstanceR   R%   R&   t   splitextt   shlib_compilert   library_filenamet   libtypet	   use_stubst   _links_to_dynamicR"   R#   (   R   R.   R/   R-   t   fnt   d(    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyR!   L   s    c         C   s,   t  j |  ƒ d  |  _ g  |  _ i  |  _ d  S(   N(   R   t   initialize_optionst   NoneR8   t   shlibsR5   (   R   (    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyR?   X   s    		c         C   sÆ  t  j |  ƒ |  j p g  |  _ |  j |  j ƒ g  |  j D] } t | t ƒ r9 | ^ q9 |  _ |  j rs |  j ƒ  n  x& |  j D] } |  j | j	 ƒ | _
 q} Wx#|  j D]} | j
 } | |  j | <| |  j | j d ƒ d <|  j rô |  j | ƒ p÷ t } | ot ot | t ƒ } | | _ | | _ |  j | ƒ } | _ t j j t j j |  j | ƒ ƒ } | rŠ| | j k rŠ| j j | ƒ n  | r¦ t r¦ t j | j k r¦ | j j t j ƒ q¦ q¦ Wd  S(   NR   iÿÿÿÿ(   R   t   finalize_optionsR   t   check_extensions_listR6   R   RA   t   setup_shlib_compilerR   R    t
   _full_nameR5   R"   t   links_to_dynamict   FalseR;   R<   R)   R!   t
   _file_nameR%   R&   t   dirnameR#   R(   t   library_dirst   appendR+   t   runtime_library_dirs(   R   R-   R.   t   ltdt   nsR/   t   libdir(    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyRB   ^   s.    				$c         C   sÉ  t  d |  j d |  j d |  j ƒ } |  _ t j d k r t j ƒ  } z, d t d <d t d <d	 t d
 <t	 | ƒ Wd  t j
 ƒ  t j | ƒ Xn
 t	 | ƒ |  j d  k	 r¼ | j |  j ƒ n  |  j d  k	 rø x* |  j D] \ } } | j | | ƒ qÕ Wn  |  j d  k	 r+x! |  j D] } | j | ƒ qWn  |  j d  k	 rM| j |  j ƒ n  |  j d  k	 ro| j |  j ƒ n  |  j d  k	 r‘| j |  j ƒ n  |  j d  k	 r³| j |  j ƒ n  t j | ƒ | _ d  S(   Nt   compilerR   t   forceR   s0   gcc -Wl,-x -dynamiclib -undefined dynamic_lookupR	   s    -dynamiclibt   CCSHAREDs   .dylibt   SO(   R   RP   R   RQ   R8   t   syst   platformR   t   copyR   t   cleart   updatet   include_dirsR@   t   set_include_dirst   definet   define_macrot   undeft   undefine_macrot	   librariest   set_librariesRJ   t   set_library_dirst   rpatht   set_runtime_library_dirst   link_objectst   set_link_objectst   link_shared_objectt   __get__(   R   RP   t   tmpR    t   valuet   macro(    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyRD   {   s:    %




c         C   s&   t  | t ƒ r | j St j |  | ƒ S(   N(   R6   R   t   export_symbolsR   t   get_export_symbols(   R   R-   (    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyRl   £   s    c         C   s„   | j  ƒ  |  j } z` t | t ƒ r4 |  j |  _ n  t j |  | ƒ | j rr |  j d ƒ j	 } |  j
 | | ƒ n  Wd  | |  _ Xd  S(   NR   (   t   _convert_pyx_sources_to_langRP   R6   R   R8   R   t   build_extensionR)   R   R(   R*   (   R   R-   t	   _compilert   cmd(    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyRn   ¨   s    
		c            sn   t  j g  |  j D] } | j ^ q ƒ ‰  d j | j j d ƒ d  d g ƒ ‰ t ‡  ‡ f d †  | j Dƒ ƒ S(   s?   Return true if 'ext' links to a dynamic lib in the same packageR   iÿÿÿÿR   c         3   s   |  ] } ˆ | ˆ  k Vq d  S(   N(    (   t   .0t   libname(   t   libnamest   pkg(    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pys	   <genexpr>¼   s    (   t   dictt   fromkeysRA   RE   R#   R"   t   anyR_   (   R   R-   t   lib(    (   Rs   Rt   s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyRF   µ   s    (&c         C   s   t  j |  ƒ |  j ƒ  S(   N(   R   t   get_outputst   _build_ext__get_stubs_outputs(   R   (    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyRy   ¾   s    c            sE   ‡  f d †  ˆ  j  Dƒ } t j | ˆ  j ƒ  ƒ } t d „  | Dƒ ƒ S(   Nc         3   s<   |  ]2 } | j  r t j j ˆ  j | j j d  ƒ Œ Vq d S(   R   N(   R)   R%   R&   R#   R(   RE   R"   (   Rq   R-   (   R   (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pys	   <genexpr>Ä   s   c         s   s   |  ] \ } } | | Vq d  S(   N(    (   Rq   t   baset   fnext(    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pys	   <genexpr>Ê   s    (   R   t	   itertoolst   productt!   _build_ext__get_output_extensionst   list(   R   t   ns_ext_basest   pairs(    (   R   s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyt   __get_stubs_outputsÁ   s    c         c   s(   d Vd V|  j  d ƒ j r$ d Vn  d  S(   Ns   .pys   .pycR   s   .pyo(   R   t   optimize(   R   (    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyt   __get_output_extensionsÌ   s    c         C   s´  t  j d | j | ƒ t j j | | j j d ƒ Œ d } | rf t j j | ƒ rf t | d ƒ ‚ n  |  j	 st
 | d ƒ } | j d j d d d	 t d
 ƒ d t j j | j ƒ d d d t d ƒ d d d t d ƒ d d t d ƒ d d d g ƒ ƒ | j ƒ  n  | r°d d l m } | | g d d d t d |  j	 ƒ|  j d  ƒ j } | d k r| | g d | d t d |  j	 ƒn  t j j | ƒ r°|  j	 r°t j | ƒ q°n  d  S(!   Ns    writing stub loader for %s to %sR   s   .pys    already exists! Please delete.t   ws   
s   def __bootstrap__():s-      global __bootstrap__, __file__, __loader__s%      import sys, os, pkg_resources, imps   , dls:      __file__ = pkg_resources.resource_filename(__name__,%r)s      del __bootstrap__s       if '__loader__' in globals():s          del __loader__s#      old_flags = sys.getdlopenflags()s      old_dir = os.getcwd()s      try:s(        os.chdir(os.path.dirname(__file__))s$        sys.setdlopenflags(dl.RTLD_NOW)s(        imp.load_dynamic(__name__,__file__)s      finally:s"        sys.setdlopenflags(old_flags)s        os.chdir(old_dir)s   __bootstrap__()R   iÿÿÿÿ(   t   byte_compileR„   i    RQ   R   t   install_lib(   R   t   infoRE   R%   R&   R#   R"   t   existsR   R   t   opent   writet   if_dlR'   RH   t   closet   distutils.utilR‡   R,   R   R„   t   unlink(   R   t
   output_dirR-   t   compilet	   stub_filet   fR‡   R„   (    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyR*   Ò   sP    				(   t   __name__t
   __module__R   R   R!   R?   RB   RD   Rl   Rn   RF   Ry   Rz   R   RG   R*   (    (    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyR    -   s   						(							i    c         C   s8   |  j  |  j | | | | | | | | |	 |
 | | ƒ d  S(   N(   t   linkt   SHARED_LIBRARY(   R   t   objectst   output_libnameR‘   R_   RJ   RL   Rk   t   debugt   extra_preargst   extra_postargst
   build_tempt   target_lang(    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyRf     s
    t   staticc         C   s„   | d  k s t ‚ t j j | ƒ \ } } t j j | ƒ \ } } |  j d ƒ j d ƒ rg | d } n  |  j | | | | | ƒ d  S(   Nt   xRx   i   (	   R@   t   AssertionErrorR%   R&   R"   R7   R9   t
   startswitht   create_static_lib(   R   R™   Rš   R‘   R_   RJ   RL   Rk   R›   Rœ   R   Rž   RŸ   R/   R'   R-   (    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyRf     s    (%   t   distutils.command.build_extR    t   _du_build_extt   distutils.file_utilR   t   distutils.ccompilerR   t   distutils.sysconfigR   t   distutils.errorsR   t	   distutilsR   R%   RT   R}   t   setuptools.extensionR   t   Cython.Distutils.build_extR   t   ImportErrort	   sysconfigR   R   R
   RG   R   R;   R:   RU   R,   R    t   dlt   hasattrR   R@   Rf   (    (    (    s@   /tmp/pip-build-5Z5nTX/setuptools/setuptools/command/build_ext.pyt   <module>   sV   

		Ô			