
][\W@                 @   sg  d  Z  d d l Z d d l Z d d l Z d d l m Z m Z m Z d d l 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 m Z d d l m Z d d	 l m Z d d
 l m Z d d   Z Gd d   d e  Z Gd d   d e  Z d Z d Z d Z  d d   Z! e j" d  Z# d d   Z$ d d   Z% d d   Z& d S)a  distutils.cygwinccompiler

Provides the CygwinCCompiler class, a subclass of UnixCCompiler that
handles the Cygwin port of the GNU C compiler to Windows.  It also contains
the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
cygwin in no-cygwin mode).
    N)PopenPIPEcheck_output)gen_preprocess_optionsgen_lib_options)UnixCCompiler)
write_file)DistutilsExecErrorCCompilerErrorCompileErrorUnknownFileError)log)LooseVersion)find_executablec              C   s   t  j j d  }  |  d k r t  j |  d |  d  } | d k rL d g S| d k r_ d g S| d	 k rr d
 g S| d k r d g S| d k r d g St d |   n  d S)zaInclude the appropriate MSVC runtime library if Python was built
    with MSVC 7.0 or later.
    zMSC v.      
   Z1300Zmsvcr70Z1310Zmsvcr71Z1400Zmsvcr80Z1500Zmsvcr90Z1600Zmsvcr100zUnknown MS Compiler version %s N)sysversionfind
ValueError)Zmsc_posZmsc_ver r   //usr/lib/python3.4/distutils/cygwinccompiler.py	get_msvcr?   s    r   c               @   s   e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 d Z
 d	 d	 d	 d
 d  Z d d   Z d d d d d d	 d d d d d d 
 Z d	 d d d  Z d S)CygwinCCompilerz? Handles the Cygwin port of the GNU C compiler to Windows.
    cygwinz.oz.az.dllzlib%s%sz%s%sz.exer   c             C   sS  t  j |  | | |  t   \ } } |  j d | | f  | t k	 r\ |  j d |  n  t   \ |  _ |  _ |  _	 |  j |  j
 d |  j |  j |  j	 f  |  j d k r d |  _ n	 d |  _ |  j d k r d } n d	 } |  j d
 d d d d d d d d d |  j | f  |  j d k rCd g |  _ |  j d  n t   |  _ d  S)Nz%Python's GCC status: %s (details: %s)zPython's pyconfig.h doesn't seem to support your compiler. Reason: %s. Compiling may fail because of undefined preprocessor macros.z: gcc %s, ld %s, dllwrap %s
z2.10.90gccdllwrapz2.13z-sharedz-mdll -staticcompilerzgcc -mcygwin -O -Wallcompiler_sozgcc -mcygwin -mdll -O -Wallcompiler_cxxzg++ -mcygwin -O -Wall
linker_exezgcc -mcygwin	linker_soz%s -mcygwin %sz2.91.57Zmsvcrtz,Consider upgrading to a newer version of gcc)r   __init__check_config_hZdebug_printCONFIG_H_OKwarnget_versionsgcc_version
ld_versionZdllwrap_versioncompiler_type
linker_dllset_executablesdll_librariesr   )selfverbosedry_runforceZstatusZdetailsshared_optionr   r   r   r$   d   s<    			
zCygwinCCompiler.__init__c             C   s   | d k s | d k ro y  |  j  d d | d | g  Wq t k
 rk } z t |   WYd d } ~ Xq Xn] y) |  j  |  j | | d | g |  Wn1 t k
 r } z t |   WYd d } ~ Xn Xd S)z:Compiles the source by spawning GCC and windres if needed.z.rcz.resZwindresz-iz-oN)Zspawnr	   r   r    )r/   objsrcextZcc_argsextra_postargsZpp_optsmsgr   r   r   _compile   s     "zCygwinCCompiler._compileNc             C   s  t  j  |
 p g   }
 t  j  | p$ g   } t  j  | p9 g   } | j |  j  | d k	 r| |  j k sy |  j d k rt j j | d  } t j j t j j	 |   \ } } t j j
 | | d  } t j j
 | d | d  } d t j j	 |  d g } x | D] } | j |  qW|  j t | | f d	 |  |  j d
 k rx|
 j d | g  |
 j d | g  q| j |  n  |	 s|
 j d  n  t j |  | | | | | | | d |	 |
 | | |  d S)zLink the objects.Nr   r   z.defZlibz.az
LIBRARY %sZEXPORTSz
writing %sr   z--output-libz--defz-s)copyextendr.   Z
EXECUTABLEr,   ospathdirnamesplitextbasenamejoinappendZexecuter   r   link)r/   Ztarget_descZobjectsZoutput_filename
output_dirZ	librariesZlibrary_dirsZruntime_library_dirsZexport_symbolsdebugZextra_preargsr7   Z
build_tempZtarget_langZtemp_dirZdll_nameZdll_extensionZdef_fileZlib_filecontentsZsymr   r   r   rC      s:    				zCygwinCCompiler.link c             C   s   | d k r d } n  g  } x | D] } t  j j t  j j |   \ } } | |  j d d g k r~ t d | | f   n  | r t  j j |  } n  | d k r | j t  j j | | | |  j	   q" | j t  j j | | |  j	   q" W| S)z#Adds supports for rc and res files.NrG   .rc.resz"unknown file type '%s' (from '%s'))rI   rH   )
r<   r=   r?   normcaseZsrc_extensionsr   r@   rB   rA   obj_extension)r/   Zsource_filenamesZ	strip_dirrD   Z	obj_namesZsrc_namebaser6   r   r   r   object_filenames   s     	$z CygwinCCompiler.object_filenames)__name__
__module____qualname____doc__r+   rK   Zstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZexe_extensionr$   r9   rC   rM   r   r   r   r   r   Y   s   ;		Kr   c               @   s1   e  Z d  Z d Z d Z d d d d d  Z d S)Mingw32CCompilerz@ Handles the Mingw32 port of the GNU C compiler to Windows.
    Zmingw32r   c             C   s   t  j |  | | |  |  j d k r. d } n d } |  j d k rL d } n d } t   rj t d   n  |  j d d	 d
 d d d d d d d |  j | | f  g  |  _ t	   |  _ d  S)Nz2.13z-sharedz-mdll -staticz2.91.57z--entry _DllMain@12rG   z1Cygwin gcc cannot be used with --compiler=mingw32r   zgcc -O -Wallr    zgcc -mdll -O -Wallr!   zg++ -O -Wallr"   r   r#   z%s %s %s)
r   r$   r*   r)   is_cygwingccr
   r-   r,   r.   r   )r/   r0   r1   r2   r3   Zentry_pointr   r   r   r$     s&    					zMingw32CCompiler.__init__N)rN   rO   rP   rQ   r+   r$   r   r   r   r   rR     s   rR   okznot okZ	uncertainc              C   s   d d l  m }  d t j k r) t d f S|  j   } yP t |  } z2 d | j   k rg t d | f St d | f SWd | j	   XWn< t
 k
 r } z t d	 | | j f f SWYd d } ~ Xn Xd S)
aw  Check if the current Python installation appears amenable to building
    extensions with GCC.

    Returns a tuple (status, details), where 'status' is one of the following
    constants:

    - CONFIG_H_OK: all is well, go ahead and compile
    - CONFIG_H_NOTOK: doesn't look good
    - CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h

    'details' is a human-readable string explaining the situation.

    Note there are two ways to conclude "OK": either 'sys.version' contains
    the string "GCC" (implying that this Python was built with GCC), or the
    installed "pyconfig.h" contains the string "__GNUC__".
    r   )	sysconfigZGCCzsys.version mentions 'GCC'Z__GNUC__z'%s' mentions '__GNUC__'z '%s' does not mention '__GNUC__'Nzcouldn't read '%s': %s)	distutilsrU   r   r   r&   Zget_config_h_filenameopenreadCONFIG_H_NOTOKcloseOSErrorCONFIG_H_UNCERTAINstrerror)rU   fnZconfig_hexcr   r   r   r%   H  s    
r%   s   (\d+\.\d+(\.\d+)*)c             C   s   |  j    d } t |  d k r& d St |  d d d t j } z | j   } Wd | j   Xt j |  } | d k r~ d St	 | j
 d  j    S)zFind the version of an executable by running `cmd` in the shell.

    If the command is not found, or the output does not match
    `RE_VERSION`, returns None.
    r   NshellTstdoutr   )splitr   r   r   ra   rX   rZ   
RE_VERSIONsearchr   groupdecode)cmd
executableout
out_stringresultr   r   r   _find_exe_versionu  s    rl   c              C   s&   d d d g }  t  d d   |  D  S)zg Try to find out the versions of gcc, ld and dllwrap.

    If not possible it returns None for it.
    zgcc -dumpversionzld -vzdllwrap --versionc             S   s   g  |  ] } t  |   q Sr   )rl   ).0rg   r   r   r   
<listcomp>  s   	 z get_versions.<locals>.<listcomp>)tuple)Zcommandsr   r   r   r(     s    r(   c              C   s%   t  d d g  }  |  j   j d  S)z>Try to determine if the gcc that would be used is from cygwin.r   z-dumpmachines   cygwin)r   stripendswith)rj   r   r   r   rS     s    rS   )'rQ   r<   r   r:   
subprocessr   r   r   reZdistutils.ccompilerr   r   Zdistutils.unixccompilerr   Zdistutils.file_utilr   Zdistutils.errorsr	   r
   r   r   rV   r   Zdistutils.versionr   Zdistutils.spawnr   r   r   rR   r&   rY   r\   r%   compilerc   rl   r(   rS   r   r   r   r   <module>   s.   )"1+