3 ª f¨:ã@s’dZddlZddlZddlZddlmZddlmZddlm Z m Z m Z ddl m Z mZmZmZddlmZejdkr~ddlZGd d „d e ƒZdS) a9distutils.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ôeZdZdZddgdgdgddgdgddgddœZejdd…d krNd ged <d d d dddgZdZdZ dZ dZ dZ dZ ZZeZejdkr�dZ‡fdd„Zd.dd„Zdd„Zd/d d!„Zd0d"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd1d,d-„Z‡ZS)2Ú UnixCCompilerZunixNZccz-sharedÚarz-cr)Ú preprocessorÚcompilerÚ compiler_soÚ compiler_cxxÚ linker_soÚ linker_exeÚarchiverÚranlibér rz.cz.Cz.ccz.cxxz.cppz.mz.oz.az.soz.dylibz.tbdzlib%s%sÚcygwinz.execsFt|j|ƒj|||ƒ\}}}tjdƒ}|r<||kr<|j|ƒ|||fS)z'Remove standard library path from rpathÚLIBDIR)ÚsuperÚ __class__Ú _fix_lib_argsrÚget_config_varÚremove)ÚselfÚ librariesÚ library_dirsÚruntime_library_dirsZlibdir)r©ú| jd|gƒ|rN|| dd…<|r\| j|ƒ| j|ƒ|js~|dks~t||ƒrÎ|r”|jtj j |ƒƒy|j | ƒWn*t k rÌ} zt | ƒ‚WYdd} ~ XnXdS)Nz-or)Z_fix_compile_argsrrÚextendÚappendZforcerÚmkpathÚosÚpathÚdirnameÚspawnrr) rÚsourceZ output_fileZmacrosZ include_dirsÚ extra_preargsÚextra_postargsÚ fixed_argsÚignoreÚpp_optsZpp_argsÚmsgr#r#r$Ú preprocess_s$      zUnixCCompiler.preprocessc Csp|j}tjdkr tj|||ƒ}y |j|||d|g|ƒWn*tk rj}zt|ƒ‚WYdd}~XnXdS)Nr z-o)rÚsysÚplatformÚ _osx_supportÚcompiler_fixupr+rr) rÚobjÚsrcZextZcc_argsr.r1rr2r#r#r$Ú_compileys   zUnixCCompiler._compilercCs²|j||ƒ\}}|j||d�}|j||ƒr¢|jtjj|ƒƒ|j|j|g||j ƒ|j r®y|j|j |gƒWq®t k rž}zt |ƒ‚WYdd}~Xq®Xn t jd|ƒdS)N)Ú output_dirzskipping %s (up-to-date))Ú_fix_object_argsÚlibrary_filenameÚ _need_linkr'r(r)r*r+rÚobjectsrrr r Údebug)rr?Zoutput_libnamer;r@Ú target_langÚoutput_filenamer2r#r#r$Úcreate_static_lib„s zUnixCCompiler.create_static_libcCsº|j||ƒ\}}|j|||ƒ}|\}}}t||||ƒ}t|ttdƒfƒsPtdƒ‚|dk rftjj ||ƒ}|j ||ƒ�rª||j |d|g}| rœdg|dd…<| r¬| |dd…<| rº|j | ƒ|j tjj|ƒƒy®|tjkrè|jdd…}n|jdd…}| dk�rR|j�rRd}tjj|dƒdk�rDd}xd||k�rB|d7}�q(W|j|||<tjd k�rjtj||ƒ}|j||ƒWn,tk �r¦}zt|ƒ‚WYdd}~XnXn tjd |ƒdS) Nz%'output_dir' must be a string or Nonez-oz-grzc++Úenvéú=r zskipping %s (up-to-date))r<rrÚ isinstanceÚstrÚtypeÚ TypeErrorr(r)Újoinr>r?r%r'r*rZ EXECUTABLErrrÚbasenamer4r5r6r7r+rr r r@)rZ target_descr?rBr;r r!r"Zexport_symbolsr@r-r.Z build_temprAr/Zlib_optsZld_argsZlinkerÚir2r#r#r$ÚlinkžsH      zUnixCCompiler.linkcCsd|S)Nz-Lr#)rÚdirr#r#r$Úlibrary_dir_optionØsz UnixCCompiler.library_dir_optioncCsd|kpd|kS)NÚgcczg++r#)rZ compiler_namer#r#r$Ú_is_gccÛszUnixCCompiler._is_gcccCsÜtjjtjdƒƒ}tjdd…dkr,d|Stjdd…dkrFd|Stjdd…d krz|j|ƒrnd d|gSd d|gStjdd…d ksžtjdd…d kr¦d|gS|j|ƒrÐtjdƒdkrÆd|Sd|Snd|SdS)NÚCCrr z-LéZfreebsdz -Wl,-rpath=ézhp-uxz-Wl,+sz+sZirix646Zosf1V5z-rpathÚGNULDÚyesz-Wl,--enable-new-dtags,-Rz-Wl,-Rz-R)r(r)rLrrr4r5rR)rrOrr#r#r$Úruntime_library_dir_optionÞs    $  z(UnixCCompiler.runtime_library_dir_optioncCsd|S)Nz-lr#)rÚlibr#r#r$Úlibrary_option szUnixCCompiler.library_optioncCs�|j|dd�}|j|dd�}|j|dd�}|j|dd�}tjdkrptjdƒ}tjd|ƒ} | dkrfd } n | jd ƒ} �x|D�]} tj j | |ƒ} tj j | |ƒ} tj j | |ƒ}tj j | |ƒ}tjdkoÞ| j d ƒsâ| j d ƒoÞ| j d ƒ �rBtj j | | d d…|ƒ} tj j | | d d…|ƒ} tj j | | d d…|ƒ}tj j | | d d…|ƒ}tj j | ƒ�rT| Stj j |ƒ�rf|Stj j | ƒ�rx| Stj j |ƒrx|SqxWdS)NÚshared)Zlib_typeÚdylibÚ xcode_stubÚstaticr ÚCFLAGSz-isysroot\s+(\S+)ú/rEz/System/z/usr/z /usr/local/) r=r4r5rrÚreÚsearchÚgroupr(r)rKÚ startswithÚexists)rÚdirsrYr@Zshared_fZdylib_fZ xcode_stub_fZstatic_fZcflagsÚmZsysrootrOr[r\r^r]r#r#r$Úfind_library_file s>       zUnixCCompiler.find_library_file)NNNNN)NrN) NNNNNrNNNN)r)Ú__name__Ú __module__Ú __qualname__Z compiler_typeZ executablesr4r5Zsrc_extensionsZ obj_extensionZstatic_lib_extensionZshared_lib_extensionZdylib_lib_extensionZxcode_stub_lib_extensionZstatic_lib_formatZshared_lib_formatZdylib_lib_formatZxcode_stub_lib_formatZ exe_extensionrr3r:rCrNrPrRrXrZrhÚ __classcell__r#r#)rr$r -sF       6,r )Ú__doc__r(r4raZ distutilsrZdistutils.dep_utilrZdistutils.ccompilerrrrZdistutils.errorsrrr r r r5r6r r#r#r#r$Ús