o )a*B@sdZddlZddlZddlZddlmZmZmZddlZddl m Z ddl m Z ddl mZmZmZmZddlmZddlmZd d ZGd d d e ZGd ddeZdZdZdZddZedZddZddZ 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 kr8dgStd|dS)zaInclude the appropriate MSVC runtime library if Python was built with MSVC 7.0 or later. zMSC v. Z1300Zmsvcr70Z1310Zmsvcr71Z1400Zmsvcr80Z1500Zmsvcr90Z1600Zmsvcr100zUnknown MS Compiler version %s N)sysversionfind ValueError)Zmsc_posZmsc_verrX/opt/alt/python310/lib/python3.10/site-packages/setuptools/_distutils/cygwinccompiler.py get_msvcr?s  rc@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 }qmd }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.ZCCgccZCXXzg++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 %sZcompiler compiler_soZ compiler_cxxZ linker_exeZ linker_so2.91.57Zmsvcrtz,Consider upgrading to a newer version of gcc)r__init__check_config_hZ debug_print CONFIG_H_OKwarnosenvirongetcccxx get_versions gcc_version ld_versionZdllwrap_version compiler_type linker_dllset_executables dll_librariesr)selfverbosedry_runforceZstatusZdetails shared_optionrrrr"dsX       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.resZwindresz-iz-oN)Zspawnrr r )r2objsrcextZcc_argsextra_postargsZpp_optsmsgrrr_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.Nrrz.deflibrz LIBRARY %sZEXPORTSz writing %srz --output-libz--defz-s)copyextendr1Z EXECUTABLEr/r&pathdirnamesplitextbasenamejoinappendZexecuterrlink)r2Z target_descZobjectsZoutput_filename output_dirZ librariesZ library_dirsZruntime_library_dirsZexport_symbolsdebugZ extra_preargsr<Z build_tempZ target_langZtemp_dirZdll_nameZ dll_extensionZdef_fileZlib_filecontentsZsymrrrrHsH         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.NrLr7r8z"unknown file type '%s' (from '%s'))r8r7) r&rBrDnormcaseZsrc_extensionsr rErGrF obj_extension)r2Zsource_filenamesZ strip_dirrIZ obj_namesZsrc_namebaser;rrrobject_filenamess&    z CygwinCCompiler.object_filenamesrrr) NNNNNrNNNN)rrL)__name__ __module__ __qualname____doc__r.rNZstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionr"r>rHrPrrrrrYs" @ Nrc@seZdZdZdZdddZdS)Mingw32CCompilerz@ Handles the Mingw32 port of the GNU C compiler to Windows. Zmingw32rc Cst||||d|jvr|jdkrd}nd}d|jvr$|jdkr$d}nd}t|jr/td|jd |jd |jd |jd |jd |j ||fd g|_ t |_ dS)Nrrrrr!z--entry _DllMain@12rLz1Cygwin gcc cannot be used with --compiler=mingw32z %s -O -Wallz%s -mdll -O -Wallz%sz%s %s %sr) rr"r)r-r, is_cygwinccrr0r*r/r1r)r2r3r4r5r6Z entry_pointrrrr"s.   zMingw32CCompiler.__init__NrQ)rRrSrTrUr.r"rrrrrVsrVokznot okZ 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) sysconfigZGCCzsys.version mentions 'GCC'ZClangzsys.version mentions 'Clang'Z__GNUC__z'%s' mentions '__GNUC__'z '%s' does not mention '__GNUC__'zcouldn't read '%s': %sN) Z distutilsrYrrr$Zget_config_h_filenameopenreadcloseCONFIG_H_NOTOKOSErrorCONFIG_H_UNCERTAINstrerror)rYfnZconfig_hexcrrrr#Ms(        r#s(\d+\.\d+(\.\d+)*)cCst|d}t|durdSt|dtdj}z |}W|n|wt|}|dur1dSt | d S)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 rrrdr[r\ RE_VERSIONsearchr groupdecode)cmd executableout out_stringresultrrr_find_exe_version~s    rpcCsgd}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)rp).0rkrrr sz get_versions..)tuple)Zcommandsrrrr+sr+cCst|dg}|dS)zCTry to determine if the compiler that would be used is from cygwin.z -dumpmachinescygwin)rstripendswith)r)rnrrrrWs rW)"rUr&rr@ subprocessrrrreZdistutils.unixccompilerrZdistutils.file_utilrZdistutils.errorsrrr r Zdistutils.versionr Zdistutils.spawnr rrrVr$r]r_r#compilergrpr+rWrrrrs.1    @1 /