3 Õì2a3ã@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ÆeZdZdZd>d?d@dAdBdCdDdEdFg Zdd„Zdd„Zdd„Zd d!„Zd"d#„Z d$d%„Z d&d'„Z d(d)„Z d*d+„Z dGd-d.„ZdHd/d0„ZdId1d2„ZdJd3d4„ZdKd5d6„ZdLd8d9„Zdddgfd:d;„ZdMd Ú réÿÿÿÿ)ÚLANG_EXTÚopenÚwriteÚclose)r&ÚbodyÚheadersÚlangÚfilenameÚfileÚheaderr'r'r(Ú_gen_temp_sourcefileks       zconfig._gen_temp_sourcefilecCs<|j|||ƒ}d}|jj||gƒ|jj|||d�||fS)Nz _configtest.i)r!)rDr%Úextendr Z preprocess)r&r>r?r!r@ÚsrcÚoutr'r'r(Ú _preprocessxs zconfig._preprocesscCs\|j|||ƒ}|jr"t|d|ƒ|jj|gƒ\}|jj||gƒ|jj|g|d�||fS)Nzcompiling '%s':)r!)rDr$Ú dump_filer Zobject_filenamesr%rEÚcompile)r&r>r?r!r@rFÚobjr'r'r(Ú_compileszconfig._compilec Csr|j||||ƒ\}}tjjtjj|ƒƒd} |jj|g| |||d�|jjdk r\| |jj} |jj | ƒ||| fS)Nr)r"r#Z target_lang) rLr-ÚpathÚsplitextÚbasenamer Zlink_executableZ exe_extensionr%Úappend) r&r>r?r!r"r#r@rFrKÚprogr'r'r(Ú_linkˆs    z config._linkc GsX|s|j}g|_tjddj|ƒƒx0|D](}ytj|ƒWq(tk rNYq(Xq(WdS)Nz removing: %sú )r%rÚinfoÚjoinr-ÚremoveÚOSError)r&Ú filenamesrAr'r'r(Ú_clean—s z config._cleanrc CsRddlm}|jƒd}y|j||||ƒWn|k rDd}YnX|jƒ|S)Nr)Ú CompileErrorTF)r5rZr6rHrY)r&r>r?r!r@rZÚokr'r'r(Útry_cpp­s  zconfig.try_cppc Csx|jƒ|j||||ƒ\}}t|tƒr0tj|ƒ}t|ƒ}d} x&|jƒ} | dkrPP|j| ƒr>d} Pq>W|j ƒ|j ƒ| S)NFÚT) r6rHr*r+ÚrerJr;ÚreadlineÚsearchr=rY) r&Úpatternr>r?r!r@rFrGrBÚmatchÚliner'r'r(Ú search_cpp¿s    zconfig.search_cppc Csdddlm}|jƒy|j||||ƒd}Wn|k rDd}YnXtj|rRdpTdƒ|jƒ|S)Nr)rZTFzsuccess!zfailure.)r5rZr6rLrrTrY)r&r>r?r!r@rZr[r'r'r(Ú try_compileÜs  zconfig.try_compilec Cspddlm}m}|jƒy|j||||||ƒd} Wn||fk rPd} YnXtj| r^dp`dƒ|jƒ| S)Nr)rZÚ LinkErrorTFzsuccess!zfailure.)r5rZrfr6rRrrTrY) r&r>r?r!r"r#r@rZrfr[r'r'r(Útry_linkìs   zconfig.try_linkc Cs„ddlm}m}|jƒy.|j||||||ƒ\} } } |j| gƒd} Wn||tfk rdd} YnXtj| rrdptdƒ|j ƒ| S)Nr)rZrfTFzsuccess!zfailure.) r5rZrfr6rRZspawnrrrTrY) r&r>r?r!r"r#r@rZrfrFrKZexer[r'r'r(Útry_runÿs   zconfig.try_runrc Cst|jƒg}|r|jd|ƒ|jdƒ|r<|jd|ƒn|jd|ƒ|jdƒdj|ƒd}|j|||||ƒS)Nz int %s ();z int main () {z %s();z %s;ú}r8)r6rPrUrg) r&Úfuncr?r!r"r#ZdeclZcallr>r'r'r(Ú check_funcs   zconfig.check_funccCs |jƒ|jd|||g||ƒS)Nzint main (void) { })r6rg)r&Zlibraryr#r?r!Zother_librariesr'r'r(Ú check_lib6s  zconfig.check_libcCs|jd|g|d�S)Nz /* No body */)r>r?r!)r\)r&rCr!r#r@r'r'r(Ú check_headerDs zconfig.check_header)rNr )r Nr )r r r)rrr)rrr)rrr)rrr)rNr)rNr)NNNr)NNNr)NNr)NNNNr)NNNNr)NNNNrr)NNr)Ú__name__Ú __module__Ú __qualname__Ú descriptionZ user_optionsr)r/r0r6rDrHrLrRrYr\rdrergrhrkrlrmr'r'r'r(rsT         rc CsJ|dkrtjd|ƒn tj|ƒt|ƒ}ztj|jƒƒWd|jƒXdS)Nz%s)rrTr;Úreadr=)rAÚheadrBr'r'r(rINs rI)N) r-r^Zdistutils.corerZdistutils.errorsrZdistutils.sysconfigrZ distutilsrr:rrIr'r'r'r(Ú s     ;