U ã€C^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ÔzXddl5Z5d&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-6_kvzl1k/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 -sharedú3.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#?s‚ ÿ  ÿ          ûü ÿû ûýzMingw32CCompiler.__init__NcCsptƒ}|r|sg}| |¡||||||||d| | | | | f}|jdkrRtjjj}ntj}||d|jj …ŽdS)Nr) rÚappendr$r r!r"Úlinkr Ú__code__Ú co_argcount)r1Z target_descZobjectsZoutput_filenameÚ output_dirÚ librariesÚ library_dirsÚruntime_library_dirsÚexport_symbolsrZ extra_preargsZextra_postargsÚ build_tempZ target_langZruntime_libraryÚargsÚfuncrrrr8¬s2 ó  zMingw32CCompiler.linkrc CsÒ|dkr d}g}|D]¸}tj tj |¡¡\}}tj |¡\}}|rP|dd…}||jddgkrrtd||fƒ‚|r‚tj |¡}|dks’|dkr²| tj  ||||j ¡¡q| tj  |||j ¡¡q|S)Nrrú.rcz.resz"unknown file type '%s' (from '%s')) ÚosÚpathÚsplitextÚnormcaseÚ splitdriveZsrc_extensionsr Úbasenamer7ÚjoinZ obj_extension) r1Zsource_filenamesZ strip_dirr;Z obj_namesÚsrc_nameÚbaseÚextÚdrvrrrÚobject_filenamesÖs0 ÿÿ   ÿ ÿz!Mingw32CCompiler.object_filenames)rrr)NrNNNN)rr)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú compiler_typer#r8rOrrrrr8s ý uó ,ýrc Cs*tjg}ttdƒr,tjtjkr,| tj¡n"ttdƒrNtjtjkrN| tj¡dddg}g}|D]"}|D]}| tj ||¡¡qhq`dtj kr¨| tj tj dd¡¡t tj dd…ƒ\}}d g}|D]L}|||f} t d | ƒ|D]*}tj || ¡} tj  | ¡rè| SqèqÈtd | |fƒ‚dS) NÚ base_prefixÚ real_prefixrÚlibÚbinZ SYSTEMROOTZSystem32ézpython%d%d.dllzLooking for %sz%s not found in %s)ÚsysÚprefixÚhasattrrUr7rVrDrErJÚ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,      rmcCs tjdd|gtjd}|j ¡S)Nz objdump.exez-p)r)r%r&r'rÚ readlines)rlÚstrrrÚ dump_tablesrpc Cst|ƒ}tt|ƒƒD]}t || ¡¡rq8qtdƒ‚g}t|dt|ƒƒD]B}t || ¡¡}|rŒ| t |  d¡  ¡ƒ|  d¡f¡qNq’qNt|ƒdkr¬t   d|¡t|dƒ}| dtj |¡¡| d¡| d ¡| d ¡|D]}| d |d¡qî| ¡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 foundrrYrzNo symbols found in %sÚwzLIBRARY %s z,;CODE PRELOAD MOVEABLE DISCARDABLE z;DATA PRELOAD SINGLE z EXPORTS z%s N)rpÚrangeÚlenÚ_STARTÚmatchÚdecoderbÚ_TABLEr7Úintr,ÚstriprÚwarnÚopenÚwriterDrErIr)) rlÚdfileÚdumpÚiZsymsÚjÚmÚdÚsrrrÚ generate_def#s*$     r„cs4dddœtƒ‰‡fdd„}dd„}||ƒp2||ƒS)NÚamd64Úx86)rÚIntelcsdtj tj dd¡d¡}tj |¡s(dSt |¡D],\}}}||kr2ˆ|kr2tj ||¡Sq2dS)NZWINDIRz C:\WINDOWSZwinsxs)rDrErJr]ÚgetraÚwalk)Údll_nameZ winsxs_pathÚrootÚdirsÚfiles©ÚarchrrÚ_find_dll_in_winsxsIsÿ z%find_dll.._find_dll_in_winsxscSsLtjgtjd d¡D].}tj ||¡}tj |¡rtj |¡SqdS)NÚPATHú;) rZr[rDr]ÚsplitrErJraÚabspath)rŠrEÚfilepathrrrÚ_find_dll_in_pathTs z#find_dll.._find_dll_in_path)r)rŠrr–rrŽ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)Údlltoolú-dú-l)rDÚnamerrrrrErJrZr[Úisfiler—rzÚinfor„r%ÚcallÚremove) rZ msvcr_verZ msvcr_nameZout_nameÚout_fileZmsvcr_dll_nameÚdll_fileÚdef_nameÚdef_fileÚcmdÚretcoderrrr.^sH    ÿÿÿ   r.cCs@tjdkrdStƒ}|dkr"tƒS|dkr0tƒStd|ƒ‚dS)Nr˜rr‡zUnhandled arch %s)rDržrÚ_build_import_library_amd64Ú_build_import_library_x86rbrŽrrrr-™s r-c Csèttjdd…ƒ\}}dddg}tjg}ttdƒrLtjtjkrL| tj¡n"ttdƒrntjtjkrn| tj¡dd g}g}|D]:}|||f}|D]$}|D]} | tj   || |¡¡qšq’q~|D]} tj   | ¡r¾d | fSq¾d |d fS) zACheck if an import library for the Python runtime already exists.NrYzlibpython%d%d.azlibpython%d%d.dll.azlibpython%d.%d.dll.arUrVršrWTFr) r^rZr_r[r\rUr7rVrDrErJrŸ) rgrhrircrdÚ candidatesrjÚfilenameZstem_dirrfÚ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) Nú)Skip building import library: "%s" existsz4Building import library (arch=AMD64): "%s" (from %s)úpython%d%d.defrYršr›rœr)r®rrrmr r^rZr_rDrErJr[r„r%r&)Ú out_existsr£r¤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 r¯Nzpython%d%d.librYršrUrVrz+Cannot build import library: "%s" not foundz(Building import library (ARCH=x86): "%s"r)Úlib2defr°z%s %srqz3dlltool --dllname "%s" --def "%s" --output-lib "%s"z:Failed to build import library for gcc. Linking will fail.)r®rrr^rZr_rDrErJr[rŸr\rUrVrzr Únumpy.distutilsr²Z DEFAULT_NMZgetnmZparse_nmZ output_defZ DEF_HEADERr{rmÚsystem)r±r£Zlib_nameZlib_fileZbase_libr²r¥r¦Znm_cmdZ nm_outputZdlistÚflistrŠrAr§ÚstatusrrrrªÝs>             rªÚwin32z 8.0.50727.42Ú80z 9.0.21022.8Z90z10.0.30319.460Z100ÚCRT_ASSEMBLY_VERSIONÚ.rYz9Cannot import msvcrt: using manifest will not be possiblecCsXztt|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ÚKeyErrorrbÚtextwrapÚdedent)r½r¾r¼ÚtemplaterrrÚmsvc_manifest_xml1sÿ  rÅrlcCs4|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 rlrYZexerzType %s not supportedz&#include "winuser.h" %d RT_MANIFEST %s)rb)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)rrxrb)Úmsverr½rrrÚ!check_embedded_msvcr_match_linkedis  þÿrÉcCs&tj | dgd¡¡}tj |¡dS)NZyoÚcr)rDrErIZ_gen_temp_sourcefilerF)ÚconfigrLrrrÚconfigtest_nameusrÌcCst|ƒ}|jj}||dS)Nz .manifest)rÌrZ exe_extension)rËr‹ZexextrrrÚ manifest_nameysrÍcCst|ƒ}|dS)NrC)rÌ)rËr‹rrrÚrc_namesrÎcCsttƒ}|dk rp|dkrpt|ƒt|ƒ}t||dƒ}t||ƒ}tt|ƒdƒ}|j t|ƒ¡| |¡|  ¡dS)Nér»rq) Úget_build_msvc_versionrÉrxrÅr{rÍZ temp_filesr7r|r))rËrÈÚmaÚmiZmanxmlZmanrrrÚgenerate_manifest„s  rÓ)F)rl)ErSÚ __future__rrrrDrZr%r*rÂZnumpy.distutils.ccompilerZnumpyr_rrr³Zdistutils.cygwinccompilerr Zdistutils.versionrZdistutils.unixccompilerr Zdistutils.msvccompilerr rÐÚdistutils.errorsr r r Znumpy.distutils.misc_utilrrrrrr!Z get_msvcrÚcompilertrwr"rrmrpr„r—r.r-r®r©rªr¿ÚplatformÚmsvcrtr\r¹r“ÚmajorÚminorÚrestÚ ImportErrorrzrÅrÇrÉrÌrÍrÎrÓrrrrÚsf       B&! ; $?