
Ee]c           @` 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  m! Z! m" Z" d   Z# e# e j$ _% 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  Z0 d   Z1 d   Z2 d   Z3 d   Z4 i  Z5 e j6 d k rxyx d d l7 Z7 d e5 d <d e5 d <d  e5 d! <e8 e7 d"  rSe7 j9 j: d# d$  \ Z; Z< Z= e7 j9 e5 e; e< <[; [< [= n  Wqxe> k
 rte j? d%  qxXn  d&   Z@ d' d(  ZA d)   ZB d*   ZC d+   ZD d,   ZE d-   ZF 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   msvc_runtime_versiont   msvc_runtime_majort   get_build_architecturec          C` s    t    }  |  d k r g  S|  g S(   sB   Replacement for outdated version of get_msvcr from cygwinccompilerN(   R   t   None(   t   msvcr(    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt   get_msvcr_replacement*   s    	s   \[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` se  t  j j j |  | | |  |  j d  k r t j d d g d t d t j	 } | j
 j   } | j
 j   t 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 |	 r0|  j d  n  t   }
 |
 rV|  j d d |
  n  t   d k r|  j d k  r|  j d d d d d d d d  qU|  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  r3|  j d d# d d$ d d! d d%  n" |  j d d& d d' d d( d d)  d g |  _ d  S(*   Nt   gccs   -dumpversiont   shellt   stdouts
   (\d+\.\d+)i   s   2.91.57s   --entry _DllMain@12t    t   dllwraps   g++t   debugt   NPY_MINGW_USE_CUSTOM_MSVCRt   __MSVCRT_VERSION__s   0x%04it   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_versionR   t
   subprocesst   Popent   Truet   PIPER   t   readt   closet   ret   searchR   t   groupt
   linker_dllt   linkert   build_import_libraryt   build_msvcr_libraryt   define_macroR   R   t   set_executablest   compiler_cxx(   t   selft   verboset   dry_runt   forcet   pt
   out_stringt   resultt   entry_pointt   msvcr_successt   msvcr_dbg_successt   msvcr_version(    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyR%   ?   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(   R7   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?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyRC      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   basenameRB   t   joint   obj_extension(	   R7   t   source_filenamest	   strip_dirRI   t	   obj_namest   src_namet   baset   extt   drv(    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt   object_filenames   s(     	$N(   t   __name__t
   __module__t   __doc__t   compiler_typeR%   R   RC   Re   (    (    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyR   8   s   rc          C` s  t  j g }  t t  d  r@ t  j t  j k r@ |  j t  j  n4 t t  d  rt t  j t  j k rt |  j t  j  n  d d d g } g  } x; |  D]3 } x* | D]" } | j t j j | |   q Wq Wd t j	 k r | j t j j t j	 d d   n  t
 t  j d   \ } } d	 g } xh | D]` } | | | f }	 t d
 |	  x9 | D]1 } t j j | |	  }
 t j j |
  rP|
 SqPWq%Wt d |	 | f   d  S(   Nt   base_prefixt   real_prefixR   t   libt   bint
   SYSTEMROOTt   System32i   s   python%d%d.dlls   Looking for %ss   %s not found in %s(   t   syst   prefixt   hasattrRj   RB   Rk   RU   RV   R\   t   environt   tuplet   version_infot   printt   existst
   ValueError(   t   stemst   sub_dirst   lib_dirst   stemt   foldert   major_versiont   minor_versiont   patternst   patt   dllnamet   dll(    (    s?   lib/python2.7/site-packages/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?   lib/python2.7/site-packages/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   decodeRx   t   _TABLERB   t   intR/   t   stripR   t   warnt   opent   writeRU   RV   R[   R,   (	   R   t   dfilet   dumpt   it   symst   jt   mt   dt   s(    (    s?   lib/python2.7/site-packages/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 j d d  d  } t  j j |  s: d  SxK t  j |  D]: \ } } } |  | k rJ   | k rJ t  j j | |   SqJ Wd  S(   Nt   WINDIRs
   C:\WINDOWSt   winsxs(   RU   RV   R\   Rs   t   getRw   R   t   walk(   t   dll_namet   winsxs_patht   roott   dirst   files(   t   arch(    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt   _find_dll_in_winsxsI  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   ;(	   Rp   Rq   RU   Rs   t   splitRV   R\   Rw   t   abspath(   R   RV   t   filepath(    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt   _find_dll_in_pathT  s    '(   R   (   R   R   R   (    (   R   s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt   find_dllD  s
    
	c         C` sq  t  j d k r t St   } | d  k r9 t j d  t S| d k  rV t j d  t St   } |  rr | 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   nts?   Skip building import library: Runtime is not compiled with MSVCiP   s=   Skip building msvcr library: custom functionality not presentR   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(   RU   t   namet   FalseR   R   R   R   R   RV   R\   Rp   Rq   t   isfileR)   R   R   t   infoR   R'   t   callt   remove(   R   t	   msvcr_vert
   msvcr_namet   out_namet   out_filet   msvcr_dll_namet   dll_filet   def_namet   def_filet   cmdt   retcode(    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyR3   ^  sB    		
	
	
	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(   RU   R   R   t   _build_import_library_amd64t   _build_import_library_x86Rx   (   R   (    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyR2     s    	c          C` sK  t  t j d   \ }  } d d d g } t j g } t t d  rh t j t j k rh | j t j  n4 t t d  r t j t j k r | j t j  n  d d g } g  } x_ | D]W } | |  | f } x> | D]6 } x- | D]% }	 | j t j	 j
 | |	 |   q Wq Wq Wx* | D]" }
 t j	 j |
  rt |
 f SqWt | d	 f S(
   sA   Check if an import library for the Python runtime already exists.i   s   libpython%d%d.as   libpython%d%d.dll.as   libpython%d.%d.dll.aRj   Rk   R   Rl   i    (   Rt   Rp   Ru   Rq   Rr   Rj   RB   Rk   RU   RV   R\   R   R)   R   (   R~   R   R   Ry   Rz   t
   candidatesR   t   filenamet   stem_dirR}   t   fullname(    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt   _check_for_import_lib  s(    	!!+c          C` s   t    \ }  } |  r) t j d |  d  St   } t j d | | f  d t t j d   } t j	 j
 t j d |  } t | |  d d | d | g } t j |  d  S(	   Ns)   Skip building import library: "%s" existss4   Building import library (arch=AMD64): "%s" (from %s)s   python%d%d.defi   R   R   s   -ds   -l(   R   R   R   R   R   Rt   Rp   Ru   RU   RV   R\   Rq   R   R'   R(   (   t
   out_existsR   R   R   R   R   (    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyR     s    		c          C` s  t    \ }  } |  r) t j d |  d Sd t t j d   } t j j t j	 d |  } t j j
 |  s t t d  r t j j t j d |  } n3 t t d  r t j j t j d |  } n d } t j j
 |  r | } q t j d	 |  d Sn  t 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   t   } | | | f } d | } t j |  } | rt j d  n  d S(   s;    Build the import libraries for Mingw32-gcc on Windows
    s)   Skip building import library: "%s" existsNs   python%d%d.libi   R   Rj   Rk   R   s+   Cannot build import library: "%s" not founds(   Building import library (ARCH=x86): "%s"i    (   t   lib2defs   python%d%d.defs   %s %sR   s3   dlltool --dllname "%s" --def "%s" --output-lib "%s"s:   Failed to build import library for gcc. Linking will fail.(   R   R   R   Rt   Rp   Ru   RU   RV   R\   Rq   R   Rr   Rj   Rk   R   R   t   numpy.distutilsR   t
   DEFAULT_NMt   getnmt   parse_nmt
   output_deft
   DEF_HEADERR   R   t   system(   R   R   t   lib_namet   lib_filet   base_libR   R   R   t   nm_cmdt	   nm_outputt   dlistt   flistR   RS   R   t   status(    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyR     s>    	"	
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   fullvert   majt   min(   t   _MSVCRVER_TO_FULLVERt   strt   KeyErrorRx   (   R   R   R   t   template(    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt   msvc_manifest_xml1  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(   Rx   (   R   t   typet   rctype(    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt   manifest_rcQ  s    		c         C` sG   t    } | rC | t |   k sC t d t |   | f   qC n  d S(   s6   msver is the ms runtime version used for the MANIFEST.sK   Discrepancy between linked msvcr (%d) and the one about to be embedded (%d)N(   R   R   Rx   (   t   msverR   (    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt!   check_embedded_msvcr_match_linkedi  s    	c         C` s5   t  j j |  j d g  d   } t  j j |  d S(   Nt   yot   ci    (   RU   RV   R[   t   _gen_temp_sourcefileRW   (   t   configRb   (    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt   configtest_nameu  s    !c         C` s$   t  |   } |  j j } | | d S(   Ns	   .manifest(   R   R   t   exe_extension(   R   R   t   exext(    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt   manifest_namey  s    c         C` s   t  |   } | d S(   Ns   .rc(   R   (   R   R   (    (    s?   lib/python2.7/site-packages/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   R   R   R   R   t
   temp_filesRB   R   R,   (   R   R   t   mat   mit   manxmlt   man(    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt   generate_manifest  s    	
(G   Rh   t
   __future__R    R   R   RU   Rp   R'   R-   t   numpy.distutils.ccompilert   numpyRu   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   R   R   R   R#   t	   get_msvcrt   compileR   R   R$   R   R   R   R   R   R   R3   R2   R   R   R   R   t   platformt   msvcrtRr   R   R   t   majort   minort   restt   ImportErrorR   R   R   R   R   R   R   R   (    (    (    s?   lib/python2.7/site-packages/numpy/distutils/mingw32ccompiler.pyt   <module>	   sd   "		&		!	;		$		?


	 				