ž «ÿf$3c@s§dZddlZddlZddlZddlmZddlmZddlm Z ddl m Z idd6d d 6Z Gd d „d eƒZ ed d„ZdS(uêdistutils.command.config Implements the Distutils 'config' command, a (mostly) empty command class that exists mainly to be sub-classed by specific module distributions and applications. The idea is that while every "config" command is different, at least they're all named the same, and users always see "config" in the list of standard commands. Also, this is a good place to put common configure-like tasks: "try to compile this C code", or "figure out where this header file lives". iN(uCommand(uDistutilsExecError(ucustomize_compiler(ulogu.cucu.cxxuc++c Bsm|EeZdZdZd>d?d@dAdBdCdDdEdFg Zdd„Zdd„Zdd„Zdd „Z d!d"„Z d#d$„Z d%d&„Z d'd(„Z d)d*„Zd=d=d=d+d,d-„Zd=d=d=d+d.d/„Zd=d=d+d0d1„Zd=d=d=d=d+d2d3„Zd=d=d=d=d+d4d5„Zd=d=d=d=d6d6d7d8„Zd=d=d=gd9d:„Zd=d=d+d;d<„Zd=S(Guconfiguprepare to buildu compiler=uspecify the compiler typeucc=uspecify the compiler executableu include-dirs=uIu.list of directories to search for header filesudefine=uDuC preprocessor macros to defineuundef=uUu!C preprocessor macros to undefineu libraries=ulu!external C libraries to link withu library-dirs=uLu.directories to search for external C librariesunoisyu1show every action (compile, link, run, ...) takenu dump-sourceu=dump generated source files before attempting to compile themcCsLd|_d|_d|_d|_d|_d|_d|_g|_dS(Ni( uNoneucompileruccu include_dirsu librariesu library_dirsunoisyu dump_sourceu temp_files(uself((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyuinitialize_options3s       uconfig.initialize_optionscCsß|jdkr'|jjpg|_n-t|jtƒrT|jjtjƒ|_n|jdkrog|_n$t|jtƒr“|jg|_n|j dkr®g|_ n-t|j tƒrÛ|j jtjƒ|_ ndS(N( u include_dirsuNoneu distributionu isinstanceustrusplituosupathsepu librariesu library_dirs(uself((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyufinalize_optionsBs  uconfig.finalize_optionscCsdS(N((uself((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyurunRsu config.runcCs½ddlm}m}t|j|ƒs¹|d|jd|jddƒ|_t|jƒ|jrx|jj|jƒn|j r—|jj |j ƒn|j r¹|jj |j ƒq¹ndS(u^Check that 'self.compiler' really is a CCompiler object; if not, make it one. i(u CCompileru new_compilerucompilerudry_runuforceiN( udistutils.ccompileru CCompileru new_compileru isinstanceucompilerudry_runucustomize_compileru include_dirsuset_include_dirsu librariesu set_librariesu library_dirsuset_library_dirs(uselfu CCompileru new_compiler((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu_check_compilerYs    uconfig._check_compilercCsdt|}t|dƒ}|rUx|D]}|jd|ƒq*W|jdƒn|j|ƒ|ddkr‚|jdƒn|jƒ|S(Nu _configtestuwu#include <%s> u iiÿÿÿÿ(uLANG_EXTuopenuwriteuclose(uselfubodyuheadersulangufilenameufileuheader((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu_gen_temp_sourcefileks   uconfig._gen_temp_sourcefilecCsT|j|||ƒ}d}|jj||gƒ|jj||d|ƒ||fS(Nu _configtest.iu include_dirs(u_gen_temp_sourcefileu temp_filesuextenducompileru preprocess(uselfubodyuheadersu include_dirsulangusrcuout((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu _preprocessxs uconfig._preprocesscCsƒ|j|||ƒ}|jr2t|d|ƒn|jj|gƒ\}|jj||gƒ|jj|gd|ƒ||fS(Nucompiling '%s':u include_dirs(u_gen_temp_sourcefileu dump_sourceu dump_fileucompileruobject_filenamesu temp_filesuextenducompile(uselfubodyuheadersu include_dirsulangusrcuobj((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu_compiles uconfig._compilec Csª|j||||ƒ\}}tjjtjj|ƒƒd} |jj|g| d|d|d|ƒ|jjdk r| |jj} n|j j | ƒ||| fS(Niu librariesu library_dirsu target_lang( u_compileuosupathusplitextubasenameucompilerulink_executableu exe_extensionuNoneu temp_filesuappend( uselfubodyuheadersu include_dirsu librariesu library_dirsulangusrcuobjuprog((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu_linkˆs"u config._linkc Gso|s|j}g|_ntjddj|ƒƒx4|D],}ytj|ƒWq;tk rfYq;Xq;WdS(Nu removing: %su (u temp_filesuloguinfoujoinuosuremoveuOSError(uselfu filenamesufilename((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu_clean—s    u config._cleanucc Cscddlm}|jƒd}y|j||||ƒWn|k rTd}YnX|jƒ|S(uQConstruct a source file from 'body' (a string containing lines of C/C++ code) and 'headers' (a list of header files to include) and run it through the preprocessor. Return true if the preprocessor succeeded, false if there were any errors. ('body' probably isn't of much use, but what the heck.) i(u CompileErrorTF(udistutils.ccompileru CompileErroru_check_compileruTrueu _preprocessuFalseu_clean(uselfubodyuheadersu include_dirsulangu CompileErroruok((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyutry_cpp­s    uconfig.try_cppc Cs®|jƒ|j||||ƒ\}}t|tƒrItj|ƒ}nt|ƒ}d} x8|jƒ} | dkrzPn|j | ƒr^d} Pq^q^|j ƒ|j ƒ| S(u´Construct a source file (just like 'try_cpp()'), run it through the preprocessor, and return true if any line of the output matches 'pattern'. 'pattern' should either be a compiled regex object or a string containing a regex. If both 'body' and 'headers' are None, preprocesses an empty file -- which can be useful to determine the symbols the preprocessor and compiler set by default. uFT( u_check_compileru _preprocessu isinstanceustrureucompileuopenuFalseureadlineusearchuTrueucloseu_clean( uselfupatternubodyuheadersu include_dirsulangusrcuoutufileumatchuline((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu search_cpp¿s      uconfig.search_cppc Cs|ddlm}|jƒy |j||||ƒd}Wn|k rTd}YnXtj|rgdpjdƒ|jƒ|S(uwTry to compile a source file built from 'body' and 'headers'. Return true on success, false otherwise. i(u CompileErrorusuccess!ufailure.TF( udistutils.ccompileru CompileErroru_check_compileru_compileuTrueuFalseuloguinfou_clean(uselfubodyuheadersu include_dirsulangu CompileErroruok((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu try_compileÜs     uconfig.try_compilec CsŽddlm}m}|jƒy&|j||||||ƒd} Wn||fk rfd} YnXtj| rydp|dƒ|j ƒ| S(užTry to compile and link a source file, built from 'body' and 'headers', to executable form. Return true on success, false otherwise. i(u CompileErroru LinkErrorusuccess!ufailure.TF( udistutils.ccompileru CompileErroru LinkErroru_check_compileru_linkuTrueuFalseuloguinfou_clean( uselfubodyuheadersu include_dirsu librariesu library_dirsulangu CompileErroru LinkErroruok((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyutry_linkìs     uconfig.try_linkc Cs¬ddlm}m}|jƒyA|j||||||ƒ\} } } |j| gƒd} Wn!||tfk r„d} YnXt j | r—dpšdƒ|j ƒ| S(uœTry to compile, link to an executable, and run a program built from 'body' and 'headers'. Return true on success, false otherwise. i(u CompileErroru LinkErrorusuccess!ufailure.TF( udistutils.ccompileru CompileErroru LinkErroru_check_compileru_linkuspawnuTrueuDistutilsExecErroruFalseuloguinfou_clean( uselfubodyuheadersu include_dirsu librariesu library_dirsulangu CompileErroru LinkErrorusrcuobjuexeuok((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyutry_runÿs    uconfig.try_runic Cs›|jƒg}|r*|jd|ƒn|jdƒ|rQ|jd|ƒn|jd|ƒ|jdƒdj|ƒd}|j|||||ƒS(uÛDetermine if function 'func' is available by constructing a source file that refers to 'func', and compiles and links it. If everything succeeds, returns true; otherwise returns false. The constructed source file starts out by including the header files listed in 'headers'. If 'decl' is true, it then declares 'func' (as "int func()"); you probably shouldn't supply 'headers' and set 'decl' true in the same call, or you might get errors about a conflicting declarations for 'func'. Finally, the constructed 'main()' function either references 'func' or (if 'call' is true) calls it. 'libraries' and 'library_dirs' are used when linking. u int %s ();u int main () {u %s();u %s;u}u (u_check_compileruappendujoinutry_link( uselfufuncuheadersu include_dirsu librariesu library_dirsudeclucallubody((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu check_funcs   uconfig.check_funccCs*|jƒ|jd|||g||ƒS(uáDetermine if 'library' is available to be linked against, without actually checking that any particular symbols are provided by it. 'headers' will be used in constructing the source file to be compiled, but the only effect of this is to check if all the header files listed are available. Any libraries listed in 'other_libraries' will be included in the link, in case 'library' has symbols that depend on other libraries. uint main (void) { }(u_check_compilerutry_link(uselfulibraryu library_dirsuheadersu include_dirsuother_libraries((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu check_lib6s uconfig.check_libcCs|jddd|gd|ƒS(u¤Determine if the system header file named by 'header_file' exists and can be found by the preprocessor; return true if so, false otherwise. ubodyu /* No body */uheadersu include_dirs(utry_cpp(uselfuheaderu include_dirsu library_dirsulang((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu check_headerDsuconfig.check_headerN(u compiler=Nuspecify the compiler type(ucc=Nuspecify the compiler executable(u include-dirs=uIu.list of directories to search for header files(udefine=uDuC preprocessor macros to define(uundef=uUu!C preprocessor macros to undefine(u libraries=ulu!external C libraries to link with(u library-dirs=uLu.directories to search for external C libraries(unoisyNu1show every action (compile, link, run, ...) taken(u dump-sourceNu=dump generated source files before attempting to compile them(u__name__u __module__u __qualname__u descriptionuNoneu user_optionsuinitialize_optionsufinalize_optionsurunu_check_compileru_gen_temp_sourcefileu _preprocessu_compileu_linku_cleanutry_cppu search_cppu try_compileutry_linkutry_runu check_funcu check_libu check_header(u __locals__((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyuconfigsT            uconfigc Csb|dkr tjd|ƒn tj|ƒt|ƒ}ztj|jƒƒWd|jƒXdS(ujDumps a file content into log.info. If head is not None, will be dumped before the file content. u%sN(uNoneuloguinfouopenureaduclose(ufilenameuheadufile((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu dump_fileNs   u dump_file(u__doc__usysuosureudistutils.coreuCommandudistutils.errorsuDistutilsExecErrorudistutils.sysconfigucustomize_compileru distutilsuloguLANG_EXTuconfiguNoneu dump_file(((u=/opt/alt/python33/lib64/python3.3/distutils/command/config.pyu s$ÿ: