3 \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Æ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!)rCr%Ú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!)rCr$Ú dump_filer Zobject_filenamesr%rDÚcompile)r&r=r>r!r?rEÚobjr'r'r(Ú_compileszconfig._compilec Csr|j||||ƒ\}}tjjtjj|ƒƒd} |jj|g| |||d�|jjdk r\| |jj} |jj | ƒ||| fS)Nr)r"r#Z target_lang) rKr-ÚpathÚsplitextÚbasenamer Zlink_executableZ exe_extensionr%Úappend) r&r=r>r!r"r#r?rErJÚ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&Ú filenamesr@r'r'r(Ú_clean—s z config._cleanrc CsRddlm}|jƒd}y|j||||ƒWn|k rDd}YnX|jƒ|S)Nr)Ú CompileErrorTF)r4rYr5rGrX)r&r=r>r!r?rYÚ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) r5rGr*r+ÚrerIr:ÚreadlineÚsearchr<rX) r&Úpatternr=r>r!r?rErFrAÚmatchÚliner'r'r(Ú search_cpp¿s    zconfig.search_cppc Csdddlm}|jƒy|j||||ƒd}Wn|k rDd}YnXtj|rRdpTdƒ|jƒ|S)Nr)rYTFzsuccess!zfailure.)r4rYr5rKrrSrX)r&r=r>r!r?rYrZr'r'r(Ú try_compileÜs  zconfig.try_compilec Cspddlm}m}|jƒy|j||||||ƒd} Wn||fk rPd} YnXtj| r^dp`dƒ|jƒ| S)Nr)rYÚ LinkErrorTFzsuccess!zfailure.)r4rYrer5rQrrSrX) r&r=r>r!r"r#r?rYrerZr'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)rYreTFzsuccess!zfailure.) r4rYrer5rQZspawnrrrSrX) r&r=r>r!r"r#r?rYrerErJZexerZr'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;ú}r7)r5rOrTrf) r&Úfuncr>r!r"r#ZdeclZcallr=r'r'r(Ú check_funcs   zconfig.check_funccCs |jƒ|jd|||g||ƒS)Nzint main (void) { })r5rf)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&rBr!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__Z descriptionZ user_optionsr)r/r0r5rCrGrKrQrXr[rcrdrfrgrjrkrlr'r'r'r(rsT         rc CsJ|dkrtjd|ƒn tj|ƒt|ƒ}ztj|jƒƒWd|jƒXdS)Nz%s)rrSr:Úreadr<)r@ÚheadrAr'r'r(rHNs rH)N) r-r]Zdistutils.corerZdistutils.errorsrZdistutils.sysconfigrZ distutilsrr9rrHr'r'r'r(Ú s     ;