a oe<@sdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z m Z m Z ddlmZmZmZmZddlmZdd lmZd d Zd d ZddZGddde 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) CCompilergen_preprocess_optionsgen_lib_options)DistutilsExecError CompileErrorLibError LinkError)log)compiler_fixupcCsJd}tj|ddkr2d}d||vr2|d7}q|d|||dfS)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']) renvr=NospathbasenamecmdpivotrDC:\Program Files\Certbot\pkgs\setuptools\_distutils\unixccompiler.py _split_env-s   rcCs,tj|ddk}|d|||dfS)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}||dS)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 @seZdZdZddgdgdgddgdgddgddZejddd krNd ged <gd Zd Zd Z dZ dZ dZ dZ ZZeZejdkrdZd)ddZddZd*ddZd+ddZddZdd Zd!d"Zd#d$Zed%d&Zd,d'd(ZdS)- UnixCCompilerZunixNZccz-sharedarz-cr) preprocessorcompiler compiler_so compiler_cxx linker_so linker_exearchiverranlibdarwinr&)z.cz.Cz.ccz.cxxz.cppz.mz.oz.az.soz.dylibz.tbdzlib%s%scygwinz.exec Cs|d||}|\}}}t||} |j| } |r>| d|g|rN|| dd<|r\| || ||jp||dup|t||} | sdS|r|tj |z| | Wn,t y} zt | WYd} ~ n d} ~ 00dS)N-or)Z_fix_compile_argsrrextendappendforcermkpathrrdirnamespawnrr ) selfsourceZ output_fileZmacrosZ include_dirs extra_preargsextra_postargs fixed_argsignorepp_optsZpp_args preprocessmsgrrrr8s(       zUnixCCompiler.preprocessc Csbt|j||}z ||||d|g|Wn,ty\}zt|WYd}~n d}~00dS)Nr*)r r!r0rr ) r1objsrcextZcc_argsr4r7r!r9rrr_compiles  zUnixCCompiler._compilerc Cs|||\}}|j||d}|||r|tj|||j|g||j |j rz||j |gWqt y}zt |WYd}~qd}~00n t d|dS)N) output_dirskipping %s (up-to-date))_fix_object_argslibrary_filename _need_linkr.rrr/r0r%objectsr&rr r debug)r1rCZoutput_libnamer>rD target_langoutput_filenamer9rrrcreate_static_libs  zUnixCCompiler.create_static_libc Cs|||\}}||||}|\}}}t||||}t|ttdfsPtd|durftj ||}| ||r||j |d|g}| rdg|dd<| r| |dd<| r| | | tj|z|tjk}|r|jn|jdd}| dkrP|jrPt|\}}t|\}}t|j\}}t|j\}}t||}||||}t||}|||Wn.ty}zt|WYd}~n d}~00n td|dS)Nz%'output_dir' must be a string or Noner*z-grzc++r?)r@Z _fix_lib_argsr isinstancestrtype TypeErrorrrjoinrBrCr+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_neparamsr9rrrlinks@         zUnixCCompiler.linkcCsd|S)N-Lr)r1dirrrrlibrary_dir_optionsz UnixCCompiler.library_dir_optioncCs0td}tjt|d}d|vp.d|vS)NZCCrZgcczg++)rget_config_varrrrshlexsplit)r1Zcc_varr rrr_is_gccs zUnixCCompiler._is_gcccCstjdddkrNddlm}m}|}|rD||ddgkrDd|Sd|SnDtjdd d krhd |Stjddd kr|rd ndd|gStddkrd|Sd|SdS)Nr'r(r)get_macosx_target_ver split_version z -Wl,-rpath,rPZfreebsdz -Wl,-rpath=zhp-uxz-Wl,+sz+sZGNULDZyesz-Wl,--enable-new-dtags,-Rz-Wl,-R)sysplatformZdistutils.utilrWrXrVrrS)r1rQrWrXZmacosx_target_verrrrruntime_library_dir_options z(UnixCCompiler.runtime_library_dir_optioncCsd|S)Nz-lr)r1librrrlibrary_optionDszUnixCCompiler.library_optioncCshtd}td|}tjdkoB|oB|dpB|doB|d }|rdtj | d|ddS|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) rrSresearchr\r] startswithrrrLgroup)rQZcflagsmatchZ apply_rootrrr _library_rootGs     zUnixCCompiler._library_rootcsRfdddD}tj|}ddt||D}ttjj|}t |dS)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|dVqdS))Zlib_typeN)rA).0rJr_r1rr sz2UnixCCompiler.find_library_file..zdylib xcode_stub shared staticcss |]\}}tj||VqdS)N)rrrL)rgrootZlib_namerrrrisN) rUmaprf itertoolsproductfilterrrexistsnext)r1dirsr_rDZ lib_namesrootsZsearchedfoundrrhrfind_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\rarTrlrZ _modifiedrZ ccompilerrrrerrorsrr r r Z_logr Z _macos_compatr rrrrrrrrs