ó
ØÆ÷Xc           @` s”  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l Z d d l	 Z
 e j d d k  r„ d d l m Z n d d l m Z d d l Z d d l m Z d d l	 m Z 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 m  Z  e j! d ƒ Z" e j! d ƒ Z# d e j$ j% f d „  ƒ  YZ& d „  Z' d „  Z( d „  Z) d „  Z* e+ d „ Z, d „  Z- d „  Z. d „  Z/ i  Z0 e j1 d k rNyx d d l2 Z2 d e0 d <d e0 d <d e0 d <e3 e2 d  ƒ r)e2 j4 j5 d! d" ƒ \ Z6 Z7 Z8 e2 j4 e0 e6 e7 <[6 [7 [8 n  WqNe9 k
 rJe j: d# ƒ qNXn  d$ „  Z; d% d& „ Z< d' „  Z= d( „  Z> d) „  Z? d* „  Z@ d+ „  ZA d S(,   s  
Support code for building Python extensions on Windows.

    # NT stuff
    # 1. Make sure libpython<version>.a exists for gcc.  If not, build it.
    # 2. Force windows to use gcc (we're struggling with MSVC and g77 support)
    # 3. Force windows to use g77

i    (   t   divisiont   absolute_importt   print_functionNi   i   (   t   log(   t   StrictVersion(   t   gen_preprocess_optionst   gen_lib_options(   t   UnixCCompiler(   t   get_build_version(   t   DistutilsExecErrort   CompileErrort   UnknownFileError(   t   msvc_runtime_libraryt   get_build_architectures   \[Ordinal/Name Pointer\] Tables$   ^\s+\[([\s*[0-9]*)\] ([a-zA-Z0-9_]*)t   Mingw32CCompilerc           B` sP   e  Z d  Z d Z d d d d „ Z d d d d d d d „ Z d d d „ Z RS(   sH    A modified MingW32 compiler compatible with an MSVC built Python.

    t   mingw32i    c         C` sw  t  j j j |  | | | ƒ |  j d  k r­ d d  l } t j d d g d t	 d t j
 ƒ} | j j ƒ  } | j j ƒ  | j d | ƒ } | r­ t | j d ƒ ƒ |  _ q­ n  |  j d k rÅ d	 } n d
 } |  j d k ræ d |  _ n |  j d k rd |  _ n  t ƒ  t ƒ  }	 t d t	 ƒ }
 |	 s,|
 r<|  j d ƒ n  d t t ƒ  j d ƒ ƒ } |  j d | ƒ t ƒ  d k rÐ|  j d k  r«|  j d d d d d d d d ƒ qg|  j d d d d d d d d ƒ n— |  j d  k r|  j d d! d d" d d# d d$ |  j | f ƒ nV |  j d k  rE|  j d d% d d& d d# d d' ƒ n" |  j d d( d d) d d* d d+ ƒ d g |  _ d  S(,   Ni    t   gccs   -dumpversiont   shellt   stdouts
   (\d+\.\d+)i   s   2.91.57s   --entry _DllMain@12t    t   dllwraps   g++t   debugt   NPY_MINGW_USE_CUSTOM_MSVCRs   0x%03i0t   msvcrt   __MSVCRT_VERSION__t   AMD64s   4.0t   compilers/   gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wallt   compiler_sosC   gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall -Wstrict-prototypest
   linker_exes   gcc -g -mno-cygwint	   linker_sos   gcc -g -mno-cygwin -shareds#   gcc -g -DDEBUG -DMS_WIN64 -O0 -Walls7   gcc -g -DDEBUG -DMS_WIN64 -O0 -Wall -Wstrict-prototypess   gcc -gs   gcc -g -shareds   3.0.0s   gcc -mno-cygwin -O2 -ws0   gcc -mno-cygwin -mdll -O2 -w -Wstrict-prototypess   g++ -mno-cygwins   %s -mno-cygwin -mdll -static %ss   gcc -mno-cygwin -O2 -Walls-   gcc -mno-cygwin -O2 -Wall -Wstrict-prototypess   g++ -mno-cygwin -shareds   gcc -O2 -Walls!   gcc -O2 -Wall -Wstrict-prototypess   g++ s   g++ -shared(   t	   distutilst   cygwinccompilert   CygwinCCompilert   __init__t   gcc_versiont   Nonet   ret
   subprocesst   Popent   Truet   PIPER   t   readt   closet   searchR   t   groupt
   linker_dllt   linkert   build_import_libraryt   build_msvcr_libraryt   define_macrot   intR   t   lstripR   t   set_executablest   compiler_cxx(   t   selft   verboset   dry_runt   forceR$   t   pt
   out_stringt   resultt   entry_pointt   msvcr_successt   msvcr_dbg_successt   msvcr_version(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyR!   4   sp    
			
	
		
c         C` s    t  ƒ  } | r. | s g  } n  | j | ƒ n  |  | | | | | | | d  |	 |
 | | | f } |  j d k  r t j j j } n	 t j } | | | j	 j
  Œ  d  S(   Ns   3.0.0(   R   t   appendR#   R"   R   R   R    t   linkR   t   __code__t   co_argcount(   R6   t   target_desct   objectst   output_filenamet
   output_dirt	   librariest   library_dirst   runtime_library_dirst   export_symbolsR   t   extra_preargst   extra_postargst
   build_tempt   target_langt   runtime_libraryt   argst   func(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyRB   ¡   s0    				R   c   	      C` s1  | d  k r d } n  g  } x| D]} t j j t j j | ƒ ƒ \ } } t j j | ƒ \ } } | rw | d } n  | |  j d d g k r© t d | | f ƒ ‚ n  | rÄ t j j | ƒ } n  | d k sÜ | d k r| j	 t j j
 | | | |  j ƒ ƒ q" | j	 t j j
 | | |  j ƒ ƒ q" W| S(   NR   i   s   .rcs   .ress"   unknown file type '%s' (from '%s')(   R#   t   ost   patht   splitextt   normcaset
   splitdrivet   src_extensionsR   t   basenameRA   t   joint   obj_extension(	   R6   t   source_filenamest	   strip_dirRH   t	   obj_namest   src_namet   baset   extt   drv(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   object_filenamesË   s(     	$N(   t   __name__t
   __module__t   __doc__t   compiler_typeR!   R#   RB   Rd   (    (    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyR   -   s   rc          C` sÿ   g  t  j d  D] }  t |  ƒ ^ q \ } } } d | | f } t d | ƒ t  j t j j t  j d ƒ g } y' | j t j j t j	 d d ƒ ƒ Wn t
 k
 r¨ n Xx9 | D]1 } t j j | | ƒ } t j j | ƒ r° | Sq° Wt d | | f ƒ ‚ d  S(   Ni   s   python%d%d.dlls   Looking for %st   libt
   SYSTEMROOTt   system32s   %s not found in %s(   t   syst   version_infoR2   t   printt   prefixRT   RU   R[   RA   t   environt   KeyErrort   existst
   ValueError(   t   it   majt   mint   microt   dllnamet   lib_dirst   dt   dll(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   find_python_dllî   s    /!'c         C` s.   t  j d d |  g d t  j ƒ} | j j ƒ  S(   Ns   objdump.exes   -pR   (   R%   R&   R(   R   t	   readlines(   R{   t   st(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt
   dump_table  s    !c   	      C` s}  t  |  ƒ } xC t t | ƒ ƒ D]# } t j | | j ƒ  ƒ r Pq q Wt d ƒ ‚ g  } xu t | d t | ƒ ƒ D]Z } t j | | j ƒ  ƒ } | rË | j t	 | j
 d ƒ j ƒ  ƒ | j
 d ƒ f ƒ qr Pqr Wt | ƒ d k rö t j d |  ƒ n  t | d ƒ } | j d t j j |  ƒ ƒ | j d ƒ | j d	 ƒ | j d
 ƒ x# | D] } | j d | d ƒ qPW| j ƒ  d S(   sŠ   Given a dll file location,  get all its exported symbols and dump them
    into the given def file.

    The .def file will be overwrittens   Symbol table not foundi   i   i    s   No symbols found in %st   ws   LIBRARY        %s
s,   ;CODE          PRELOAD MOVEABLE DISCARDABLE
s   ;DATA          PRELOAD SINGLE
s	   
EXPORTS
s   %s
N(   R   t   ranget   lent   _STARTt   matcht   decodeRs   t   _TABLERA   R2   R,   t   stripR   t   warnt   opent   writeRT   RU   RZ   R*   (	   R{   t   dfilet   dumpRt   t   symst   jt   mRz   t   s(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   generate_def  s*     4c         ` sI   i d d 6d d 6t  ƒ  ‰  ‡  f d †  } d „  } | |  ƒ pH | |  ƒ S(   Nt   amd64R   t   x86t   Intelc         ` s„   t  j j t  j d d ƒ } t  j j | ƒ s2 d  SxK t  j | ƒ D]: \ } } } |  | k rB ˆ  | k rB t  j j | |  ƒ SqB Wd  S(   Nt   WINDIRt   winsxs(   RT   RU   R[   Rp   Rr   R#   t   walk(   t   dll_namet   winsxs_patht   roott   dirst   files(   t   arch(    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   _find_dll_in_winsxs.  s    c         S` sf   x_ t  j g t j d j d ƒ D]= } t j j | |  ƒ } t j j | ƒ r! t j j | ƒ Sq! Wd  S(   Nt   PATHt   ;(	   Rl   Ro   RT   Rp   t   splitRU   R[   Rr   t   abspath(   R˜   RU   t   filepath(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   _find_dll_in_path8  s    '(   R   (   R˜   Rž   R¤   (    (   R   s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   find_dll)  s
    

	c   
      C` sZ  t  j d k r t St ƒ  } t | j d ƒ ƒ d k  rH t j d ƒ t S|  r[ | d 7} n  d | } t  j j	 t
 j d | ƒ } t  j j | ƒ rª t j d | f ƒ t S| d	 } t | ƒ } | sÛ t j d
 | ƒ t Sd | } t  j j	 t
 j d | ƒ } t j d | | f ƒ t | | ƒ d d | d | g } t j | ƒ }	 t  j | ƒ |	 S(   Nt   ntR   iP   s=   Skip building msvcr library: custom functionality not presentRz   s   lib%s.at   libss(   Skip building msvcr library: "%s" existss   .dlls*   Cannot build msvcr library: "%s" not founds	   lib%s.defs&   Building msvcr library: "%s" (from %s)t   dlltools   -ds   -l(   RT   t   namet   FalseR   R2   R3   R   R   RU   R[   Rl   Ro   t   isfileR'   R¥   Rˆ   t   infoR‘   R%   t   callt   remove(
   R   t
   msvcr_namet   out_namet   out_filet   msvcr_dll_namet   dll_filet   def_namet   def_filet   cmdt   retcode(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyR0   B  s:    	
	
	
	c          C` sV   t  j d k r d  St ƒ  }  |  d k r/ t ƒ  S|  d k rB t ƒ  St d |  ƒ ‚ d  S(   NR¦   R   R”   s   Unhandled arch %s(   RT   R©   R   t   _build_import_library_amd64t   _build_import_library_x86Rs   (   R   (    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyR/   s  s    	c          C` sÞ   t  ƒ  }  d t t j d  ƒ } t j j t j d | ƒ } t j j | ƒ rb t	 j
 d | ƒ d  Sd t t j d  ƒ } t j j t j d | ƒ } t	 j d | |  f ƒ t |  | ƒ d d | d	 | g } t j | ƒ d  S(
   Ns   libpython%d%d.ai   R§   s)   Skip building import library: "%s" existss   python%d%d.defs4   Building import library (arch=AMD64): "%s" (from %s)R¨   s   -ds   -l(   R|   t   tupleRl   Rm   RT   RU   R[   Ro   R«   R   R   R¬   R‘   R%   R&   (   R³   R°   R±   R´   Rµ   R¶   (    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyR¸     s    			c          C` s·  d t  t j d  ƒ }  t j j t j d |  ƒ } d t  t j d  ƒ } t j j t j d | ƒ } t j j | ƒ s‹ t j	 d | ƒ d St j j | ƒ r² t j
 d | ƒ d St j d | ƒ d	 d
 l m } d t  t j d  ƒ } t j j t j d | ƒ } d | j | f } | j | ƒ } | j | ƒ \ }	 }
 | j |	 |
 | j t | d ƒ ƒ d t  t j d  ƒ } | | | f } d | } t j | ƒ } | r³t j	 d ƒ n  d S(   s;    Build the import libraries for Mingw32-gcc on Windows
    s   python%d%d.libi   R§   s   libpython%d%d.as+   Cannot build import library: "%s" not foundNs)   Skip building import library: "%s" existss(   Building import library (ARCH=x86): "%s"i    (   t   lib2defs   python%d%d.defs   %s %sR€   s   python%d%d.dlls-   dlltool --dllname %s --def %s --output-lib %ss:   Failed to build import library for gcc. Linking will fail.(   Rº   Rl   Rm   RT   RU   R[   Ro   R«   R   Rˆ   R   R¬   t   numpy.distutilsR»   t
   DEFAULT_NMt   getnmt   parse_nmt
   output_deft
   DEF_HEADERR‰   t   system(   t   lib_namet   lib_fileR°   R±   R»   R´   Rµ   t   nm_cmdt	   nm_outputt   dlistt   flistR˜   RR   R¶   t   status(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyR¹   ”  s2    "
t   win32s   8.0.50727.42t   80s   9.0.21022.8t   90s   10.0.30319.460t   100t   CRT_ASSEMBLY_VERSIONt   .i   s9   Cannot import msvcrt: using manifest will not be possiblec         C` si   y t  t |  d | ƒ } Wn' t k
 rE t d |  | f ƒ ‚ n Xd } | i | d 6|  d 6| d 6S(   sU   Given a major and minor version of the MSVCR, returns the
    corresponding XML file.i
   s)   Version %d,%d of MSVCRT not supported yetsS  <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC%(maj)d%(min)d.CRT" version="%(fullver)s" processorArchitecture="*" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  </dependency>
</assembly>t   fullverRu   Rv   (   t   _MSVCRVER_TO_FULLVERt   strRq   Rs   (   Ru   Rv   RÐ   t   template(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   msvc_manifest_xmlÛ  s    R{   c         C` sH   | d k r d } n% | d k r* d } n t  d | ƒ ‚ d | |  f S(   sW  Return the rc file used to generate the res file which will be embedded
    as manifest for given manifest file name, of given type ('dll' or
    'exe').

    Parameters
    ----------
    name : str
            name of the manifest file to embed
    type : str {'dll', 'exe'}
            type of the binary which will embed the manifest

    R{   i   t   exei   s   Type %s not supporteds&   #include "winuser.h"
%d RT_MANIFEST %s(   Rs   (   R©   t   typet   rctype(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   manifest_rcû  s    		c         C` su   t  ƒ  } | rq | j d ƒ s* t | ƒ ‚ t | d d !ƒ } | t |  ƒ k sq t d t |  ƒ | f ƒ ‚ qq n  d S(   s6   msver is the ms runtime version used for the MANIFEST.R   i   iÿÿÿÿsK   Discrepancy between linked msvcr (%d) and the one about to be embedded (%d)N(   R   t
   startswitht   AssertionErrorR2   Rs   (   t   msvert   msvcvRu   (    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt!   check_embedded_msvcr_match_linked  s    	c         C` s5   t  j j |  j d g  d ƒ ƒ } t  j j | ƒ d S(   Nt   yot   ci    (   RT   RU   RZ   t   _gen_temp_sourcefileRV   (   t   configRa   (    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   configtest_name#  s    !c         C` s$   t  |  ƒ } |  j j } | | d S(   Ns	   .manifest(   Râ   R   t   exe_extension(   Rá   Rš   t   exext(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   manifest_name'  s    c         C` s   t  |  ƒ } | d S(   Ns   .rc(   Râ   (   Rá   Rš   (    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   rc_name-  s    c         C` s¦   t  ƒ  } | d  k	 r¢ | d k r¢ t | ƒ t | ƒ } t | | d ƒ } t | | ƒ } t t |  ƒ d ƒ } |  j j t |  ƒ ƒ | j	 | ƒ | j
 ƒ  q¢ n  d  S(   Ni   i
   R€   (   t   get_build_msvc_versionR#   RÝ   R2   RÔ   R‰   Rå   t
   temp_filesRA   RŠ   R*   (   Rá   RÛ   t   mat   mit   manxmlt   man(    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   generate_manifest2  s    	
(B   Rg   t
   __future__R    R   R   RT   Rl   R%   R$   t   numpy.distutils.ccompilert   numpyRm   R   R   R¼   t   distutils.cygwinccompilerR   t   distutils.versionR   R   R   t   distutils.unixccompilerR   t   distutils.msvccompilerR   Rç   t   distutils.errorsR	   R
   R   t   numpy.distutils.misc_utilR   R   t   compileRƒ   R†   R   R    R   R|   R   R‘   R¥   Rª   R0   R/   R¸   R¹   RÑ   t   platformt   msvcrtt   hasattrRÎ   R¡   t   majort   minort   restt   ImportErrorRˆ   RÔ   RØ   RÝ   Râ   Rå   Ræ   Rí   (    (    (    s?   /tmp/pip-build-X4mzal/numpy/numpy/distutils/mingw32ccompiler.pyt   <module>	   s^   Á			!	1			2


	 				