]$3@sddlZddlZddlZddlmZddlmZddlmZddl m Z dddd iZ Gd d d eZ dd d Z dS)N)Command)DistutilsExecError)customize_compiler)logcz.czc++z.cxxc @sieZdZdZd>d?d@dAdBdCdDdEdFg ZddZddZddZd d!Zd"d#Z d$d%Z d&d'Z d(d)Z d*d+Z dddd,d-d.Zdddd,d/d0Zddd,d1d2Zddddd,d3d4Zddddd,d5d6Zddddd7d7d8d9Zdddgd:d;Zddd,d<d=ZdS)Gconfigzprepare to build compiler=Nspecify the compiler typecc=specify the compiler executable include-dirs=I.list of directories to search for header filesdefine=DC preprocessor macros to defineundef=U!C preprocessor macros to undefine libraries=l!external C libraries to link with library-dirs=L.directories to search for external C librariesnoisy1show every action (compile, link, run, ...) taken dump-source=dump generated source files before attempting to compile themcCsLd|_d|_d|_d|_d|_d|_d|_g|_dS)N)compilerZcc include_dirs libraries library_dirsr dump_source temp_files)selfr'+/opt/alt/python35/lib64/python3.5/config.pyinitialize_options3s       zconfig.initialize_optionscCs|jdkr'|jjpg|_n*t|jtrQ|jjtj|_|jdkrlg|_n!t|jtr|jg|_|jdkrg|_n*t|jtr|jjtj|_dS)N) r!Z distribution isinstancestrsplitospathsepr"r#)r&r'r'r(finalize_optionsBs  zconfig.finalize_optionscCsdS)Nr')r&r'r'r(runRsz config.runcCsddlm}m}t|j|s|d|jd|jdd|_t|j|jru|jj|j|j r|jj |j |j r|jj |j dS)Nr) CCompiler new_compilerr dry_runforcer) distutils.ccompilerr1r2r*r r3rr!Zset_include_dirsr"Z set_librariesr#Zset_library_dirs)r&r1r2r'r'r(_check_compilerYs    zconfig._check_compilercCsdt|}t|d}|rRx|D]}|jd|q*W|jd|j||ddkr||jd|j|S)NZ _configtestwz#include <%s>  r)LANG_EXTopenwriteclose)r&bodyheaderslangfilenamefileheaderr'r'r(_gen_temp_sourcefileks     zconfig._gen_temp_sourcefilecCsT|j|||}d}|jj||g|jj||d|||fS)Nz _configtest.ir!)rDr%extendr Z preprocess)r&r>r?r!r@srcoutr'r'r( _preprocessxs zconfig._preprocesscCs|j|||}|jr/t|d||jj|g\}|jj||g|jj|gd|||fS)Nzcompiling '%s':r!)rDr$ dump_filer Zobject_filenamesr%rEcompile)r&r>r?r!r@rFobjr'r'r(_compiles zconfig._compilec Cs|j||||\}}tjjtjj|d} |jj|g| d|d|d||jjdk r| |jj} |jj | ||| fS)Nrr"r#Z target_lang) rLr-pathsplitextbasenamer Zlink_executableZ exe_extensionr%append) r&r>r?r!r"r#r@rFrKprogr'r'r(_links"z config._linkc Gsl|s|j}g|_tjddj|x4|D],}ytj|Wq8tk rcYq8Xq8WdS)Nz removing: %s )r%rinfojoinr-removeOSError)r& filenamesrAr'r'r(_cleans    z config._cleanrc Cscddlm}|jd}y|j||||Wn|k rTd}YnX|j|S)Nr) CompileErrorTF)r5rZr6rHrY)r&r>r?r!r@rZokr'r'r(try_cpps    zconfig.try_cppc Cs|j|j||||\}}t|trFtj|}t|}d} x3|j} | dkrtP|j| r[d} Pq[W|j |j | S)NFT) r6rHr*r+rerJr;readlinesearchr=rY) r&patternr>r?r!r@rFrGrBmatchliner'r'r( search_cpps      zconfig.search_cppc Cs|ddlm}|jy |j||||d}Wn|k rTd}YnXtj|rgdpjd|j|S)Nr)rZTFzsuccess!zfailure.)r5rZr6rLrrTrY)r&r>r?r!r@rZr[r'r'r( try_compiles     zconfig.try_compilec Csddlm}m}|jy&|j||||||d} Wn||fk rfd} YnXtj| rydp|d|j| S)Nr)rZ LinkErrorTFzsuccess!zfailure.)r5rZrfr6rRrrTrY) r&r>r?r!r"r#r@rZrfr[r'r'r(try_links     zconfig.try_linkc Csddlm}m}|jyA|j||||||\} } } |j| gd} Wn!||tfk rd} YnXtj| rdpd|j | S)Nr)rZrfTFzsuccess!zfailure.) r5rZrfr6rRspawnrrrTrY) r&r>r?r!r"r#r@rZrfrFrKZexer[r'r'r(try_runs    zconfig.try_runrc Cs|jg}|r'|jd||jd|rN|jd|n|jd||jddj|d}|j|||||S)Nz int %s ();z int main () {z %s();z %s;}r8)r6rPrUrg) r&funcr?r!r"r#Zdeclcallr>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|jddd|gd|S)Nr>z /* No body */r?r!)r\)r&rCr!r#r@r'r'r( check_headerDszconfig.check_header)rNr )r Nr )r r r)rrr)rrr)rrr)rrr)rNr)rNr)__name__ __module__ __qualname__ descriptionZ user_optionsr)r/r0r6rDrHrLrRrYr\rdrergrirmrnror'r'r'r(rsT             rc Csb|dkr tjd|n tj|t|}ztj|jWd|jXdS)Nz%s)rrTr;readr=)rAheadrBr'r'r(rINs   rI)sysr-r^Zdistutils.corerZdistutils.errorsrZdistutils.sysconfigrZ distutilsrr:rrIr'r'r'r( s$: