
.c`~:  ã               @   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ÚUnixCCompilerZunixÚpreprocessorNÚcompilerZccÚcompiler_soÚcompiler_cxxÚ	linker_soz-sharedÚ
linker_exeÚarchiverZ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ÚappendZforcer   ÚmkpathÚosÚpathÚdirnameÚspawnr   r   )ÚselfÚsourceZoutput_fileZmacrosZinclude_dirsÚextra_preargsÚextra_postargsÚ
fixed_argsÚignoreÚpp_optsZpp_argsÚmsg© r'   ú-/usr/lib/python3.5/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ÚsrcZ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   r5   Zoutput_libnamer1   r6   Útarget_langÚoutput_filenamer&   r'   r'   r(   Úcreate_static_libz   s    	"zUnixCCompiler.create_static_libc                s½  |  j  | | ƒ \ } } |  j | | | ƒ } | \ } } } d d d d g ‰  t j d ƒ } | r~ ˆ  j d | d | g ƒ ‡  f d d	 †  | Dƒ } ‡  f d
 d	 †  | Dƒ } t |  | | | ƒ } t | t t d  ƒ f ƒ sì t	 d ƒ ‚ | d  k	 rt
 j j | | ƒ } |  j | | ƒ r©| |  j | d | g } |	 rSd g | d  d … <|
 ri|
 | d  d … <| r|| j | ƒ |  j t
 j j | ƒ ƒ yÝ | t j k r½|  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W|  j | | | <t j d k r`t j | | ƒ } |  j | | ƒ Wq¹t k
 r¥} z t | ƒ ‚ WYd  d  } ~ Xq¹Xn t j d | ƒ d  S)Nz/libz/lib64z/usr/libz
/usr/lib64Z	MULTIARCHz/lib/%sz/usr/lib/%sc                s"   g  |  ] } | ˆ  k r | ‘ q Sr'   r'   )Ú.0Údir)Úsystem_libdirsr'   r(   ú
<listcomp>¤   s   	 z&UnixCCompiler.link.<locals>.<listcomp>c                s"   g  |  ] } | ˆ  k r | ‘ q Sr'   r'   )r:   r;   )r<   r'   r(   r=   ¦   s   	 z%'output_dir' must be a string or Nonez-oz-gr   zc++Úenvé   ú=r   zskipping %s (up-to-date)) r2   Z_fix_lib_argsr   Úget_config_varr   r   Ú
isinstanceÚstrÚtypeÚ	TypeErrorr   r   Újoinr4   r5   r   r   r   Z
EXECUTABLEr   r   r   Úbasenamer*   r+   r,   r-   r   r   r
   r   r6   )r   Ztarget_descr5   r8   r1   Z	librariesZlibrary_dirsZruntime_library_dirsZexport_symbolsr6   r!   r"   Z
build_tempr7   r#   Z	multiarchZlib_optsZld_argsZlinkerÚir&   r'   )r<   r(   Úlink”   sT    		"zUnixCCompiler.linkc             C   s   d | S)Nz-Lr'   )r   r;   r'   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€ |  j | ƒ rr d d | g Sd d | g St j d  d	 … d
 k s² t j d  d … d k r¼ d | g S|  j | ƒ ró t j d ƒ d k rè d | Sd | Sn d | Sd  S)NZCCr   r   z-Lé   zhp-uxz-Wl,+sz+sé   Zirix646Zosf1V5z-rpathZGNULDZyesz-Wl,--enable-new-dtags,-Rz-Wl,-Rz-R)r   r   rG   r   rA   r*   r+   rK   )r   r;   r   r'   r'   r(   Úruntime_library_dir_optionß   s    2
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   ZCFLAGSz-isysroot\s+(\S+)ú/r?   z/System/z/usr/z/usr/local/)r3   r*   r+   r   rA   ÚreÚsearchÚgroupr   r   rF   Ú
startswithÚexists)r   ÚdirsrO   r6   Zshared_fZdylib_fZxcode_stub_fZstatic_fZcflagsÚmZsysrootr;   rQ   rR   rT   rS   r'   r'   r(   Úfind_library_file  s>    	""""zUnixCCompiler.find_library_file)Ú__name__Ú
__module__Ú__qualname__Zcompiler_typeZexecutablesr*   r+   Zsrc_extensionsZobj_extensionZstatic_lib_extensionZ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)   r0   r9   rI   rJ   rK   rN   rP   r]   r'   r'   r'   r(   r   -   sD   					A*r   )Ú__doc__r   r*   rV   Z	distutilsr   Zdistutils.dep_utilr   Zdistutils.ccompilerr   r   r   Zdistutils.errorsr   r   r	   r
   r   r+   r,   r   r'   r'   r'   r(   Ú<module>   s   $"