
(°hh9  ã               @   sÍ   d  Z  d d l Z d d l Z d d l 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 e j d k r³ d d l Z Gd	 d
 „  d
 e	 ƒ Z d S)a9  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'
é    N)Ú	sysconfig)Únewer)Ú	CCompilerÚgen_preprocess_optionsÚgen_lib_options)ÚDistutilsExecErrorÚCompileErrorÚLibErrorÚ	LinkError)ÚlogÚdarwinc               @   sŽ  e  Z d  Z d Z d d d d g d d g d d g d d d	 g d
 d g d d d g d d i Z e j d d … d k r† d g e d <d d d d d d g Z d Z d Z	 d Z
 d Z d Z d Z Z Z e Z e j d k rå d Z d d d d d d d  „ Z d! d" „  Z d d# d d$ d% „ Z d d d d d d# d d d d d& d' „
 Z d( d) „  Z d* d+ „  Z d, d- „  Z d. d/ „  Z d# d0 d1 „ Z d S)2ÚUnixCCompilerÚunixÚpreprocessorNÚcompilerÚccÚcompiler_soÚcompiler_cxxÚ	linker_soz-sharedÚ
linker_exeÚarchiverÚarz-crÚranlibé   r   z.cz.Cz.ccz.cxxz.cppz.mz.oz.az.soz.dylibz.tbdzlib%s%sÚcygwinz.exec             C   s  |  j  d  | | ƒ } | \ } } } t | | ƒ }	 |  j |	 }
 | rY |
 j d | g ƒ | ro | |
 d  d … <| r‚ |
 j | ƒ |
 j | ƒ |  j s³ | d  k s³ t | | ƒ r| rÒ |  j t j	 j
 | ƒ ƒ y |  j |
 ƒ Wn1 t k
 r} z t | ƒ ‚ WYd  d  } ~ Xn Xd  S)Nz-or   )Z_fix_compile_argsr   r   ÚextendÚappendÚforcer   ÚmkpathÚosÚpathÚdirnameÚspawnr   r   )ÚselfÚsourceZoutput_fileÚmacrosÚinclude_dirsÚextra_preargsÚextra_postargsÚ
fixed_argsÚignoreÚpp_optsZpp_argsÚmsg© r-   úI/tmp/pip-build-kmztzv_d/setuptools/setuptools/_distutils/unixccompiler.pyÚ
preprocessU   s$    $zUnixCCompiler.preprocessc       	      C   sŒ   |  j  } t j d k r. t j | | | ƒ } y& |  j | | | d | g | ƒ Wn1 t k
 r‡ } z t | ƒ ‚ WYd  d  } ~ Xn Xd  S)Nr   z-o)r   ÚsysÚplatformÚ_osx_supportÚcompiler_fixupr"   r   r   )	r#   ÚobjÚsrcÚextZcc_argsr(   r+   r   r,   r-   r-   r.   Ú_compileo   s    		zUnixCCompiler._compiler   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Ñ } z t | ƒ ‚ WYd  d  } ~ Xqå Xn t j d | ƒ d  S)NÚ
output_dirzskipping %s (up-to-date))Ú_fix_object_argsÚlibrary_filenameÚ
_need_linkr   r   r    r!   r"   r   Úobjectsr   r   r	   r   Údebug)r#   r<   Zoutput_libnamer8   r=   Útarget_langÚoutput_filenamer,   r-   r-   r.   Úcreate_static_libz   s    	"zUnixCCompiler.create_static_libc             C   sx  |  j  | | ƒ \ } } |  j | | | ƒ } | \ } } } t |  | | | ƒ } t | t t d  ƒ f ƒ sx t d ƒ ‚ | d  k	 r™ t j j	 | | ƒ } |  j
 | | ƒ rd| |  j | d | g } |	 rß d g | d  d … <|
 rõ |
 | d  d … <| r| j | ƒ |  j t j j | ƒ ƒ y| t j k rI|  j d  d  … } n |  j d  d  … } | d k rú|  j rúd } t j j | d ƒ d k rºd } x d | | k r¹| d 7} qœWt j j | | ƒ d	 k rßd } n d } |  j | | | | <t j d
 k rt j | | ƒ } |  j | | ƒ Wqtt k
 r`} z t | ƒ ‚ WYd  d  } ~ XqtXn t j d | ƒ d  S)Nz%'output_dir' must be a string or Nonez-oz-gr   zc++Úenvé   ú=Z	ld_so_aixr   zskipping %s (up-to-date))r9   Z_fix_lib_argsr   Ú
isinstanceÚstrÚtypeÚ	TypeErrorr   r    Újoinr;   r<   r   r   r!   r   Z
EXECUTABLEr   r   r   Úbasenamer0   r1   r2   r3   r"   r   r
   r   r=   )r#   Ztarget_descr<   r?   r8   Ú	librariesÚlibrary_dirsÚruntime_library_dirsÚexport_symbolsr=   r'   r(   Ú
build_tempr>   r)   Zlib_optsZld_argsZlinkerÚiÚoffsetr,   r-   r-   r.   Úlink”   sN    			"zUnixCCompiler.linkc             C   s   d | S)Nz-Lr-   )r#   Údirr-   r-   r.   Úlibrary_dir_optionÖ   s    z UnixCCompiler.library_dir_optionc             C   s   d | k p d | k S)NZgcczg++r-   )r#   Zcompiler_namer-   r-   r.   Ú_is_gccÙ   s    zUnixCCompiler._is_gccc             C   sä   t  j j t j d ƒ ƒ } t j d  d … d k r< d | St j d  d … d k r] d | St j d  d … d	 k r¡ |  j | ƒ r“ d
 d | g Sd d | g S|  j | ƒ rØ t j d ƒ d k rÍ d | Sd | Sn d | Sd  S)NÚCCr   r   z-Lé   Zfreebsdz-Wl,-rpath=é   zhp-uxz-Wl,+sz+sÚGNULDÚyesz-Wl,--enable-new-dtags,-Rz-Wl,-Rz-R)r   r    rI   r   Úget_config_varr0   r1   rT   )r#   rR   r   r-   r-   r.   Úruntime_library_dir_optionÜ   s    z(UnixCCompiler.runtime_library_dir_optionc             C   s   d | S)Nz-lr-   )r#   Úlibr-   r-   r.   Úlibrary_option  s    zUnixCCompiler.library_optionc             C   s.  |  j  | d d ƒ} |  j  | d d ƒ} |  j  | d d ƒ} |  j  | d d ƒ} t j d k r¨ t j d ƒ } t j d | ƒ }	 |	 d  k r™ d	 }
 n |	 j d
 ƒ }
 x| D]w} t j	 j
 | | ƒ } t j	 j
 | | ƒ } t j	 j
 | | ƒ } t j	 j
 | | ƒ } t j d k rÎ| j d ƒ sF| j d ƒ rÎ| j d ƒ rÎt j	 j
 |
 | d
 d  … | ƒ } t j	 j
 |
 | d
 d  … | ƒ } t j	 j
 |
 | d
 d  … | ƒ } t j	 j
 |
 | d
 d  … | ƒ } t j	 j | ƒ rä| St j	 j | ƒ rú| St j	 j | ƒ r| St j	 j | ƒ r¯ | Sq¯ Wd  S)NZlib_typeÚsharedÚdylibÚ
xcode_stubÚstaticr   ÚCFLAGSz-isysroot\s*(\S+)ú/rB   z/System/z/usr/z/usr/local/)r:   r0   r1   r   rZ   ÚreÚsearchÚgroupr   r    rH   Ú
startswithÚexists)r#   Údirsr\   r=   Zshared_fZdylib_fZxcode_stub_fZstatic_fÚcflagsÚmZsysrootrR   r^   r_   ra   r`   r-   r-   r.   Úfind_library_file	  s>    	""""zUnixCCompiler.find_library_file)Ú__name__Ú
__module__Ú__qualname__Úcompiler_typeZexecutablesr0   r1   Zsrc_extensionsZobj_extensionZstatic_lib_extensionÚshared_lib_extensionZdylib_lib_extensionZxcode_stub_lib_extensionZstatic_lib_formatZshared_lib_formatZdylib_lib_formatZxcode_stub_lib_formatZexe_extensionr/   r7   r@   rQ   rS   rT   r[   r]   rl   r-   r-   r-   r.   r   -   sD   					>*r   )Ú__doc__r   r0   rd   Ú	distutilsr   Údistutils.dep_utilr   Údistutils.ccompilerr   r   r   Zdistutils.errorsr   r   r	   r
   r   r1   r2   r   r-   r-   r-   r.   Ú<module>   s   $"