a „oeò<ã@s´dZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z m Z m Z ddlmZmZmZmZddlmZdd lmZd d „Zd d „Zdd„ZGdd„de ƒZdS)a9distutils.unixccompiler Contains the UnixCCompiler class, a subclass of CCompiler that handles the "typical" Unix-style command-line C compiler: * macros defined with -Dname[=value] * macros undefined with -Uname * include search directories specified with -Idir * libraries specified with -lllib * library search directories specified with -Ldir * compile handled by 'cc' (or similar) executable with -c option: compiles .c to .o * link static library handled by 'ar' command (possibly with 'ranlib') * link shared library handled by 'cc -shared' éNé)Ú sysconfig)Únewer)Ú CCompilerÚgen_preprocess_optionsÚgen_lib_options)ÚDistutilsExecErrorÚ CompileErrorÚLibErrorÚ LinkError)Úlog)Úcompiler_fixupcCsJd}tj |d¡dkr2d}d||vr2|d7}q|d|…||d…fS)zÿ For macOS, split command into 'env' portion (if any) and the rest of the linker command. >>> _split_env(['a', 'b', 'c']) ([], ['a', 'b', 'c']) >>> _split_env(['/usr/bin/env', 'A=3', 'gcc']) (['/usr/bin/env', 'A=3'], ['gcc']) rÚenvrú=N©ÚosÚpathÚbasename©ÚcmdÚpivot©rúDC:\Program Files\Certbot\pkgs\setuptools\_distutils\unixccompiler.pyÚ _split_env-s   rcCs,tj |d¡dk}|d|…||d…fS)a AIX platforms prefix the compiler with the ld_so_aix script, so split that from the linker command. >>> _split_aix(['a', 'b', 'c']) ([], ['a', 'b', 'c']) >>> _split_aix(['/bin/foo/ld_so_aix', 'gcc']) (['/bin/foo/ld_so_aix'], ['gcc']) rZ ld_so_aixNrrrrrÚ _split_aix?s rcCs,t|ƒ}|d|…|kr|nd}||d…S)a The linker command usually begins with the compiler command (possibly multiple elements), followed by zero or more params for shared library building. If the LDSHARED env variable overrides the linker command, however, the commands may not match. Return the best guess of the linker parameters by stripping the linker command. If the compiler command does not match the linker command, assume the linker command is just the first element. >>> _linker_params('gcc foo bar'.split(), ['gcc']) ['foo', 'bar'] >>> _linker_params('gcc foo bar'.split(), ['other']) ['foo', 'bar'] >>> _linker_params('ccache gcc foo bar'.split(), 'ccache gcc'.split()) ['foo', 'bar'] >>> _linker_params(['gcc'], ['gcc']) [] Nr)Úlen)Z linker_cmdZ compiler_cmdZc_lenrrrrÚ_linker_paramsMsrc @sèeZdZdZddgdgdgddgdgddgddœZejdd…d krNd ged <gd ¢Zd Zd Z dZ dZ dZ dZ ZZeZejdkrˆdZd)dd„Zdd„Zd*dd„Zd+dd„Zdd„Zdd „Zd!d"„Zd#d$„Zed%d&„ƒZd,d'd(„ZdS)-Ú UnixCCompilerZunixNZccz-sharedÚarz-cr)Ú preprocessorÚcompilerÚ compiler_soÚ compiler_cxxÚ linker_soÚ linker_exeÚarchiverÚranlibéÚdarwinr&)z.cz.Cz.ccz.cxxz.cppz.mz.oz.az.soz.dylibz.tbdzlib%s%sÚcygwinz.exec CsÜ| d||¡}|\}}}t||ƒ} |j| } |r>|  d|g¡|rN|| dd…<|r\|  |¡|  |¡|jp||dup|t||ƒ} | s†dS|rœ| tj   |¡¡z|  | ¡Wn,t yÖ} zt | ƒ‚WYd} ~ n d} ~ 00dS)Nú-or)Z_fix_compile_argsrrÚextendÚappendÚforcerÚmkpathrrÚdirnameÚspawnrr ) ÚselfÚsourceZ output_fileZmacrosZ include_dirsÚ extra_preargsÚextra_postargsÚ fixed_argsÚignoreÚpp_optsZpp_argsÚ preprocessÚmsgrrrr8‘s(       zUnixCCompiler.preprocessc Csbt|j||ƒ}z | |||d|g|¡Wn,ty\}zt|ƒ‚WYd}~n d}~00dS)Nr*)r r!r0rr ) r1ÚobjÚsrcÚextZcc_argsr4r7r!r9rrrÚ_compile¶s  zUnixCCompiler._compilerc Cs´| ||¡\}}|j||d�}| ||¡r¤| tj |¡¡| |j|g||j ¡|j r°z| |j |g¡Wq°t y }zt |ƒ‚WYd}~q°d}~00n t  d|¡dS)N)Ú output_dirúskipping %s (up-to-date))Ú_fix_object_argsÚlibrary_filenameÚ _need_linkr.rrr/r0r%Úobjectsr&rr r Údebug)r1rCZoutput_libnamer>rDÚ target_langÚoutput_filenamer9rrrÚcreate_static_lib½s  zUnixCCompiler.create_static_libc Cs¬| ||¡\}}| |||¡}|\}}}t||||ƒ}t|ttdƒfƒsPtdƒ‚|durftj  ||¡}|  ||¡�rœ||j |d|g}| rœdg|dd…<| r¬| |dd…<| rº|  | ¡|  tj |¡¡zž|tjk}|râ|jn|jdd…}| dk�rP|j�rPt|ƒ\}}t|ƒ\}}t|jƒ\}}t|jƒ\}}t||ƒ}||||}t||ƒ}| ||¡Wn.t�y˜}zt|ƒ‚WYd}~n d}~00n t d|¡dS)Nz%'output_dir' must be a string or Noner*z-grzc++r?)r@Z _fix_lib_argsrÚ isinstanceÚstrÚtypeÚ TypeErrorrrÚjoinrBrCr+r.r/rZ EXECUTABLEr$r#r"rrrr r0rr r rD)r1Z target_descrCrFr>Z librariesZ library_dirsZruntime_library_dirsZexport_symbolsrDr3r4Z build_temprEr5Zlib_optsZld_argsZ building_exeZlinkerrZ linker_neZaixZ linker_naÚ_Zcompiler_cxx_neZ linker_exe_neÚparamsr9rrrÚlinkÕs@         zUnixCCompiler.linkcCsd|S)Nú-Lr)r1ÚdirrrrÚlibrary_dir_optionsz UnixCCompiler.library_dir_optioncCs0t d¡}tj t |¡d¡}d|vp.d|vS)NZCCrZgcczg++)rÚget_config_varrrrÚshlexÚsplit)r1Zcc_varr rrrÚ_is_gccs zUnixCCompiler._is_gcccCs´tjdd…dkrNddlm}m}|ƒ}|rD||ƒddgkrDd|Sd|SnDtjdd …d krhd |Stjdd…d kr’| ¡r†d ndd|gSt d¡dkr¨d|Sd|SdS)Nr'r(r)Úget_macosx_target_verÚ split_versioné éz -Wl,-rpath,rPéZfreebsdz -Wl,-rpath=zhp-uxz-Wl,+sz+sZGNULDZyesz-Wl,--enable-new-dtags,-Rz-Wl,-R)ÚsysÚplatformZdistutils.utilrWrXrVrrS)r1rQrWrXZmacosx_target_verrrrÚruntime_library_dir_options þz(UnixCCompiler.runtime_library_dir_optioncCsd|S)Nz-lr)r1ÚlibrrrÚlibrary_optionDszUnixCCompiler.library_optioncCsht d¡}t d|¡}tjdkoB|oB| d¡pB| d¡oB| d¡ }|rdtj  |  d¡|dd…¡S|S) a° macOS users can specify an alternate SDK using'-isysroot'. Calculate the SDK root if it is specified. Note that, as of Xcode 7, Apple SDKs may contain textual stub libraries with .tbd extensions rather than the normal .dylib shared libraries installed in /. The Apple compiler tool chain handles this transparently but it can cause problems for programs that are being built with an SDK and searching for specific libraries. Callers of find_library_file need to keep in mind that the base filename of the returned SDK library file might have a different extension from that of the library file installed on the running system, for example: /Applications/Xcode.app/Contents/Developer/Platforms/ MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/ usr/lib/libedit.tbd vs /usr/lib/libedit.dylib ZCFLAGSz-isysroot\s*(\S+)r(z/System/z/usr/z /usr/local/rN) rrSÚreÚsearchr\r]Ú startswithrrrLÚgroup)rQZcflagsÚmatchZ apply_rootrrrÚ _library_rootGs   ÿ û zUnixCCompiler._library_rootcsR‡‡fdd„d ¡Dƒ}tˆj|ƒ}dd„t ||¡Dƒ}ttjj|ƒ}t |dƒS)a/ Second-guess the linker with not much hard data to go on: GCC seems to prefer the shared library, so assume that *all* Unix C compilers do, ignoring even GCC's "-static" option. >>> compiler = UnixCCompiler() >>> compiler._library_root = lambda dir: dir >>> monkeypatch = getfixture('monkeypatch') >>> monkeypatch.setattr(os.path, 'exists', lambda d: 'existing' in d) >>> dirs = ('/foo/bar/missing', '/foo/bar/existing') >>> compiler.find_library_file(dirs, 'abc').replace('\\', '/') '/foo/bar/existing/libabc.dylib' >>> compiler.find_library_file(reversed(dirs), 'abc').replace('\\', '/') '/foo/bar/existing/libabc.dylib' >>> monkeypatch.setattr(os.path, 'exists', ... lambda d: 'existing' in d and '.a' in d) >>> compiler.find_library_file(dirs, 'abc').replace('\\', '/') '/foo/bar/existing/libabc.a' >>> compiler.find_library_file(reversed(dirs), 'abc').replace('\\', '/') '/foo/bar/existing/libabc.a' c3s|]}ˆjˆ|d�VqdS))Zlib_typeN)rA)Ú.0rJ©r_r1rrÚ �sÿz2UnixCCompiler.find_library_file..zdylib xcode_stub shared staticcss |]\}}tj ||¡VqdS)N)rrrL)rgÚrootZlib_namerrrriˆsÿN) rUÚmaprfÚ itertoolsÚproductÚfilterrrÚexistsÚnext)r1Údirsr_rDZ lib_namesÚrootsZsearchedÚfoundrrhrÚfind_library_filejs þ  þzUnixCCompiler.find_library_file)NNNNN)NrN) NNNNNrNNNN)r)Ú__name__Ú __module__Ú __qualname__Z compiler_typeZ executablesr\r]Zsrc_extensionsZ obj_extensionZstatic_lib_extensionZshared_lib_extensionZdylib_lib_extensionZxcode_stub_lib_extensionZstatic_lib_formatZshared_lib_formatZdylib_lib_formatZxcode_stub_lib_formatZ exe_extensionr8r=rGrOrRrVr^r`Ú staticmethodrfrtrrrrrisb ø    ù %ÿ ò ?( "r)Ú__doc__rr\rarTrlÚrZ _modifiedrZ ccompilerrrrÚerrorsrr r r Z_logr Z _macos_compatr rrrrrrrrÚs