o bc=3@sldZddlZddlZddlmZddlmZddlmZddl m Z ddd Z Gd d d eZ dd 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++c@seZdZdZgdZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ d(ddZ  d(ddZd)ddZ  d*ddZ  d*dd Z  !d+d"d#Zdddgfd$d%Z  d)d&d'ZdS),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 themcCs4d|_d|_d|_d|_d|_d|_d|_g|_dS)N)compilercc include_dirs libraries library_dirsr dump_source temp_filesselfr//usr/lib/python3.10/distutils/command/config.pyinitialize_options3s zconfig.initialize_optionscCs|jdur |jjp g|_nt|jtr|jtj|_|jdur$g|_n t|jtr/|jg|_|jdur9g|_dSt|jtrI|jtj|_dSdSN) r distribution isinstancestrsplitospathseprrrrrrfinalize_optionsBs        zconfig.finalize_optionscCsdSrrrrrrrunRsz config.runcCsddlm}m}t|j|s=||j|jdd|_t|j|jr'|j|j|j r1|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%rrr&rrset_include_dirsr set_librariesrset_library_dirs)rr$r%rrr_check_compilerYs  zconfig._check_compilercCsdt|}t|d4}|r|D] }|d|q|d|||ddkr7|dWd|SWd|S1sBwY|S)N _configtestwz#include <%s>  )LANG_EXTopenwrite)rbodyheaderslangfilenamefileheaderrrr_gen_temp_sourcefileks        zconfig._gen_temp_sourcefilecCs<||||}d}|j||g|jj|||d||fS)Nz _configtest.ir)r:rextendr preprocess)rr4r5rr6srcoutrrr _preprocessws zconfig._preprocesscCs\||||}|jrt|d||j|g\}|j||g|jj|g|d||fS)Nzcompiling '%s':r;)r:r dump_filerobject_filenamesrr<compile)rr4r5rr6r>objrrr_compile~szconfig._compilec Csr|||||\}}tjtj|d} |jj|g| |||d|jjdur.| |jj} |j | ||| fS)Nr)rr target_lang) rEr pathsplitextbasenamerlink_executable exe_extensionrappend) rr4r5rrrr6r>rDprogrrr_links     z config._linkc GsP|s|j}g|_tdd||D]}zt|Wqty%YqwdS)Nz removing: %s )rrinfojoinr removeOSError)r filenamesr7rrr_cleans z config._cleanNrcCsPddlm}|d}z |||||Wn |y!d}Ynw||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(rWr,r@rUrr4r5rr6rWokrrrtry_cpps  zconfig.try_cppc Cs||||||\}}t|trt|}t|}d} |} | dkr)n || r1d} nq Wdn1sr?r8matchlinerrr search_cpps$      zconfig.search_cppcCsbddlm}|z |||||d}Wn |y!d}Ynwt|r(dp)d||S)zwTry to compile a source file built from 'body' and 'headers'. Return true on success, false otherwise. rrVTFsuccess!failure.)r(rWr,rErrPrUrXrrr try_compiles  zconfig.try_compilec Csnddlm}m}|z|||||||d} Wn ||fy'd} Ynwt| r.dp/d|| S)zTry to compile and link a source file, built from 'body' and 'headers', to executable form. Return true on success, false otherwise. rrW LinkErrorTFrcrd)r(rWrgr,rNrrPrU) rr4r5rrrr6rWrgrYrrrtry_links zconfig.try_linkc Csddlm}m}|z|||||||\} } } || gd} Wn||tfy1d} Ynwt| r8dp9d| | S)zTry to compile, link to an executable, and run a program built from 'body' and 'headers'. Return true on success, false otherwise. rrfTFrcrd) r(rWrgr,rNspawnrrrPrU) rr4r5rrrr6rWrgr>rDexerYrrrtry_runs  zconfig.try_runrc Cst|g}|r|d||d|r|d|n|d||dd|d}||||||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;}r/)r,rLrQrh) rfuncr5rrrdeclcallr4rrr check_funcs   zconfig.check_funccCs ||d|||g||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) { })r,rh)rlibraryrr5rother_librariesrrr check_lib4s  zconfig.check_libcCs|jd|g|dS)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 */)r4r5r)rZ)rr9rrr6rrr check_headerBs zconfig.check_header)NNNr)NNr)NNNNr)NNNNrr)__name__ __module__ __qualname__ description user_optionsrr"r#r,r:r@rErNrUrZrbrerhrkrprsrtrrrrrs@        rcCsP|dur td|nt|t|}zt|W|dS|w)zjDumps a file content into log.info. If head is not None, will be dumped before the file content. Nz%s)rrPr2readclose)r7headr8rrrrAKs rAr)__doc__r r\distutils.corerdistutils.errorsrdistutils.sysconfigr distutilsrr1rrArrrrs     8