B ¬[ð]bã@sdZddlmZmZmZddlZddlZddlZddlZddl Z ddl Z ej ddkrdddl mZn ddlmZddlZddlmZddlmZdd lmZdd lmZmZmZdd lmZmZm Z m!Z!d d „Z"e"ej#_$e %d¡Z&e %d¡Z'Gdd„dej#j(ƒZ)dd„Z*dd„Z+dd„Z,dd„Z-d?dd„Z.dd„Z/dd „Z0d!d"„Z1d#d$„Z2iZ3ej4d%krÔyXddl5Z5d&e3d'<d(e3d)<d*e3d+<e6e5d,ƒr°e5j7 8d-d.¡\Z9Z:Z;e5j7e3e9e:<[9[:[;Wn ed@d3d4„Z?d5d6„Z@d7d8„ZAd9d:„ZBd;d<„ZCd=d>„ZDdS)Aa Support code for building Python extensions on Windows. # NT stuff # 1. Make sure libpython.a exists for gcc. If not, build it. # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) # 3. Force windows to use g77 é)ÚdivisionÚabsolute_importÚprint_functionNéé)Úlog)Ú StrictVersion)Ú UnixCCompiler)Úget_build_version)ÚDistutilsExecErrorÚ CompileErrorÚUnknownFileError)Úmsvc_runtime_libraryÚmsvc_runtime_versionÚmsvc_runtime_majorÚget_build_architecturecCstƒ}|dkrgS|gS)zBReplacement for outdated version of get_msvcr from cygwinccompilerN)r)Zmsvcr©rúC/tmp/pip-install-svzetoqp/numpy/numpy/distutils/mingw32ccompiler.pyÚget_msvcr_replacement*srz\[Ordinal/Name Pointer\] Tablez$^\s+\[([\s*[0-9]*)\] ([a-zA-Z0-9_]*)c@s2eZdZdZdZd dd„Zd dd„Zdd d „ZdS)ÚMingw32CCompilerzH A modified MingW32 compiler compatible with an MSVC built Python. Zmingw32rc Csˆtjj ||||¡|jdkrhtjddgdtjd}|j  ¡}|j  ¡t   d|¡}|rht | d¡ƒ|_|jdkrxd}nd }|jd krŽd |_n|jdkržd |_tƒtƒ}tdd } |s¼| rÆ| d ¡tƒ} | rà| dd| ¡tƒdkr |jdkr |jdddddn|jdddddn\|jdkrJ|jdddd|j|fdn2|jdkrj|jd d!dd"dn|jd#d$d%d&dd g|_dS)'NZgccz -dumpversionT)ÚshellÚstdoutz (\d+\.\d+)rz2.91.57z--entry _DllMain@12ÚZdllwrapzg++)ÚdebugZNPY_MINGW_USE_CUSTOM_MSVCRZ__MSVCRT_VERSION__z0x%04iÚAMD64z4.0z/gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -WallzCgcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall -Wstrict-prototypeszgcc -g -mno-cygwinzgcc -g -mno-cygwin -shared)ÚcompilerÚ compiler_soÚ linker_exeÚ linker_soz#gcc -g -DDEBUG -DMS_WIN64 -O0 -Wallz7gcc -g -DDEBUG -DMS_WIN64 -O0 -Wall -Wstrict-prototypeszgcc -gzgcc -g -sharedz3.0.0zgcc -mno-cygwin -O2 -wz0gcc -mno-cygwin -mdll -O2 -w -Wstrict-prototypeszg++ -mno-cygwinz%s -mno-cygwin -mdll -static %szgcc -mno-cygwin -O2 -Wallz-gcc -mno-cygwin -O2 -Wall -Wstrict-prototypeszg++ -mno-cygwin -sharedz gcc -O2 -Wallz!gcc -O2 -Wall -Wstrict-prototypeszg++ z g++ -shared)Ú distutilsÚcygwinccompilerÚCygwinCCompilerÚ__init__Ú gcc_versionÚ subprocessÚPopenÚPIPErÚreadÚcloseÚreÚsearchrÚgroupZ linker_dllZlinkerÚbuild_import_libraryÚbuild_msvcr_libraryZ define_macrorrÚset_executablesÚ compiler_cxx) ÚselfÚverboseÚdry_runÚforceÚpZ out_stringÚresultZ entry_pointZ msvcr_successZmsvcr_dbg_successZ msvcr_versionrrrr"?sp                   zMingw32CCompiler.__init__NcCsptƒ}|r|sg}| |¡||||||||d| | | | | f}|jdkrRtjjj}ntj}||d|jj …ŽdS)Nz3.0.0) rÚappendr#rr r!Úlinkr Ú__code__Ú co_argcount)r0Z target_descZobjectsZoutput_filenameÚ output_dirÚ librariesÚ library_dirsÚruntime_library_dirsÚexport_symbolsrZ extra_preargsZextra_postargsÚ build_tempZ target_langZruntime_libraryÚargsÚfuncrrrr7¬s0   zMingw32CCompiler.linkrc CsÖ|dkr d}g}xÀ|D]¸}tj tj |¡¡\}}tj |¡\}}|rR|dd…}||jddgkrttd||fƒ‚|r„tj |¡}|dks”|dkr´| tj  ||||j ¡¡q| tj  |||j ¡¡qW|S)Nrrz.rcz.resz"unknown file type '%s' (from '%s')) ÚosÚpathÚsplitextÚnormcaseÚ splitdriveZsrc_extensionsr Úbasenamer6ÚjoinZ obj_extension) r0Zsource_filenamesZ strip_dirr:Z obj_namesÚsrc_nameÚbaseÚextÚdrvrrrÚobject_filenamesÖs(      z!Mingw32CCompiler.object_filenames)rrr)NrNNNN)rr)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú compiler_typer"r7rMrrrrr8s r rc Cs2tjg}ttdƒr,tjtjkr,| tj¡n"ttdƒrNtjtjkrN| tj¡dddg}g}x.|D]&}x |D]}| tj ||¡¡qlWqbWdtj kr°| tj tj dd¡¡t tj dd…ƒ\}}d g}xP|D]H}|||f} t d | ƒx*|D]"}tj || ¡} tj  | ¡rô| SqôWqÒWtd | |fƒ‚dS) NÚ base_prefixÚ real_prefixrÚlibÚbinZ SYSTEMROOTZSystem32ézpython%d%d.dllzLooking for %sz%s not found in %s)ÚsysÚprefixÚhasattrrSr6rTrBrCrHÚenvironÚtupleÚ version_infoÚprintÚexistsÚ ValueError) ÚstemsÚsub_dirsÚlib_dirsZstemÚfolderÚ major_versionÚ minor_versionÚpatternsÚpatÚdllnameÚdllrrrÚfind_python_dllùs,           rkcCs tjdd|gtjd}|j ¡S)Nz objdump.exez-p)r)r$r%r&rÚ readlines)rjÚstrrrÚ dump_tablesrnc Cst|ƒ}x0tt|ƒƒD]}t || ¡¡rPqWtdƒ‚g}xVt|dt|ƒƒD]@}t || ¡¡}|r| t |  d¡  ¡ƒ|  d¡f¡qRPqRWt|ƒdkr°t   d|¡t|dƒ}| dtj |¡¡| d¡| d ¡| d ¡x|D]}| d |d¡qôW| ¡d S) zŠGiven a dll file location, get all its exported symbols and dump them into the given def file. The .def file will be overwrittenzSymbol table not foundrrWrzNo symbols found in %sÚwzLIBRARY %s z,;CODE PRELOAD MOVEABLE DISCARDABLE z;DATA PRELOAD SINGLE z EXPORTS z%s N)rnÚrangeÚlenÚ_STARTÚmatchÚdecoder`Ú_TABLEr6Úintr+ÚstriprÚwarnÚopenÚwriterBrCrGr() rjÚdfileÚdumpÚiZsymsÚjÚmÚdÚsrrrÚ generate_def#s*$      r‚cs4dddœtƒ‰‡fdd„}dd„}||ƒp2||ƒS)NÚamd64Zx86)rÚIntelcsdtj tj dd¡d¡}tj |¡s(dSx6t |¡D](\}}}||kr4ˆ|kr4tj ||¡Sq4WdS)NZWINDIRz C:\WINDOWSZwinsxs)rBrCrHr[Úgetr_Úwalk)Údll_nameZ winsxs_pathÚrootÚdirsÚfiles)ÚarchrrÚ_find_dll_in_winsxsIs z%find_dll.._find_dll_in_winsxscSsLxFtjgtjd d¡D]*}tj ||¡}tj |¡rtj |¡SqWdS)NÚPATHú;) rXrYrBr[ÚsplitrCrHr_Úabspath)r‡rCÚfilepathrrrÚ_find_dll_in_pathTs z#find_dll.._find_dll_in_path)r)r‡rŒr’r)r‹rÚfind_dllDs  r“Fc CstjdkrdStƒ}|dkr*t d¡dS|dkr@t d¡dStƒ}|rR|d7}d|}tj tj d|¡}tj  |¡rŒt d |f¡d S|d }t |ƒ}|s²t  d |¡dSd |}tj tj d|¡}t  d||f¡t||ƒdd|d|g} t | ¡} t |¡| S)NÚntFz?Skip building import library: Runtime is not compiled with MSVCéPz=Skip building msvcr library: custom functionality not presentr€zlib%s.aÚlibsz(Skip building msvcr library: "%s" existsTz.dllz*Cannot build msvcr library: "%s" not foundz lib%s.defz&Building msvcr library: "%s" (from %s)Údlltoolz-dz-l)rBÚnamerrrrrCrHrXrYÚisfiler“rxÚinfor‚r$ÚcallÚremove) rZ msvcr_verZ msvcr_nameZout_nameÚout_fileZmsvcr_dll_nameÚdll_fileÚdef_nameÚdef_fileÚcmdÚretcoderrrr-^sB         r-cCs@tjdkrdStƒ}|dkr"tƒS|dkr0tƒStd|ƒ‚dS)Nr”rr„zUnhandled arch %s)rBr˜rÚ_build_import_library_amd64Ú_build_import_library_x86r`)r‹rrrr,™s r,c Csôttjdd…ƒ\}}dddg}tjg}ttdƒrLtjtjkrL| tj¡n"ttdƒrntjtjkrn| tj¡dd g}g}xJ|D]B}|||f}x0|D](}x"|D]} | tj   || |¡¡q Wq–Wq€Wx |D]} tj   | ¡rÌd | fSqÌWd |d fS) zACheck if an import library for the Python runtime already exists.NrWzlibpython%d%d.azlibpython%d%d.dll.azlibpython%d.%d.dll.arSrTr–rUTFr) r\rXr]rYrZrSr6rTrBrCrHr™) rerfrgrarbÚ candidatesrhÚfilenameZstem_dirrdÚfullnamerrrÚ_check_for_import_lib¥s(     "   r¨cCs„tƒ\}}|rt d|¡dStƒ}t d||f¡dttjdd…ƒ}tj   tj d|¡}t ||ƒdd|d|g}t  |¡dS) Nz)Skip building import library: "%s" existsz4Building import library (arch=AMD64): "%s" (from %s)zpython%d%d.defrWr–r—z-dz-l)r¨rrrkršr\rXr]rBrCrHrYr‚r$r%)Ú out_existsrržrŸr r¡rrrr£És    r£cCshtƒ\}}|rt d|¡dSdttjdd…ƒ}tj tj d|¡}tj  |¡s´t tdƒrptj tj d|¡}n"t tdƒrŽtj tj d|¡}nd}tj  |¡r¤|}nt d |¡dSt d |¡d d lm}d ttjdd…ƒ}tj tj d|¡}d|j|f}| |¡} | | ¡\} } | | | |jt|dƒ¡tƒ} | ||f} d| }t |¡}|rdt d¡dS)z; Build the import libraries for Mingw32-gcc on Windows z)Skip building import library: "%s" existsNzpython%d%d.librWr–rSrTrz+Cannot build import library: "%s" not foundz(Building import library (ARCH=x86): "%s"r)Úlib2defzpython%d%d.defz%s %sroz3dlltool --dllname "%s" --def "%s" --output-lib "%s"z:Failed to build import library for gcc. Linking will fail.)r¨rrr\rXr]rBrCrHrYr™rZrSrTrxršÚnumpy.distutilsrªZ DEFAULT_NMZgetnmZparse_nmZ output_defZ DEF_HEADERryrkÚsystem)r©rZlib_nameZlib_fileZbase_librªrŸr Znm_cmdZ nm_outputZdlistÚflistr‡r@r¡Ústatusrrrr¤Ýs>             r¤Úwin32z 8.0.50727.42Ú80z 9.0.21022.8Z90z10.0.30319.460Z100ÚCRT_ASSEMBLY_VERSIONÚ.rWz9Cannot import msvcrt: using manifest will not be possiblecCsXytt|d|ƒ}Wn$tk r<td||fƒ‚YnXt d¡}||||dœS)zUGiven a major and minor version of the MSVCR, returns the corresponding XML file.é z)Version %d,%d of MSVCRT not supported yetaà )ÚfullverÚmajÚmin)Ú_MSVCRVER_TO_FULLVERÚstrÚKeyErrorr`ÚtextwrapÚdedent)rµr¶r´ÚtemplaterrrÚmsvc_manifest_xml1sr½rjcCs4|dkrd}n|dkrd}n td|ƒ‚d||fS)aWReturn the rc file used to generate the res file which will be embedded as manifest for given manifest file name, of given type ('dll' or 'exe'). Parameters ---------- name : str name of the manifest file to embed type : str {'dll', 'exe'} type of the binary which will embed the manifest rjrWZexerzType %s not supportedz&#include "winuser.h" %d RT_MANIFEST %s)r`)r˜ÚtypeZrctyperrrÚ manifest_rcQs  r¿cCs.tƒ}|r*|t|ƒks*tdt|ƒ|fƒ‚dS)z6msver is the ms runtime version used for the MANIFEST.zKDiscrepancy between linked msvcr (%d) and the one about to be embedded (%d)N)rrvr`)ÚmsverrµrrrÚ!check_embedded_msvcr_match_linkedis  rÁcCs&tj | dgd¡¡}tj |¡dS)NZyoÚcr)rBrCrGZ_gen_temp_sourcefilerD)ÚconfigrJrrrÚconfigtest_nameusrÄcCst|ƒ}|jj}||dS)Nz .manifest)rÄrZ exe_extension)rÃrˆZexextrrrÚ manifest_nameysrÅcCst|ƒ}|dS)Nz.rc)rÄ)rÃrˆrrrÚrc_namesrÆcCsttƒ}|dk rp|dkrpt|ƒt|ƒ}t||dƒ}t||ƒ}tt|ƒdƒ}|j t|ƒ¡| |¡|  ¡dS)Nér³ro) Úget_build_msvc_versionrÁrvr½ryrÅZ temp_filesr6rzr()rÃrÀÚmaÚmiZmanxmlZmanrrrÚgenerate_manifest„s  rË)F)rj)ErQÚ __future__rrrrBrXr$r)rºZnumpy.distutils.ccompilerZnumpyr]rrr«Zdistutils.cygwinccompilerrZdistutils.versionrZdistutils.unixccompilerr Zdistutils.msvccompilerr rÈÚdistutils.errorsr r r Znumpy.distutils.misc_utilrrrrrr Z get_msvcrÚcompilerrrur!rrkrnr‚r“r-r,r¨r£r¤r·ÚplatformÚmsvcrtrZr±rÚmajorÚminorÚrestÚ ImportErrorrxr½r¿rÁrÄrÅrÆrËrrrrÚ sf      B&! ; $?