U e5d=3ã@shddlZddlZddlmZddlmZddlmZddlm Z dddœZ Gd d „d eƒZ d d d „Z dS)éN)ÚCommand)ÚDistutilsExecError)Úcustomize_compiler)Úlogz.cz.cxx)Úczc++c @sÆeZdZdZdddddddd d g Zd d „Zd d„Zdd„Zdd„Zdd„Z dd„Z dd„Z dd„Z dd„Z d0dd „Zd1d!d"„Zd2d#d$„Zd3d%d&„Zd4d'd(„Zd5d*d+„Zdddgfd,d-„Zd6d.d/„ZdS)7Ú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é)ÚcompilerZccÚ include_dirsÚ librariesÚ library_dirsr Ú dump_sourceÚ temp_files©Úself©rú0/usr/lib64/python3.8/distutils/command/config.pyÚinitialize_options3szconfig.initialize_optionscCs�|jdkr|jjpg|_nt|jtƒr6|j tj¡|_|jdkrHg|_nt|jtƒr^|jg|_|jdkrpg|_nt|jtƒrŒ|j tj¡|_dS©N) rZ distributionÚ isinstanceÚstrÚsplitÚosÚpathseprrrrrrÚfinalize_optionsBs       zconfig.finalize_optionscCsdSrrrrrrÚrunRsz 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)rÚdry_runZforce) Údistutils.ccompilerr"r#rrr$rrZset_include_dirsrZ set_librariesrZset_library_dirs)rr"r#rrrÚ_check_compilerYs ÿ zconfig._check_compilerc Csldt|}t|dƒ�L}|r>|D]}| d|¡q | d¡| |¡|ddkr^| d¡W5QRX|S)NZ _configtestÚwz#include <%s> Ú éÿÿÿÿ)ÚLANG_EXTÚopenÚwrite)rÚbodyÚheadersÚlangÚfilenameÚfileÚheaderrrrÚ_gen_temp_sourcefileks     zconfig._gen_temp_sourcefilecCs<| |||¡}d}|j ||g¡|jj|||d�||fS)Nz _configtest.i©r)r3rÚextendrZ preprocess)rr-r.rr/ÚsrcÚoutrrrÚ _preprocessws zconfig._preprocesscCs\| |||¡}|jr"t|d|ƒ|j |g¡\}|j ||g¡|jj|g|d�||fS)Nzcompiling '%s':r4)r3rÚ dump_filerZobject_filenamesrr5Úcompile)rr-r.rr/r6ÚobjrrrÚ_compile~szconfig._compilec Csr| ||||¡\}}tj tj |¡¡d} |jj|g| |||d�|jjdk r\| |jj} |j  | ¡||| fS)Nr)rrZ target_lang) r<rÚpathÚsplitextÚbasenamerZlink_executableZ exe_extensionrÚappend) rr-r.rrrr/r6r;ÚprogrrrÚ_link‡s ý   z config._linkc GsT|s|j}g|_t dd |¡¡|D](}zt |¡Wq&tk rLYq&Xq&dS)Nz removing: %sú )rrÚinfoÚjoinrÚremoveÚOSError)rÚ filenamesr0rrrÚ_clean–sz config._cleanNrcCsRddlm}| ¡d}z| ||||¡Wn|k rDd}YnX| ¡|S)Nr©Ú CompileErrorTF)r%rKr&r8rI©rr-r.rr/rKÚokrrrÚtry_cpp¬s  zconfig.try_cppc Csx| ¡| ||||¡\}}t|tƒr0t |¡}t|ƒ�.}d} | ¡} | dkrPqb| | ¡r>d} qbq>W5QRX|  ¡| S)NFÚT) r&r8rrÚrer:r+ÚreadlineÚsearchrI) rÚpatternr-r.rr/r6r7r1ÚmatchÚlinerrrÚ search_cpp¾s     zconfig.search_cppcCsdddlm}| ¡z| ||||¡d}Wn|k rDd}YnXt |rRdpTd¡| ¡|S)NrrJTFúsuccess!úfailure.)r%rKr&r<rrDrIrLrrrÚ try_compileÚs  zconfig.try_compilec Cspddlm}m}| ¡z| ||||||¡d} Wn||fk rPd} YnXt | r^dp`d¡| ¡| S©Nr)rKÚ LinkErrorTFrWrX)r%rKr[r&rBrrDrI) rr-r.rrrr/rKr[rMrrrÚtry_linkês ÿ zconfig.try_linkc Cs„ddlm}m}| ¡z.| ||||||¡\} } } | | g¡d} Wn||tfk rdd} YnXt | rrdptd¡|  ¡| SrZ) r%rKr[r&rBZspawnrrrDrI) rr-r.rrrr/rKr[r6r;ZexerMrrrÚtry_runýs ÿ   zconfig.try_runrc Cst| ¡g}|r| d|¡| d¡|r<| d|¡n| d|¡| d¡d |¡d}| |||||¡S)Nz int %s ();z int main () {z %s();z %s;ú}r()r&r@rEr\) rÚfuncr.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|d�S)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|dkrt d|¡n t |¡t|ƒ}zt | ¡¡W5| ¡XdS)Nz%s)rrDr+ÚcloseÚread)r0Úheadr1rrrr9Ks r9)N) rrPZdistutils.corerZdistutils.errorsrZdistutils.sysconfigrZ distutilsrr*rr9rrrrÚ s     8