h fy@s dZddlZddlZddlZddlmZddlTddlmZm Z ddlm Z ddl m Z ddl mZdd lmZdd lmZdd lmZejd krdd lmZeeZnejdZddZGdddeZdS)zdistutils.command.build_ext Implements the Distutils 'build_ext' command, for building extension modules (currently limited to C extensions, should accommodate C++ extensions ASAP).N)Command)*)customize_compilerget_python_version)get_config_h_filename) newer_group) Extension) get_platform)log) USER_BASEnt)get_build_versionz3^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$cCsddlm}|dS)Nr)show_compilers)distutils.ccompilerr)rr@/opt/alt/python34/lib64/python3.4/distutils/command/build_ext.pyrsrc@steZdZdZdejZdWdXd d d efd d ddfdddefdYdZd[dddefd\d]d^d_d`dadbdcddgZd d%d(d.d5gZ d7d/d8e fgZ d9d:Z d;d<Z d=d>Zd?d@ZdAdBZdCdDZdEdFZdGdHZdIdJZdKdLZdMdNZdOdPZdQdRZdSdTZdUdVZd/S)e build_extz8build C/C++ extensions (compile/link to build directory)z (separated by '%s') build-lib=b(directory for compiled extension modules build-temp=t1directory for temporary files (build by-products)z plat-name=pz>platform name to cross-compile for, if supported (default: %s)inplaceiz=ignore build-lib and put compiled extensions into the source z,directory alongside your pure Python modulesz include-dirs=Iz.list of directories to search for header filesdefine=DC preprocessor macros to defineundef=U!C preprocessor macros to undefine libraries=l!external C libraries to link withz library-dirs=Lz.directories to search for external C librariesrpath=R7directories to search for shared C libraries at runtime link-objects=O2extra explicit link objects to include in the linkdebugg'compile/link with debugging informationforcef2forcibly build everything (ignore file timestamps) compiler=cspecify the compiler typeswig-cppN)make SWIG create C++ files (default is C) swig-opts=!list of SWIG command line optionsswig=path to the SWIG executableuser#add user include, library and rpathz help-compilerzlist available compilerscCsd|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_d|_dS)Nr) extensions build_lib plat_name build_temprpackage include_dirsdefineundef libraries library_dirsrpath link_objectsr-r0compilerswigswig_cpp swig_optsr<)selfrrrinitialize_optionsis(                   zbuild_ext.initialize_optionsc Csddlm}|jdd,d-d.d/d0d1|jdkrP|jj|_n|jj|_|j}|jd d }|j dkr|jj pg|_ nt |j t r|j j t j|_ ntjtjkr|j jt jjtjd n|j j|||kr7|j j|n|jd |jdkr_g|_n|jdkrzg|_n-t |jt r|jj t j|_n|jdkrg|_n-t |jt r|jj t j|_nt jdkr|jjt jjtjdtjtjkrW|jjt jjtjdn|jr~t jj|jd|_nt jj|jd|_|j jt jjtttdd}|r|jj|nt dkrc|j!dkrd}n|j!dd}t jjtjd}|rPt jj||}n|jj|qt dkr|jjt jjtjddqt dkr|jjt jjtjddq|jjt jjtjddntj"dddks%tj"ddd krtj#j$t jjtjd!r{|jjt jjtjd"d#t%d$q|jjd%n|j&d&r|j's|jj|j&d'q|jjd%n|j(r |j(j d(}d)d*|D|_(n|j)r*|j)j d(|_)n|j*dkrEg|_*n|j*j d+|_*|j+rt jjt,d }t jjt,d"} t jj-|r|j j|nt jj-| r|jj| |jj| qndS)2Nr) sysconfigZbuildr?rArJr-r0r@Z plat_specificincluderFr ZlibsZDebugZRelease_home win32ZPCbuildPCzVS8.0zVS7.1ZVC6cygwinatheosbinlibpythonconfig.Py_ENABLE_SHAREDLIBDIR,cSsg|]}|dfqS)1r).0Zsymbolrrr s z.build_ext.finalize_options.. ) build_librj) build_temprk)compilerrl)debugrm)forcern) plat_namero). distutilsrPZset_undefined_optionsrB distributionZ ext_packageZ ext_modulesr>Zget_python_incrC isinstancestrsplitospathsepsys exec_prefixbase_exec_prefixappendpathjoinZensure_string_listrFrGrHnameprefixr-rAdirnamergetattr MSVC_VERSIONr@platform executable startswithrget_config_varZ python_buildrDrErMr<r isdir) rNrPZ py_includeZplat_py_include _sys_homesuffixZnew_libZdefinesZ user_includeZuser_librrrfinalize_optionss  %     "%     2$       zbuild_ext.finalize_optionsc 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) Nr) new_compiler build_clibrJverbosedry_runr0r )#rrr>rqZhas_c_librariesget_finalized_commandrFextendZget_library_namesrGrzrrJrrr0rrur}r@r Z initializerCZset_include_dirsrDZ define_macrorEZundefine_macroZ set_librariesZset_library_dirsrHZset_runtime_library_dirsrIZset_link_objectsbuild_extensions)rNrrr}valuemacrorrrruns>    !z build_ext.runc Cs0t|tstdnx t|D]\}}t|trLq+nt|t snt|dkr}tdn|\}}tjd|t|t ot j |stdnt|t stdnt||d}x<dD]4}|j |}|dk rt|||qqW|j d|_d|kretjdn|j d}|rg|_g|_x|D]} t| tot| dkstdnt| dkr|jj| dqt| dkr|jj| qqWn|||rextext_nameZ build_infokeyvalrrrrrcheck_extensions_listUsT  "           ! zbuild_ext.check_extensions_listcCs>|j|jg}x!|jD]}|j|jq W|S)N)rr>rr)rN filenamesrrrrget_source_filess zbuild_ext.get_source_filescCsG|j|jg}x*|jD]}|j|j|jq W|S)N)rr>rzget_ext_fullpathr})rNZoutputsrrrr get_outputss zbuild_ext.get_outputscCs|j|jx||jD]q}y|j|Wqtttfk r}z.|js^n|jd|j|fWYdd}~XqXqWdS)Nz"building extension "%s" failed: %s) rr>build_extensionZCCompilerErrorZDistutilsErrorZ CompileErrorZoptionalrr})rNrerrrrs  zbuild_ext.build_extensionsc Cs |j}|dks+t|ttf rAtd|jnt|}|j|j}||j}|jpt ||dst j d|jdSt j d|j|j ||}|jpg}|jdd}x!|jD]}|j|fqW|jj|d|jd|d|jd|j d |d |j}|dd|_|jrz|j|jn|jpg}|jp|jj|} |jj||d |j|d |jd |jd |d|j |d|j d|jd| dS)Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesZnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extensionZ output_dirrrCr-Zextra_postargsdependsrFrGrexport_symbolsrAZ target_lang)!rrrrrrr}rrr0rr r-info swig_sourcesrrrrzrJcompilerArCZ_built_objectsrrrlanguageZdetect_languageZlink_shared_object get_librariesrGrget_export_symbols) rNrrext_pathrZ extra_argsrrEZobjectsrrrrrsN "             zbuild_ext.build_extensioncCsg}g}i}|jr+tjdn|jsRd|jksRd|jkr[d}nd}xr|D]j}tjj|\}} | dkr|j|d||j||d ||          zbuild_ext.swig_sourcescCstjdkrdStjdkrixWd D]5}tjjd|d}tjj|r)|Sq)WdSntd tjd S) zReturn the name of the SWIG executable. On Unix, this is just "swig" -- it should be in the PATH. Tries a bit harder on Windows. posixrKr 1.31.21.1z c:\swig%szswig.exez>I don't know how to find (much less run) SWIG on platform '%s'N)rrr)rur}r{r|isfileZDistutilsPlatformError)rNZversfnrrrrOs zbuild_ext.find_swigcCs|j|}|jd}|j|d}|jsstjj|dd|g}tjj|j|Sdj|dd}|jd}tjj |j |}tjj||S) zReturns the path of the filename for a given extension. The file is located in `build_lib` or directly in the package (inplace option). rbrQNrbuild_pyrrr) get_ext_fullnamertget_ext_filenamerrur{r|r?rabspathZget_package_dir)rNrfullnameZmodpathfilenamerBrZ package_dirrrrrgs #zbuild_ext.get_ext_fullpathcCs&|jdkr|S|jd|SdS)zSReturns the fullname of a given extension name. Adds the `package.` prefixNrb)rB)rNrrrrrszbuild_ext.get_ext_fullnamecCsoddlm}|jd}|d}tjdkr[|jr[tjj|d|Stjj||S)zConvert the name of an extension (eg. "foo.bar") into the name of the file from which it will be loaded (eg. "foo/bar.so", or "foo\bar.pyd"). r)rrb EXT_SUFFIXr _d)distutils.sysconfigrrtrur}r-r{r|)rNrrrZ ext_suffixrrrrs  zbuild_ext.get_ext_filenamecCsCd|jjdd}||jkr<|jj|n|jS)aReturn the list of symbols that a shared extension has to export. This either uses 'ext.export_symbols' or, if it's not provided, "PyInit_" + module_name. Only relevant on Windows, where the .pyd file (DLL) must export the module "PyInit_" function. ZPyInit_rbrQr)r}rtrrz)rNrZ initfunc_namerrrrszbuild_ext.get_export_symbolscCs0tjdkrddlm}t|j|s}d}|jrM|d}n|tjd?tjd?d@f}|j|gS|jSntjd d d krd }|tjd?tjd?d@f}|j|gStjd d d krddl m }d }|tjd?tjd?d@f}g}xS|j dj D]<}|j drr|j|dd qC|j|qCW|j|dg|Stjdkr|jStjd ddkr|jSddl m }|j dr%djtjd?tjd?d@tj}|j|gS|jSd S)zReturn the list of libraries to link against when building a shared extension. On most platforms, this is just 'ext.libraries'; on Windows, we add the Python library (eg. python20.dll). rUr) MSVCCompilerz python%d%drNr[r\z python%d.%dr])rPSHLIBSz-lrmdarwinaixrcz python{}.{}{})rwrdistutils.msvccompilerrrrrJr- hexversionrFrprPrrtrrzformatabiflags)rNrrtemplateZ pythonlibrPZextrar_rrrrsJ     zbuild_ext.get_libraries)rrr)rrr)rrr)r r!r")r#r$r%)r'r(r))r*r+r,)zdebugr.r/)zforcer1r2)r3r4r5)r6Nr7)r8Nr9)r:Nr;)zuserNr=)__name__ __module__ __qualname__Z descriptionrurvZsep_byr Z user_optionsZboolean_optionsrZ help_optionsrOrrrrrrrrrrrrrrrrrrr"st        @ N  R 6   r)__doc__rwrureZdistutils.corerZdistutils.errorsrrrrZdistutils.dep_utilrZdistutils.extensionrZdistutils.utilr rpr Zsiter r}rr intrrrrrrrrrs"$