qfc@s/dZdZddlZddlZddlZddlZddlTddlmZm Z ddl m Z ddl Tddl mZmZddlmZdd lmZdd lmZdd lmZejd krdd lmZeeZnejdZdZde fdYZ dS(sdistutils.command.build_ext Implements the Distutils 'build_ext' command, for building extension modules (currently limited to C extensions, should accommodate C++ extensions ASAP).s$Id$iN(t*(t USER_BASEt USER_SITE(tCommand(tcustomize_compilertget_python_version(t newer_group(t Extension(t get_platform(tlogtnt(tget_build_versions3^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$cCsddlm}|dS(Ni(tshow_compilers(tdistutils.ccompilerR (R ((s3/usr/lib64/python2.7/distutils/command/build_ext.pyR st build_extcBs?eZdZdejZdFdGdd d efd d d dfdddefdHdIdJdddefdKdLdMdNdOdQdRdSdTgZd d$d'd-d3gZ d5dPd6e fgZ d7Z d8Z d9Zd:Zd;Zd<Zd=Zd>Zd?Zd@ZdAZdBZdCZdDZdEZRS(Us8build C/C++ extensions (compile/link to build directory)s (separated by '%s')s build-lib=tbs(directory for compiled extension moduless build-temp=tts1directory for temporary files (build by-products)s plat-name=tps>platform name to cross-compile for, if supported (default: %s)tinplacetis=ignore build-lib and put compiled extensions into the source s,directory alongside your pure Python moduless include-dirs=tIs.list of directories to search for header filessdefine=tDsC preprocessor macros to definesundef=tUs!C preprocessor macros to undefines libraries=tls!external C libraries to link withs library-dirs=tLs.directories to search for external C librariessrpath=tRs7directories to search for shared C libraries at runtimes link-objects=tOs2extra explicit link objects to include in the linktdebugtgs'compile/link with debugging informationtforcetfs2forcibly build everything (ignore file timestamps)s compiler=tcsspecify the compiler typesswig-cpps)make SWIG create C++ files (default is C)s swig-opts=s!list of SWIG command line optionssswig=spath to the SWIG executabletusers#add user include, library and rpaths help-compilerslist available compilerscCsd|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_d|_d|_dS(Ni(tNonet extensionst build_libt plat_namet build_tempRtpackaget include_dirstdefinetundeft librariest library_dirstrpatht link_objectsRRtcompilertswigtswig_cppt swig_optsR (tself((s3/usr/lib64/python2.7/distutils/command/build_ext.pytinitialize_optionsls(                   c Csddlm}|jdd/d0d1d2d3d4|jdkrP|jj|_n|jj|_|j }|j d d }|j dkr|jj pg|_ nt |j t r|j j tj|_ n|j j|||kr|j j|n|jd |jdkr(g|_n|jdkrCg|_n3t|jtkrvtj |jtj|_n|jdkrg|_n3t|jtkrtj |jtj|_ntjd krc|jjtjjtjd|jrtjj|jd|_ntjj|jd|_|j jtjjtjdtdkr|j dkr}d}n |j d}tjjtjd}|rtjj||}n|jj|qctdkr|jjtjjtjddqctdkr;|jjtjjtjddqc|jjtjjtjddntjdkr|jjtjjtjdntj!d dkstj!d d kr&tj"j#tjjtjd!r|jjtjjtj$d"d#t%d$q&|jjd%n|j&d&tj!j#d'sitj!j#d(sitj!j#d)r|j&d&rtj"j#tjjtjd!r|jj|j&d*q|jjd%n|j'r|j'j d+}t(d,||_'n|j)r|j)j d+|_)n|j*dkr:g|_*n|j*j d-|_*|j+rtjjt,d.}tjjt,d"}tjj-|r|j j|ntjj-|r|jj||jj|qndS(5Ni(t sysconfigtbuildR#R%R.RRR$t plat_specificiR*R tlibstDebugtReleasetPCi twin32titPCbuildisVS8.0isVS7.1tVC6tos2tConfigitcygwintatheostbintlibtpythontconfigt.tPy_ENABLE_SHAREDtlinuxtgnutsunostLIBDIRt,cSs |dfS(Nt1((tsymbol((s3/usr/lib64/python2.7/distutils/command/build_ext.pytst tinclude(s build_libs build_lib(s build_temps build_temp(scompilerscompiler(sdebugsdebug(sforcesforce(s plat_names plat_name(.t distutilsR4tset_undefined_optionsR&R!t distributiont ext_packaget ext_modulesR"tget_python_incR't isinstancetstrtsplittostpathseptappendtensure_string_listR*R+ttypet StringTypetstringR,tnametpathtjointsyst exec_prefixRR%t MSVC_VERSIONR$tplatformt executablet startswithtprefixRtget_config_varR(tmapR)R1R Rtisdir( R2R4t py_includetplat_py_includetsuffixtnew_libtdefinest user_includetuser_lib((s3/usr/lib64/python2.7/distutils/command/build_ext.pytfinalize_optionss       " "     %&$   $$    c Csddlm}|jsdS|jjrm|jd}|jj|jpSg|j j |j n|d|j d|j d|jd|j|_ t|j tjdkr|jtkr|j j|jn|jdk r|j j|jn|jdk rEx-|jD]\}}|j j||qWn|jdk r{x$|jD]}|j j|q^Wn|jdk r|j j|jn|j dk r|j j|j n|jdk r|j j |jn|j!dk r|j j"|j!n|j#dS( Ni(t new_compilert build_clibR.tverbosetdry_runRR ($R RxR"RUthas_c_librariestget_finalized_commandR*textendtget_library_namesR+R^RyR.RzR{RRR\RcR$Rt initializeR'R!tset_include_dirsR(t define_macroR)tundefine_macrot set_librariestset_library_dirsR,tset_runtime_library_dirsR-tset_link_objectstbuild_extensions(R2RxRyRctvaluetmacro((s3/usr/lib64/python2.7/distutils/command/build_ext.pytruns>    !c Cs!t|tstdnxt|D]\}}t|trIq(nt|t skt|dkrwtdn|\}}tjd|t|t ot j |stdnt|t stdnt||d}x<dD]4}|j |}|dk rt|||qqW|j d|_d|krYtjdn|j d}|rg|_g|_x|D]} t| tot| dkstdnt| dkr|jj| dqt| dkr|jj| qqWn||||j|jg}x!|jD]}|j|jq W|S(N(RR"R~R(R2t filenamesR((s3/usr/lib64/python2.7/distutils/command/build_ext.pytget_source_filess cCsG|j|jg}x*|jD]}|j|j|jq W|S(N(RR"R^tget_ext_fullpathRc(R2toutputsR((s3/usr/lib64/python2.7/distutils/command/build_ext.pyt get_outputss cCs5|j|jx|jD]}|j|qWdS(N(RR"tbuild_extension(R2R((s3/usr/lib64/python2.7/distutils/command/build_ext.pyRsc Cs|j}|dks-t|ttfkrHtddd|jnt|}|j|j}||j }|j pt ||dst j d|jdSt jd|j|j||}|jpg}|j}x!|jD]}|j|fqW|jj|d|jd|d |jd |j d |d |j }||_|jro|j|jn|jp{g}|jp|jj|} |jj||d |j|d|j d|j!d |d|j"|d |j d|jd| dS(Ns*in 'ext_modules' option (extension '%s'), s&'sources' must be present and must be sa list of source filenamestnewers$skipping '%s' extension (up-to-date)sbuilding '%s' extensiont output_dirRR'Rtextra_postargstdependsR*R+Rtexport_symbolsR%t target_lang(#RR!R`tListTypet TupleTypeRRcRRRRRR Rtinfot swig_sourcesRRRR^R.tcompileR%R't_built_objectsRR~Rtlanguagetdetect_languagetlink_shared_objectt get_librariesR+Rtget_export_symbols( R2RRtext_pathRt extra_argsRR)tobjectsR((s3/usr/lib64/python2.7/distutils/command/build_ext.pyRsN $              c Csg}g}i}|jr+tjdn|jsRd|jksRd|jkr[d}nd}xr|D]j}tjj|\}} | dkr|j|d||j||d||          cCstjdkrdStjdkrixgd D]5}tjjd|d}tjj|r)|Sq)WdSn#tjd kr|dStd tjd S( sReturn the name of the SWIG executable. On Unix, this is just "swig" -- it should be in the PATH. Tries a bit harder on Windows. tposixR/R s1.3s1.2s1.1s c:\swig%ssswig.exeR?s>I don't know how to find (much less run) SWIG on platform '%s'N(s1.3s1.2s1.1(R\RcRdRetisfiletDistutilsPlatformError(R2tverstfn((s3/usr/lib64/python2.7/distutils/command/build_ext.pyROs c Cstjdtjd}|j|}|j|}|jd}|j|}tjj|d}|j stjj |d |g}tjj |j |Sdj |dd!}|j d}tjj |j|}tjj ||S(sReturns the path of the filename for a given extension. The file is located in `build_lib` or directly in the package (inplace option). t/s..RGiitbuild_py(Rbt maketransR\tsept translatetget_ext_fullnameR[tget_ext_filenameRdRReR#R}tabspathtget_package_dir( R2Rtall_dotstfullnametmodpathtfilenameR&Rt package_dir((s3/usr/lib64/python2.7/distutils/command/build_ext.pyRps cCs&|jdkr|S|jd|SdS(sSReturns the fullname of a given extension name. Adds the `package.` prefixRGN(R&R!(R2R((s3/usr/lib64/python2.7/distutils/command/build_ext.pyRscCsddlm}tj|d}tjdkrZ|t|dd |t|ds$0