
][\S                 @   s  d  Z  d d l Z d d l Z d d l Z d d l m Z e j j e j  Z	 e j j e j
  Z e j j e j  Z e j j e j  Z d e j k r e j j e j d  Z n! e j j e j j e j   Z e j d k r/d e d1 d  j   k r/e j j e j j e e j j   Z n  e j d k rd	 e d2 d  j   k re j j e j j e e j j e j j   Z n  e j d k rd e d3 d  j   k re j j e j j e e j j e j j   Z n  d d   Z e e d d  Z e rle j d k rle j   j d4  rle j j e  Z e j d  rle j j e  Z qln  d d   Z e   Z d Z y e se j  Z n  Wn e! k
 rYn Xd d   Z" d d d d  Z# d d d d d  Z$ d d   Z% d d   Z& d d   Z' d d  d!  Z( e j) d"  Z* e j) d#  Z+ e j) d$  Z, d d% d&  Z- d' d(   Z. d a/ d) d*   Z0 d+ d,   Z1 d- d.   Z2 d/ d0   Z3 d S)5a  Provide access to Python's configuration information.  The specific
configuration variables available depend heavily on the platform and
configuration.  The values may be retrieved using
get_config_var(name), and the list of variables is available via
get_config_vars().keys().  Additional convenience functions are also
available.

Written by:   Fred L. Drake, Jr.
Email:        <fdrake@acm.org>
    N   )DistutilsPlatformErrorZ_PYTHON_PROJECT_BASEntpcbuild   z\pc\v
   z\pcbuild\amd64   c             C   s=   x6 d D]. } t  j j t  j j |  d |   r d Sq Wd S)N
Setup.distSetup.localZModulesTF)r	   r
   )ospathisfilejoin)dfn r   )/usr/lib/python3.4/distutils/sysconfig.py_is_python_source_dir0   s    $r   Z_homepcbuild\amd64c               C   s   t  r t t   St t  S)N)	_sys_homer   project_baser   r   r   r   _python_build;   s    
r    c               C   s   t  j d d  S)zReturn a string containing the major and minor Python version,
    leaving off the patchlevel.  Sample return values could be '1.5'
    or '2.2'.
    N   )sysversionr   r   r   r   get_python_versionM   s    r   c             C   s!  | d k r! |  r t  p t } n  t j d k r t r t p? t } |  rL | St rp t j j t t	 d   } n t j j t	 d  d  } t j j
 |  Sd t   t } t r |  r d d l } | j d  St j j | d	 |  St j d
 k r
t j j | d	  St d t j   d S)a  Return the directory containing installed Python header files.

    If 'plat_specific' is false (the default), this is the path to the
    non-platform-specific header files, i.e. Python.h and so on;
    otherwise, this is the path to platform-specific header files
    (namely pyconfig.h).

    If 'prefix' is supplied, use it instead of sys.base_prefix or
    sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
    NposixZ	AST_H_DIRsrcdirZIncludepythonr   ZplatincludeZincluder   zFI don't know where Python installs its C header files on platform '%s')BASE_EXEC_PREFIXBASE_PREFIXr   namepython_buildr   r   r   r   get_config_varnormpathr   build_flags	sysconfigZget_pathr   )plat_specificprefixbaseZincdirZ
python_dirr'   r   r   r   get_python_incU   s*    r+   c             C   s_  | p t  j j |  d k } | d k r[ | rF |  r= t p@ t } q[ |  rR t pU t } n  t  j d k rt  j j | d d t	    } | r | S| r d t  j
 k r d t  j
 k r d	 t j k r t j t j k r t  j j | d d
 d  St  j j | d  SnT t  j d k rH| r/t  j j | d  St  j j | d d  Sn t d t  j   d S)aS  Return the directory containing the Python library (standard or
    site additions).

    If 'plat_specific' is true, return the directory containing
    platform-specific modules, i.e. any module from a non-pure-Python
    module distribution; otherwise, return the platform-shared library
    directory.  If 'standard_lib' is true, return the directory
    containing standard Python library modules; otherwise, return the
    directory for site-specific modules.

    If 'prefix' is supplied, use it instead of sys.base_prefix or
    sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
    /usr
/usr/localNr   Zlibr   ZPYTHONUSERBASEZVIRTUAL_ENVZreal_prefixZpython3zdist-packageszsite-packagesr   ZLibz?I don't know where Python installs its library on platform '%s')r,   r-   )r   r   r%   r    r!   EXEC_PREFIXPREFIXr"   r   r   environr   __dict__r)   base_prefixr   )r(   standard_libr)   Zis_default_prefixZ	libpythonr   r   r   get_python_lib~   s0    r4   c             C   sK  |  j  d k rGt j d k rS t d  sS d d l } | j t  d t d <qS n  t d d d	 d
 d d d d d d d d  \ } } } } } } } }	 }
 } } } d t j	 k rt j	 d } t j d k r
d t j	 k r
| j
 |  r
| | t |  d  } n  | } n  d t j	 k r2t j	 d } n  d t j	 k rQt j	 d } n  d t j	 k rpt j	 d } n
 | d } d t j	 k r| d t j	 d } n | r| d | } n  d
 t j	 k r| d t j	 d
 } | d t j	 d
 } n% | r| d | } | d | } n  d t j	 k rj| d t j	 d } | d t j	 d } | d t j	 d } n3 | r| d | } | d | } | d | } n  d t j	 k rt j	 d }	 n  d t j	 k r|	 d t j	 d } n |	 d |
 } | d | } |  j d | d | d | d | d | d | d | d |  | |  _ n  d S)zDo any platform-specific customization of a CCompiler instance.

    Mainly needed on Unix, so we can plug in the information that
    varies across Unices and is stored in Python's Makefile.
    ZunixdarwinZCUSTOMIZED_OSX_COMPILERr   NTrueZCCZCXXZOPTCFLAGSZCCSHAREDZLDSHAREDZSHLIB_SUFFIXZARZARFLAGSZCONFIGURE_CPPFLAGSZCONFIGURE_CFLAGSZCONFIGURE_LDFLAGSZCPPz -ELDFLAGS CPPFLAGSZpreprocessorcompilerZcompiler_soZcompiler_cxxZ	linker_soZ
linker_exearchiver)Zcompiler_typer   platformr$   _osx_supportcustomize_compiler_config_varsget_config_varsr   r0   
startswithlenZset_executablesZshared_lib_extension)r;   r>   ZccZcxxZoptZcflagsZccsharedZldsharedZshlib_suffixZarZar_flagsZconfigure_cppflagsZconfigure_cflagsZconfigure_ldflagsZnewccZcppr<   Zcc_cmdr   r   r   r?      sp    3	
	r?   c              C   sd   t  rB t j d k r3 t j j t p' t d  }  qQ t p< t }  n t d d  }  t j j |  d  S)z2Return full pathname of installed pyconfig.h file.r   ZPCr(   r   z
pyconfig.h)r#   r   r"   r   r   r   r   r+   )Zinc_dirr   r   r   get_config_h_filename   s    rD   c              C   s   t  r t j j t p t d  St d d d d  }  d j t   t	  } t
 t j d  rr | d t j j 7} n  t j j |  | d  S)	zAReturn full pathname of installed Makefile from the Python build.ZMakefiler(   r   r3   r   zconfig-{}{}
_multiarchz-%s)r#   r   r   r   r   r   r4   formatr   r&   hasattrr   implementationrE   )Zlib_dirZconfig_filer   r   r   get_makefile_filename  s    rI   c             C   s   | d k r i  } n  t  j d  } t  j d  } x |  j   } | sL Pn  | j |  } | r | j d d  \ } } y t |  } Wn t k
 r Yn X| | | <q6 | j |  } | r6 d | | j d  <q6 q6 | S)zParse a config.h-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    Nz"#define ([A-Z][A-Za-z0-9_]+) (.*)
z&/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/
r      r   )recompilereadlinematchgroupint
ValueError)fpgZ	define_rxZundef_rxlinemnvr   r   r   parse_config_h  s(    	  rX   z"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)z\$\(([A-Za-z][A-Za-z0-9_]*)\)z\${([A-Za-z][A-Za-z0-9_]*)}c             C   s  d d l  m } | |  d d d d d d d d } | d	 k rI i  } n  i  } i  } x | j   } | d	 k rt Pn  t j |  } | rX | j d d
  \ } }	 |	 j   }	 |	 j d d  }
 d |
 k r |	 | | <q y t |	  }	 Wn( t	 k
 r|	 j d d  | | <Yq X|	 | | <qX qX d } x&| rQxt
 |  D]} | | } t j |  pjt j |  } | rC| j d  } d } | | k rt | |  } n | | k rd } n | t j k rt j | } nx | | k rE| j d  r| d d	  | k rd } qSd | | k r.d } qSt | d |  } n d | | <} | rJ| | j   d	  } | d	 | j    | | } d | k r| | | <q@y t |  } Wn" t	 k
 r| j   | | <Yn X| | | <| | =| j d  r@| d d	  | k r@| d d	  } | | k r=| | | <q=q@qJq?| | =q?Wq,W| j   x< | j   D]. \ } }	 t |	 t  ri|	 j   | | <qiqiW| j |  | S)zParse a Makefile-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    r   )TextFileZstrip_commentsr   Zskip_blanksZ
join_lineserrorssurrogateescapeNrJ   z$$r   $r7   r8   r:   TFZPY_r   )zCFLAGSzLDFLAGSzCPPFLAGS)Zdistutils.text_filerY   rM   _variable_rxrN   rO   stripreplacerP   rQ   list_findvar1_rxsearch_findvar2_rxstrr   r0   rB   endstartcloseitems
isinstanceupdate)r   rS   rY   rR   ZdoneZnotdonerT   rU   rV   rW   ZtmpvZrenamed_variablesr"   valuefounditemZafterkr   r   r   parse_makefile;  s    $		
	%		 

ro   c             C   sx   xq t  j |   p t j |   } | rp | j   \ } } |  d |  | j | j d   |  | d  }  q Pq |  S)a  Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
    'string' according to 'vars' (a dictionary mapping variable names to
    values).  Variables not present in 'vars' are silently expanded to the
    empty string.  The variable values in 'vars' should not contain further
    variable expansions; if 'vars' is the output of 'parse_makefile()',
    you're fine.  Returns a variable-expanded version of 's'.
    r   r   N)ra   rb   rc   spangetrO   )svarsrU   Zbegre   r   r   r   expand_makefile_vars  s    7rt   c              C   s'   d d l  m }  i  a t j |   d S)z7Initialize the module as appropriate for POSIX systems.r   )build_time_varsN)Z_sysconfigdataru   r@   rj   )ru   r   r   r   _init_posix  s    rv   c              C   s   i  }  t  d d d d  |  d <t  d d d d  |  d <t d d  |  d <d |  d	 <d
 |  d <t   j d d  |  d <t j j t j j t j	   |  d <|  a
 d S)z+Initialize the module as appropriate for NTr(   r   r3   r   ZLIBDESTZ
BINLIBDESTZ	INCLUDEPYz.pyd
EXT_SUFFIXz.exeZEXE.r   ZVERSIONZBINDIRN)r4   r+   r   r_   r   r   dirnameabspathr   
executabler@   )rS   r   r   r   _init_nt  s    

%r|   c              G   s  t  d k rt   j d t j  } | r5 |   n i  a  t t  d <t t  d <t  j d  } | d k	 rw | t  d <n  t  j d t  } t j d k r t r t j	 j
 t    } t j	 j | |  } q t j	 j
 t    } n  t j	 j t j	 j |   t  d <t r~t j d k r~t } t j	 j t  d  r~| t j   k r~t j	 j | t  d  } t j	 j |  t  d <q~n  t j d	 k rd
 d l } | j t   qn  |  rg  } x$ |  D] } | j t  j |   qW| St  Sd S)a  With no arguments, return a dictionary of all configuration
    variables relevant for the current platform.  Generally this includes
    everything needed to build extensions and install both pure modules and
    extensions.  On Unix, this means every variable defined in Python's
    installed Makefile; on Windows it's a much smaller set.

    With arguments, return a list of values that result from looking up
    each argument in the configuration variable dictionary.
    NZ_init_r)   exec_prefixrw   SOr   r   r5   r   )r@   globalsrq   r   r"   r/   r.   r   r#   r   ry   rI   r   rz   r%   isabsgetcwdr   r=   r>   Zcustomize_config_varsappend)argsfuncr~   r   r*   r>   Zvalsr"   r   r   r   rA     s@    


"rA   c             C   s>   |  d k r. d d l  } | j d t d  n  t   j |   S)zReturn the value of a single variable using the dictionary
    returned by 'get_config_vars()'.  Equivalent to
    get_config_vars().get(name)
    r~   r   Nz SO is deprecated, use EXT_SUFFIXrJ   )warningswarnDeprecationWarningrA   rq   )r"   r   r   r   r   r$   &  s    r$   iii)r   r   )4__doc__r   rK   r   rZ   r   r   r%   r)   r/   r}   r.   r2   r!   base_exec_prefixr    r0   rz   r   ry   r{   r"   lowerr   pardirr   getattrr   endswithr   r#   r&   abiflagsAttributeErrorr   r+   r4   r?   rD   rI   rX   rL   r]   ra   rc   ro   rt   r@   rv   r|   rA   r$   r   r   r   r   <module>
   sf   !+*++	).Tj	J