a  ze=3@shddlZddlZddlmZddlmZddlmZddlm Z dddZ Gd d d eZ d d d Z dS)N)Command)DistutilsExecError)customize_compiler)logz.cz.cxx)czc++c@seZdZdZgdZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ d(ddZd)ddZd*ddZd+ddZd,dd Zd-d"d#Zdddgfd$d%Zd.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)compilerZcc include_dirs libraries library_dirsr dump_source temp_filesselfrL/opt/bitninja-python-dojo/embedded/lib/python3.9/distutils/command/config.pyinitialize_options3szconfig.initialize_optionscCs|jdur|jjpg|_nt|jtr6|jtj|_|jdurHg|_nt|jtr^|jg|_|jdurpg|_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_runforce) distutils.ccompilerr"r#rrr$rrZset_include_dirsrZ set_librariesrZset_library_dirs)rr"r#rrr_check_compilerYs  zconfig._check_compilercCsdt|}t|dV}|r>|D]}|d|q |d|||ddkr^|dWdn1sr0Y|S)NZ _configtestwz#include <%s>  )LANG_EXTopenwrite)rbodyheaderslangfilenamefileheaderrrr_gen_temp_sourcefileks     (zconfig._gen_temp_sourcefilecCs<||||}d}|j||g|jj|||d||fS)Nz _configtest.ir)r4rextendrZ preprocess)rr.r/rr0srcoutrrr _preprocessws zconfig._preprocesscCs\||||}|jr"t|d||j|g\}|j||g|jj|g|d||fS)Nzcompiling '%s':r5)r4r dump_filerZobject_filenamesrr6compile)rr.r/rr0r7objrrr_compile~szconfig._compilec Csr|||||\}}tjtj|d} |jj|g| |||d|jjdur\| |jj} |j | ||| fS)Nr)rrZ target_lang) r=rpathsplitextbasenamerZlink_executableZ exe_extensionrappend) rr.r/rrrr0r7r<progrrr_links    z config._linkc GsR|s|j}g|_tdd||D]&}zt|Wq&tyJYq&0q&dS)Nz removing: %s )rrinfojoinrremoveOSError)r filenamesr1rrr_cleans z config._cleanNrcCsPddlm}|d}z|||||Wn|yBd}Yn0||S)Nr CompileErrorTF)r&rLr'r9rJrr.r/rr0rLokrrrtry_cpps   zconfig.try_cppc Cs||||||\}}t|tr0t|}t|8}d} |} | dkrPqb|| r>d} qbq>Wdn1sv0Y| | S)NFT) r'r9rrrer;r,readlinesearchrJ) rpatternr.r/rr0r7r8r2matchlinerrr search_cpps     "zconfig.search_cppcCsbddlm}|z|||||d}Wn|yBd}Yn0t|rPdpRd||S)NrrKTFsuccess!failure.)r&rLr'r=rrErJrMrrr try_compiles   zconfig.try_compilec Csnddlm}m}|z|||||||d} Wn||fyNd} Yn0t| r\dp^d|| SNr)rL LinkErrorTFrXrY)r&rLr\r'rCrrErJ) rr.r/rrrr0rLr\rNrrrtry_links  zconfig.try_linkc Csddlm}m}|z.|||||||\} } } || gd} Wn||tfybd} Yn0t| rpdprd| | Sr[) r&rLr\r'rCspawnrrrErJ) rr.r/rrrr0rLr\r7r<ZexerNrrrtry_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'rArFr]) rfuncr/rrrZdeclcallr.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)rO)rr3rrr0rrr check_headerBs zconfig.check_header)NNNr)NNNr)NNr)NNNNr)NNNNr)NNNNrr)NNr)__name__ __module__ __qualname__ descriptionZ user_optionsrr r!r'r4r9r=rCrJrOrWrZr]r_rcrdrerrrrrs>         rcCsR|durtd|n t|t|}zt|W|n |0dS)Nz%s)rrEr,readclose)r1headr2rrrr:Ks r:)N) rrQZdistutils.corerZdistutils.errorsrZdistutils.sysconfigrZ distutilsrr+rr:rrrr s     8