\d=3xdZddlZddlZddlmZddlmZddlmZddl m Z ddd Z Gd d eZ d d Z dS)adistutils.command.config Implements the Distutils 'config' command, a (mostly) empty command class that exists mainly to be sub-classed by specific module distributions and applications. The idea is that while every "config" command is different, at least they're all named the same, and users always see "config" in the list of standard commands. Also, this is a good place to put common configure-like tasks: "try to compile this C code", or "figure out where this header file lives". N)Command)DistutilsExecError)customize_compiler)logz.cz.cxx)czc++ceZdZdZgdZdZdZdZdZdZ dZ d Z d Z d Z ddZ ddZddZ ddZ ddZ ddZd d d gfdZ ddZd S)configzprepare to build) )z compiler=Nzspecify the compiler type)zcc=Nzspecify the compiler executable)z include-dirs=Iz.list of directories to search for header files)zdefine=DzC preprocessor macros to define)zundef=Uz!C preprocessor macros to undefine)z libraries=lz!external C libraries to link with)z library-dirs=Lz.directories to search for external C libraries)noisyNz1show every action (compile, link, run, ...) taken)z dump-sourceNz=dump generated source files before attempting to compile themcvd|_d|_d|_d|_d|_d|_d|_g|_dS)N)compilercc include_dirs libraries library_dirsr dump_source temp_filesselfs )..\python\lib\distutils\command\config.pyinitialize_optionszconfig.initialize_options3sE    c|j|jjpg|_nCt|jtr)|jt j|_|jg|_n't|jtr |jg|_|j g|_dSt|jtr+|jt j|_dSdSN) r distribution isinstancestrsplitospathseprrrs rfinalize_optionszconfig.finalize_optionsBs   $ $ 1 > D"D   )3 / / D $ 1 7 7 C CD  > !DNN  , , ."n-DN   $ "D    )3 / / D $ 1 7 7 C CD    D DrcdSrrs rrunz config.runRs rcddlm}m}t|j|s||j|jd|_t |j|jr|j|j|j r|j |j |j r#|j |j dSdSdS)z^Check that 'self.compiler' really is a CCompiler object; if not, make it one. r) CCompiler new_compilerr)rdry_runforceN) distutils.ccompilerr+r,r!rr-rrset_include_dirsr set_librariesrset_library_dirs)rr+r,s r_check_compilerzconfig._check_compilerYs @???????$-33 B(L$-15QHHHDM t} - - -  B ..t/@AAA~ < ++DN;;;  B ..t/@AAAAA B B B BrcJdt|z}t|d5}|r2|D]}|d|z|d|||ddkr|ddddn #1swxYwY|S)N _configtestwz#include <%s>  )LANG_EXTopenwrite)rbodyheaderslangfilenamefileheaders r_gen_temp_sourcefilezconfig._gen_temp_sourcefileks 8D>1 (C  !D !%;;FJJ069:::: 4   JJt   Bx4 4    ! ! ! ! ! ! ! ! ! ! ! ! ! ! !sA+BBBc||||}d}|j||g|j|||||fS)Nz _configtest.ir)rBrextendr preprocess)rr<r=rr>srcouts r _preprocesszconfig._preprocessws_''gt<< Sz***   c  EEESzrc||||}|jrt|d|z|j|g\}|j||g|j|g|||fS)Nzcompiling '%s':rD)rBr dump_filerobject_filenamesrrEcompile)rr<r=rr>rGobjs r_compilezconfig._compile~s''gt<<   4 c,s2 3 3 3//66 Sz*** se,???Szrcp|||||\}}tjtj|d} |j|g| ||||jj| |jjz} |j | ||| fS)Nr)rr target_lang) rOr$pathsplitextbasenamerlink_executable exe_extensionrappend) rr<r=rrrr>rGrNprogs r_linkz config._links]]4,EE cw 0 0 5 566q9 %%seT093?26 & 8 8 8 = & 2$-55D t$$$S$rc|s|j}g|_tjdd||D]'} t j|#t $rY$wxYwdS)Nz removing: %s )rrinfojoinr$removeOSError)r filenamesr?s r_cleanz config._cleans !I DO )!4!4555!  H  (####      sA A A Nrcddlm}|d} |||||n #|$rd}YnwxYw||S)aQConstruct a source file from 'body' (a string containing lines of C/C++ code) and 'headers' (a list of header files to include) and run it through the preprocessor. Return true if the preprocessor succeeded, false if there were any errors. ('body' probably isn't of much use, but what the heck.) r CompileErrorTF)r/rdr3rIrarr<r=rr>rdoks rtry_cppzconfig.try_cpps 544444      T7L$ ? ? ? ?   BBB   s7AAc||||||\}}t|trt j|}t |5}d} |} | dkrn|| rd} n4dddn #1swxYwY| | S)aConstruct a source file (just like 'try_cpp()'), run it through the preprocessor, and return true if any line of the output matches 'pattern'. 'pattern' should either be a compiled regex object or a string containing a regex. If both 'body' and 'headers' are None, preprocesses an empty file -- which can be useful to determine the symbols the preprocessor and compiler set by default. FTN) r3rIr!r"rerMr:readlinesearchra) rpatternr<r=rr>rGrHr@matchlines r search_cppzconfig.search_cpps  ##D'<FFS gs # # *j))G #YY $E }}2::>>$'' E                   s(8B,,B03B0cddlm}| |||||d}n #|$rd}YnwxYwt j|rdpd||S)zwTry to compile a source file built from 'body' and 'headers'. Return true on success, false otherwise. rrcTFsuccess!failure.)r/rdr3rOrr\rares r try_compilezconfig.try_compiles 544444   MM$t < < <BB   BBB  " 0j111  s7AAcddlm}m}| |||||||d} n#||f$rd} YnwxYwt j| rdpd|| S)zTry to compile and link a source file, built from 'body' and 'headers', to executable form. Return true on success, false otherwise. rrd LinkErrorTFrrrs)r/rdrwr3rYrr\ra) rr<r=rrrr>rdrwrfs rtry_linkzconfig.try_links @???????   JJtWl , 6 6 6BBi(   BBB  " 0j111  s; AAc0ddlm}m}| |||||||\} } } || gd} n#||t f$rd} YnwxYwtj| rdpd| | S)zTry to compile, link to an executable, and run a program built from 'body' and 'headers'. Return true on success, false otherwise. rrvTFrrrs) r/rdrwr3rYspawnrrr\ra) rr<r=rrrr>rdrwrGrNexerfs rtry_runzconfig.try_runs @???????   JJtWl'0,FFMCc JJu   BBi);<   BBB  " 0j111  s6AA'&A'rc~|g}|r|d|z|d|r|d|zn|d|z|dd|dz}||||||S)aDetermine if function 'func' is available by constructing a source file that refers to 'func', and compiles and links it. If everything succeeds, returns true; otherwise returns false. The constructed source file starts out by including the header files listed in 'headers'. If 'decl' is true, it then declares 'func' (as "int func()"); you probably shouldn't supply 'headers' and set 'decl' true in the same call, or you might get errors about a conflicting declarations for 'func'. Finally, the constructed 'main()' function either references 'func' or (if 'call' is true) calls it. 'libraries' and 'library_dirs' are used when linking. z int %s ();z int main () {z %s();z %s;}r7)r3rWr]rx) rfuncr=rrrdeclcallr<s r check_funczconfig.check_funcs   - KK t+ , , , O$$$  ( KK D( ) ) ) ) KK$ ' ' ' Cyy%}}T7L& 66 6rcd||d|||g|z|S)aDetermine if 'library' is available to be linked against, without actually checking that any particular symbols are provided by it. 'headers' will be used in constructing the source file to be compiled, but the only effect of this is to check if all the header files listed are available. Any libraries listed in 'other_libraries' will be included in the link, in case 'library' has symbols that depend on other libraries. zint main (void) { })r3rx)rlibraryrr=rother_librariess r check_libzconfig.check_lib4sB }}2G\%Y8,HH Hrc4|d|g|S)zDetermine if the system header file named by 'header_file' exists and can be found by the preprocessor; return true if so, false otherwise. z /* No body */)r<r=r)rg)rrArrr>s r check_headerzconfig.check_headerBs( ||6()577 7r)NNNr)NNr)NNNNr)NNNNrr)__name__ __module__ __qualname__ description user_optionsrr&r)r3rBrIrOrYrargrprtrxr|rrrr(rrr r s$K   L4   DDD    BBB$          ,$IM8 IM),&HL(+2;?CD6666</3D#R H H H HDH777777rr c$|tjd|ntj|t|} tj||dS#|wxYw)zjDumps a file content into log.info. If head is not None, will be dumped before the file content. Nz%s)rr\r:readclose)r?headr@s rrKrKKsv  | x      >>D   s &A99Br)__doc__r$rjdistutils.corerdistutils.errorsrdistutils.sysconfigr distutilsrr9r rKr(rrrs   """"""//////222222f % %t7t7t7t7t7Wt7t7t7l      r