B 1 ÅÜv×cã@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 ZZeZejdkrdZ‡fdd„Zd.dd„Zdd„Zd/d d!„Zd0d"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd1d,d-„Z‡ZS)2Ú UnixCCompilerZunixNZccz-sharedZarz-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|ƒ |||¡\}}}t d¡}|r<||kr<| |¡|||fS)z'Remove standard library path from rpathZLIBDIR)ÚsuperÚ __class__Ú _fix_lib_argsrÚget_config_varÚremove)ÚselfÚ librariesÚ library_dirsÚruntime_library_dirsZlibdir)r©ú|  d|g¡|rN|| dd…<|r\|  |¡|  |¡|js~|dks~t||ƒrÎ|r”| tj   |¡¡y|  | ¡Wn*t k rÌ} z t | ƒ‚Wdd} ~ XYnXdS)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 t |||¡}y | |||d|g|¡Wn*tk rj}z t|ƒ‚Wdd}~XYnXdS)Nr z-o)rÚsysÚplatformÚ _osx_supportÚcompiler_fixupr)rr) rÚobjÚsrcZextZcc_argsr,r/rr0r!r!r"Ú_compileys   zUnixCCompiler._compilerc Cs²| ||¡\}}|j||d}| ||¡r¢| tj |¡¡| |j|g||j ¡|j r®y| |j |g¡Wq®t k rž}z t |ƒ‚Wdd}~XYq®Xn t  d|¡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_libnamer9r>Ú target_langÚoutput_filenamer0r!r!r"Úcreate_static_lib„s zUnixCCompiler.create_static_libc CsÞ| ||¡\}}| |||¡}|\}}}t||||ƒ}t|ttdƒfƒsPtdƒ‚|dk rftj  ||¡}|  ||¡rÎ||j |d|g}| rœdg|dd…<| r¬| |dd…<| rº|  | ¡|  tj |¡¡yÒ|tjkrè|jdd…}n|jdd…}| dkrv|jrvd}tj |d¡dkrDd}xd||krB|d7}q(Wtj ||¡d kr`d}nd}|j||||<tjd krŽt ||¡}| ||¡Wn,tk rÊ}z t|ƒ‚Wdd}~XYnXn t d |¡dS) Nz%'output_dir' must be a string or Nonez-oz-grzc++Úenvéú=Z ld_so_aixr zskipping %s (up-to-date))r:rrÚ isinstanceÚstrÚtypeÚ TypeErrorr&r'Újoinr<r=r#r%r(rZ EXECUTABLErrrÚbasenamer2r3r4r5r)rr r r>)rZ target_descr=r@r9rrr Zexport_symbolsr>r+r,Z build_tempr?r-Zlib_optsZld_argsZlinkerÚiÚoffsetr0r!r!r"ÚlinkžsN      zUnixCCompiler.linkcCsd|S)Nz-Lr!)rÚdirr!r!r"Úlibrary_dir_optionàsz UnixCCompiler.library_dir_optioncCsd|kpd|kS)NZgcczg++r!)rZ compiler_namer!r!r"Ú_is_gccãszUnixCCompiler._is_gcccCs°tj t d¡¡}tjdd…dkr,d|Stjdd…dkrFd|Stjdd…d krz| |¡rnd d|gSd d|gS| |¡r¤t d ¡d kršd|Sd|Snd|SdS)NZCCrr z-LéZfreebsdz -Wl,-rpath=ézhp-uxz-Wl,+sz+sZGNULDZyesz-Wl,--enable-new-dtags,-Rz-Wl,-Rz-R)r&r'rJrrr2r3rP)rrNrr!r!r"Úruntime_library_dir_optionæs     z(UnixCCompiler.runtime_library_dir_optioncCsd|S)Nz-lr!)rÚlibr!r!r"Úlibrary_optionszUnixCCompiler.library_optioncCs’|j|dd}|j|dd}|j|dd}|j|dd}tjdkrpt d¡}t d|¡} | dkrfd } n |  d ¡} x|D]} tj   | |¡} tj   | |¡} tj   | |¡}tj   | |¡}tjdkrD|   d ¡sä|   d ¡rD|   d ¡sDtj   | | d d…|¡} tj   | | d d…|¡} tj   | | d d…|¡}tj   | | d d…|¡}tj   | ¡rV| Stj   |¡rh|Stj   | ¡rz| Stj   |¡rx|SqxWdS)NÚshared)Zlib_typeÚdylibÚ xcode_stubÚstaticr ZCFLAGSz-isysroot\s*(\S+)ú/rCz/System/z/usr/z /usr/local/) r;r2r3rrÚreÚsearchÚgroupr&r'rIÚ startswithÚexists)rÚdirsrTr>Zshared_fZdylib_fZ xcode_stub_fZstatic_fZcflagsÚmZsysrootrNrVrWrYrXr!r!r"Úfind_library_files>       zUnixCCompiler.find_library_file)NNNNN)NrN) NNNNNrNNNN)r)Ú__name__Ú __module__Ú __qualname__Z compiler_typeZ executablesr2r3Zsrc_extensionsZ obj_extensionZstatic_lib_extensionZshared_lib_extensionZdylib_lib_extensionZxcode_stub_lib_extensionZstatic_lib_formatZshared_lib_formatZdylib_lib_formatZxcode_stub_lib_formatZ exe_extensionrr1r8rArMrOrPrSrUrbÚ __classcell__r!r!)rr"r -sF       >*r )Ú__doc__r&r2r[Z distutilsrZdistutils.dep_utilrZdistutils.ccompilerrrrZdistutils.errorsrrr r r r3r4r r!r!r!r"Ús