U e5d=3@shddlZddlZddlmZddlmZddlmZddlm Z dddZ Gd d d eZ d d d Z dS)N)Command)DistutilsExecError)customize_compiler)logz.cz.cxx)czc++c @seZdZdZdddddddd d g Zd d Zd dZddZddZddZ ddZ ddZ ddZ ddZ d0dd Zd1d!d"Zd2d#d$Zd3d%d&Zd4d'd(Zd5d*d+Zdddgfd,d-Zd6d.d/ZdS)7configzprepare 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)compilerZcc include_dirs libraries library_dirsr dump_source temp_filesselfr0/usr/lib64/python3.8/distutils/command/config.pyinitialize_options3szconfig.initialize_optionscCs|jdkr|jjpg|_nt|jtr6|jtj|_|jdkrHg|_nt|jtr^|jg|_|jdkrpg|_nt|jtr|jtj|_dSN) rZ distribution isinstancestrsplitospathseprrrrrrfinalize_optionsBs       zconfig.finalize_optionscCsdSrrrrrrrunRsz config.runcCszddlm}m}t|j|sv||j|jdd|_t|j|jrN|j|j|j rb|j |j |j rv|j |j dS)Nr) CCompiler new_compilerr)rdry_runZforce) distutils.ccompilerr"r#rrr$rrZset_include_dirsrZ set_librariesrZset_library_dirs)rr"r#rrr_check_compilerYs  zconfig._check_compilerc Csldt|}t|dL}|r>|D]}|d|q |d|||ddkr^|dW5QRX|S)NZ _configtestwz#include <%s>  )LANG_EXTopenwrite)rbodyheaderslangfilenamefileheaderrrr_gen_temp_sourcefileks     zconfig._gen_temp_sourcefilecCs<||||}d}|j||g|jj|||d||fS)Nz _configtest.ir)r3rextendrZ preprocess)rr-r.rr/srcoutrrr _preprocessws zconfig._preprocesscCs\||||}|jr"t|d||j|g\}|j||g|jj|g|d||fS)Nzcompiling '%s':r4)r3r dump_filerZobject_filenamesrr5compile)rr-r.rr/r6objrrr_compile~szconfig._compilec Csr|||||\}}tjtj|d} |jj|g| |||d|jjdk r\| |jj} |j | ||| fS)Nr)rrZ target_lang) r<rpathsplitextbasenamerZlink_executableZ exe_extensionrappend) rr-r.rrrr/r6r;progrrr_links    z config._linkc GsT|s|j}g|_tdd||D](}zt|Wq&tk rLYq&Xq&dS)Nz removing: %s )rrinfojoinrremoveOSError)r filenamesr0rrr_cleansz config._cleanNrcCsRddlm}|d}z|||||Wn|k rDd}YnX||S)Nr CompileErrorTF)r%rKr&r8rIrr-r.rr/rKokrrrtry_cpps  zconfig.try_cppc Csx||||||\}}t|tr0t|}t|.}d} |} | dkrPqb|| r>d} qbq>W5QRX| | S)NFT) r&r8rrrer:r+readlinesearchrI) rpatternr-r.rr/r6r7r1matchlinerrr search_cpps     zconfig.search_cppcCsdddlm}|z|||||d}Wn|k rDd}YnXt|rRdpTd||S)NrrJTFsuccess!failure.)r%rKr&r<rrDrIrLrrr try_compiles  zconfig.try_compilec Cspddlm}m}|z|||||||d} Wn||fk rPd} YnXt| r^dp`d|| SNr)rK LinkErrorTFrWrX)r%rKr[r&rBrrDrI) rr-r.rrrr/rKr[rMrrrtry_links  zconfig.try_linkc Csddlm}m}|z.|||||||\} } } || gd} Wn||tfk rdd} YnXt| rrdptd| | SrZ) r%rKr[r&rBZspawnrrrDrI) rr-r.rrrr/rKr[r6r;ZexerMrrrtry_runs    zconfig.try_runrc Cst|g}|r|d||d|r<|d|n|d||dd|d}||||||S)Nz int %s ();z int main () {z %s();z %s;}r()r&r@rEr\) rfuncr.rrrZdeclZcallr-rrr check_funcs   zconfig.check_funccCs ||d|||g||S)Nzint main (void) { })r&r\)rZlibraryrr.rZother_librariesrrr check_lib4s  zconfig.check_libcCs|jd|g|dS)Nz /* No body */)r-r.r)rN)rr2rrr/rrr check_headerBs zconfig.check_header)NNNr)NNNr)NNr)NNNNr)NNNNr)NNNNrr)NNr)__name__ __module__ __qualname__Z descriptionZ user_optionsrr r!r&r3r8r<rBrIrNrVrYr\r]r`rarbrrrrrs\         rcCsJ|dkrtd|n t|t|}zt|W5|XdS)Nz%s)rrDr+closeread)r0headr1rrrr9Ks r9)N) rrPZdistutils.corerZdistutils.errorsrZdistutils.sysconfigrZ distutilsrr*rr9rrrr s     8