
8	Pc           @   s   d  Z  d Z d d l Z d d l 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 d d l m Z m Z m Z m Z d d	 l m Z d
   Z d e f d     YZ d S(   s9  distutils.unixccompiler

Contains the UnixCCompiler class, a subclass of CCompiler that handles
the "typical" Unix-style command-line C compiler:
  * macros defined with -Dname[=value]
  * macros undefined with -Uname
  * include search directories specified with -Idir
  * libraries specified with -lllib
  * library search directories specified with -Ldir
  * compile handled by 'cc' (or similar) executable with -c option:
    compiles .c to .o
  * link static library handled by 'ar' command (possibly with 'ranlib')
  * link shared library handled by 'cc -shared'
s   $Id$iN(   t
   StringTypet   NoneType(   t	   sysconfig(   t   newer(   t	   CCompilert   gen_preprocess_optionst   gen_lib_options(   t   DistutilsExecErrort   CompileErrort   LibErrort	   LinkError(   t   logc   	      C   s  d } } t  |   }  t j   d } t | j d  d  } | d k  rX t } } n d | k } d | k } | s d t j k r x< y! |  j d  } |  | | d 5Wq t k
 r Pq Xq n  d t j k r | r |  t j d j   }  n  | r2y! |  j d  } |  | | d 5Wq2t k
 r.q2Xn  d } d | k rd| j d  } | | d } n, d |  k r|  j d  } |  | d } n  | rt j
 j |  rt j d	 |  t j d
  n  |  S(   se  
    This function will strip '-isysroot PATH' and '-arch ARCH' from the
    compile flags if the user has specified one them in extra_compile_flags.

    This is needed because '-arch ARCH' adds another architecture to the
    build, without a way to remove an architecture. Furthermore GCC will
    barf if multiple '-isysroot' arguments are present.
    i    i   t   .i   s   -archs	   -isysroott	   ARCHFLAGSi   s4   Compiling with an SDK that doesn't seem to exist: %ss$   Please check your Xcode installationN(   t   listt   ost   unamet   intt   splitt   Truet   environt   indext
   ValueErrort   Nonet   patht   isdirR   t   warn(	   t   compiler_sot   cc_argst	   stripArcht   stripSysroott   kernel_versiont   major_versionR   t   sysroott   idx(    (    s-   /usr/lib/python2.7/distutils/unixccompiler.pyt   _darwin_compiler_fixup,   sF    	
	t   UnixCCompilerc           B   sg  e  Z d  Z i d& d 6d g d 6d g d 6d g d 6d d g d 6d g d 6d	 d
 g d 6d& d 6Z e j d  d k r d g e d <n  d d d d d d g Z d Z d Z	 d Z
 d Z d Z Z Z e j d k r d Z n  d& d& d& d& d& d  Z d   Z d& d d& d  Z d& d& d& d& d& d d& d& d& d& d  
 Z d!   Z d"   Z d#   Z d$   Z d d%  Z RS('   t   unixt   preprocessort   cct   compilerR   t   compiler_cxxs   -sharedt	   linker_sot
   linker_exet   ars   -crt   archivert   ranlibi   t   darwins   .cs   .Cs   .ccs   .cxxs   .cpps   .ms   .os   .as   .sos   .dylibs   lib%s%st   cygwins   .exec         C   s	  |  j  d  | |  \ } } } t | |  } |  j | }	 | rV |	 j d | g  n  | ri | |	 d *n  | r |	 j |  n  |	 j |  |  j s | d  k s t | |  r| r |  j t	 j
 j |   n  y |  j |	  Wqt k
 r}
 t |
  qXn  d  S(   Ns   -oi    (   t   _fix_compile_argsR   R   R&   t   extendt   appendt   forceR   t   mkpathR   R   t   dirnamet   spawnR   R   (   t   selft   sourcet   output_filet   macrost   include_dirst   extra_preargst   extra_postargst   ignoret   pp_optst   pp_argst   msg(    (    s-   /usr/lib/python2.7/distutils/unixccompiler.pyt
   preprocess   s"    $c   	      C   sw   |  j  } t j d k r. t | | |  } n  y& |  j | | | d | g |  Wn t k
 rr } t |  n Xd  S(   NR/   s   -o(   R   t   syst   platformR#   R7   R   R   (	   R8   t   objt   srct   extR   R>   R@   R   RB   (    (    s-   /usr/lib/python2.7/distutils/unixccompiler.pyt   _compile   s    	i    c         C   s   |  j  | |  \ } } |  j | d | } |  j | |  r |  j t j j |   |  j |  j | g | |  j	  |  j
 r y |  j |  j
 | g  Wq t k
 r } t |  q Xq n t j d |  d  S(   Nt
   output_dirs   skipping %s (up-to-date)(   t   _fix_object_argst   library_filenamet
   _need_linkR5   R   R   R6   R7   R-   t   objectsR.   R   R	   R   t   debug(   R8   RN   t   output_libnameRJ   RO   t   target_langt   output_filenameRB   (    (    s-   /usr/lib/python2.7/distutils/unixccompiler.pyt   create_static_lib   s    	c         C   si  |  j  | |  \ } } |  j | | |  \ } } } g  | D] } | d k r= | ^ q= } g  | D] } | d k rb | ^ qb } t |  | | |  } t |  t t f k r t d  n  | d  k	 r t j	 j
 | |  } n  |  j | |  rU| |  j | d | g } |	 r d g | d *n  |
 r3|
 | d *n  | rI| j |  n  |  j t j	 j |   y | t j k r|  j } n
 |  j } | d	 k r |  j r d } t j	 j | d  d
 k rd } x! d | | k r| d } qWn  |  j | | | <n  t j d k r!t | |  } n  |  j | |  Wqet k
 rQ} t |  qeXn t j d |  d  S(   Ns   /libs   /lib64s   /usr/libs
   /usr/lib64s%   'output_dir' must be a string or Nones   -os   -gi    s   c++t   envi   t   =R/   s   skipping %s (up-to-date)(   s   /libs   /lib64s   /usr/libs
   /usr/lib64(   s   /libs   /lib64s   /usr/libs
   /usr/lib64(   RK   t   _fix_lib_argsR   t   typeR    R   t	   TypeErrorR   R   R   t   joinRM   RN   R2   R5   R6   R   t
   EXECUTABLER+   R*   R)   t   basenameRD   RE   R#   R7   R   R
   R   RO   (   R8   t   target_descRN   RR   RJ   t	   librariest   library_dirst   runtime_library_dirst   export_symbolsRO   R=   R>   t
   build_tempRQ   t   dirt   lib_optst   ld_argst   linkert   iRB   (    (    s-   /usr/lib/python2.7/distutils/unixccompiler.pyt   link   sL    	
c         C   s   d | S(   Ns   -L(    (   R8   Rb   (    (    s-   /usr/lib/python2.7/distutils/unixccompiler.pyt   library_dir_option  s    c         C   s   d | k p d | k S(   Nt   gccs   g++(    (   R8   t   compiler_name(    (    s-   /usr/lib/python2.7/distutils/unixccompiler.pyt   _is_gcc  s    c         C   s   t  j j t j d   } t j d  d k r6 d | St j d  d k rt |  j |  rf d d | g Sd d | g St j d	  d
 k s t j d  d k r d | g S|  j |  r d | Sd | Sd  S(   Nt   CCi   R/   s   -Li   s   hp-uxs   -Wl,+ss   +si   t   irix646t   osf1V5s   -rpaths   -Wl,-Rs   -R(   R   R   R[   R   t   get_config_varRD   RE   Rk   (   R8   Rb   R(   (    (    s-   /usr/lib/python2.7/distutils/unixccompiler.pyt   runtime_library_dir_option  s    &
c         C   s   d | S(   Ns   -l(    (   R8   t   lib(    (    s-   /usr/lib/python2.7/distutils/unixccompiler.pyt   library_option1  s    c         C   s  |  j  | d d } |  j  | d d } |  j  | d d } t j d k r t j d  } t j d |  } | d  k r d }	 q | j d	  }	 n  x#| D]}
 t	 j
 j |
 |  } t	 j
 j |
 |  } t	 j
 j |
 |  } t j d k rv|
 j d
  s|
 j d  rv|
 j d  rvt	 j
 j |	 |
 d	 |  } t	 j
 j |	 |
 d	 |  } t	 j
 j |	 |
 d	 |  } n  t	 j
 j |  r| St	 j
 j |  r| St	 j
 j |  r | Sq Wd  S(   Nt   lib_typet   sharedt   dylibt   staticR/   t   CFLAGSs   -isysroot\s+(\S+)t   /i   s   /System/s   /usr/s   /usr/local/(   RL   RD   RE   R   Ro   t   ret   searchR   t   groupR   R   RY   t
   startswitht   exists(   R8   t   dirsRq   RO   t   shared_ft   dylib_ft   static_ft   cflagst   mR!   Rb   Rt   Ru   Rv   (    (    s-   /usr/lib/python2.7/distutils/unixccompiler.pyt   find_library_file4  s4    	N(   t   __name__t
   __module__t   compiler_typeR   t   executablesRD   RE   t   src_extensionst   obj_extensiont   static_lib_extensiont   shared_lib_extensiont   dylib_lib_extensiont   static_lib_formatt   shared_lib_formatt   dylib_lib_formatt   exe_extensionRC   RI   RS   Rg   Rh   Rk   Rp   Rr   R   (    (    (    s-   /usr/lib/python2.7/distutils/unixccompiler.pyR$   k   s@   





				;				(   t   __doc__t   __revision__R   RD   Ry   t   typesR    R   t	   distutilsR   t   distutils.dep_utilR   t   distutils.ccompilerR   R   R   t   distutils.errorsR   R   R	   R
   R   R#   R$   (    (    (    s-   /usr/lib/python2.7/distutils/unixccompiler.pyt   <module>   s   $"	?