o _aC@sdZddlZddlZddlZddlmZmZmZddlZddl Z ddl m Z ddl mZddlmZmZmZmZddl mZddlmZd d ZGd d d e ZGd ddeZdZdZdZddZedZddZ ddZ!ddZ"dS)adistutils.cygwinccompiler Provides the CygwinCCompiler class, a subclass of UnixCCompiler that handles the Cygwin port of the GNU C compiler to Windows. It also contains the Mingw32CCompiler class which handles the mingw32 port of GCC (same as cygwin in no-cygwin mode). N)PopenPIPE check_output) UnixCCompiler) write_file)DistutilsExecErrorCCompilerError CompileErrorUnknownFileError) LooseVersion)find_executablecCstjd}|dkr\tj|d|d}|dkrdgS|dkr#dgS|d kr*d gS|d kr1d gS|d kr8dgS|dkr?dgS|dkrFdgSdt|krUdkrVddgStd|dS)zaInclude the appropriate MSVC runtime library if Python was built with MSVC 7.0 or later. zMSC v. 1300msvcr701310msvcr711400msvcr801500msvcr901600msvcr1001700msvcr1101800msvcr120iliucrt vcruntime140zUnknown MS Compiler version %s N)sysversionfindint ValueError)msc_posmsc_verr'G/usr/lib/python3/dist-packages/setuptools/_distutils/cygwinccompiler.py get_msvcr@s,  r)c@sZeZdZdZdZdZdZdZdZdZ dZ dd d Z d d Z    dddZ dddZdS)CygwinCCompilerz? Handles the Cygwin port of the GNU C compiler to Windows. cygwinz.o.az.dllzlib%s%sz%s%sz.exercCsFt||||t\}}|d||f|tur!|d|tjdd|_ tjdd|_ d|j vrgt \|_ |_ |_||jd|j |j |jf|j dkrY|j |_nd |_|j d krdd }n d }n|j |_d }|jd |j d|j d |j d|j d|j|fdd|j vr|j dkrdg|_|ddSt|_dS)Nz%Python's GCC status: %s (details: %s)zPython's pyconfig.h doesn't seem to support your compiler. Reason: %s. Compiling may fail because of undefined preprocessor macros.CCgccCXXzg++z: gcc %s, ld %s, dllwrap %s z2.10.90dllwrap2.13-shared -mdll -staticz%s -mcygwin -O -Wallz%s -mcygwin -mdll -O -Wallz %s -mcygwinz%s -mcygwin %scompiler compiler_so compiler_cxx linker_exe linker_so2.91.57msvcrtz,Consider upgrading to a newer version of gcc)r__init__check_config_h debug_print CONFIG_H_OKwarnosenvirongetcccxx get_versions gcc_version ld_versiondllwrap_version compiler_type linker_dllset_executables dll_librariesr))selfverbosedry_runforcestatusdetails shared_optionr'r'r(r<nsX       zCygwinCCompiler.__init__c Cs|dks|dkr&z |dd|d|gWdSty%}zt|d}~wwz||j||d|g|WdStyH}zt|d}~ww)z:Compiles the source by spawning GCC and windres if needed..rc.reswindresz-iz-oN)spawnrr r6)rNobjsrcextcc_argsextra_postargspp_optsmsgr'r'r(_compiles zCygwinCCompiler._compileNcCsHt| pg} t|p g}t|pg}||j|dur||jks)|jdkrtj|d}tjtj |\}}tj ||d}tj |d|d}dtj |dg}|D]}| |q]| t ||fd ||jd kr| d |g| d |gn| || s| d t||||||||d| | | | | dS)zLink the objects.Nr.rz.deflibr,z LIBRARY %sEXPORTSz writing %sr0z --output-libz--defz-s)copyextendrM EXECUTABLErKrApathdirnamesplitextbasenamejoinappendexecuterrlink)rN target_descobjectsoutput_filename output_dir libraries library_dirsruntime_library_dirsexport_symbolsdebug extra_preargsr] build_temp target_langtemp_dirdll_name dll_extensiondef_filelib_filecontentssymr'r'r(rmsB         zCygwinCCompiler.linkcCs|durd}g}|D]H}tjtj|\}}||jddgvr)td||f|r1tj|}|dvrE|tj||||j q |tj|||j q |S)z#Adds supports for rc and res files.NrrUrVz"unknown file type '%s' (from '%s'))rVrU) rArfrhnormcasesrc_extensionsr rirkrj obj_extension)rNsource_filenames strip_dirrq obj_namessrc_namebaser[r'r'r(object_filenames s&    z CygwinCCompiler.object_filenamesrrr) NNNNNrNNNN)rr)__name__ __module__ __qualname____doc__rJrstatic_lib_extensionshared_lib_extensionstatic_lib_formatshared_lib_format exe_extensionr<r`rmrr'r'r'r(r*cs" @ Nr*c@seZdZdZdZdddZdS)Mingw32CCompilerz@ Handles the Mingw32 port of the GNU C compiler to Windows. mingw32rc Cst||||d|jvr|jdkrd}nd}d|jvr$|jdkr$d}nd}t|jr/td|jd |jd |jd |jd |jd |j ||fd g|_ t |_ dS)Nr.r1r3r2r:z--entry _DllMain@12rz1Cygwin gcc cannot be used with --compiler=mingw32z %s -O -Wallz%s -mdll -O -Wallz%sz%s %s %sr4) r*r<rDrHrG is_cygwinccrrLrErKrMr))rNrOrPrQrT entry_pointr'r'r(r<'s.   zMingw32CCompiler.__init__Nr)rrrrrJr<r'r'r'r(r"srokznot ok uncertainc Csddlm}dtjvrtdfSdtjvrtdfS|}z(t|}zd|vr4td|fW|WSt d |fW|WS|wt y_}zt d ||j ffWYd }~Sd }~ww) awCheck if the current Python installation appears amenable to building extensions with GCC. Returns a tuple (status, details), where 'status' is one of the following constants: - CONFIG_H_OK: all is well, go ahead and compile - CONFIG_H_NOTOK: doesn't look good - CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h 'details' is a human-readable string explaining the situation. Note there are two ways to conclude "OK": either 'sys.version' contains the string "GCC" (implying that this Python was built with GCC), or the installed "pyconfig.h" contains the string "__GNUC__". r) sysconfigGCCzsys.version mentions 'GCC'Clangzsys.version mentions 'Clang'__GNUC__z'%s' mentions '__GNUC__'z '%s' does not mention '__GNUC__'zcouldn't read '%s': %sN) distutilsrr r!r?get_config_h_filenameopenreadcloseCONFIG_H_NOTOKOSErrorCONFIG_H_UNCERTAINstrerror)rfnconfig_hexcr'r'r(r=Ws(        r=s(\d+\.\d+(\.\d+)*)cCs|d}t|durdSt|dtdj}z |}W|n|wt|}|dur1dS| d }t j t|WdS1sLwYdS)zFind the version of an executable by running `cmd` in the shell. If the command is not found, or the output does not match `RE_VERSION`, returns None. rNT)shellstdout)splitr rrrrr RE_VERSIONsearchgroupdecoderr!suppress_known_deprecationr )cmd executableout out_stringresultver_strr'r'r(_find_exe_versions     $rcCsgd}tdd|DS)zg Try to find out the versions of gcc, ld and dllwrap. If not possible it returns None for it. )zgcc -dumpversionzld -vzdllwrap --versioncSsg|]}t|qSr')r).0rr'r'r( sz get_versions..)tuple)commandsr'r'r(rFsrFcCst|dg}|dS)zCTry to determine if the compiler that would be used is from cygwin.z -dumpmachinescygwin)rstripendswith)rDrr'r'r(rs r)#rrAr rc subprocessrrrredistutils.versionrdistutils.unixccompilerrdistutils.file_utilrdistutils.errorsrrr r r distutils.spawnr r)r*rr?rrr=compilerrrFrr'r'r'r(s01    #@1 /