_d<dZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z m Z m Z ddlmZmZmZmZddlmZdd lmZd Zd Zd ZGd de Zy)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_fixupcd}tjj|ddk(rd}d||vr |dz }d||vr |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=Nospathbasenamecmdpivots E/usr/lib/python3/dist-packages/setuptools/_distutils/unixccompiler.py _split_envr-sc E wwA5(SZ QJESZ v;EF ##c`tjj|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']) r ld_so_aixNrrs r _split_aixr?s8 GG  SV $ 3E v;EF ##rc:t|}|d||k(r|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) linker_cmd compiler_cmdc_lenrs r_linker_paramsr$Ms0.  E'<7EQE ef rc "eZdZdZddgdgdgddgdgddgddZej ddd k(rd ged <gd Zd Zd Z dZ dZ dZ dxZ xZZeZej dk(rdZ ddZdZ ddZ d dZdZdZdZdZedZd!dZy)" UnixCCompilerunixNccz-sharedarz-cr) preprocessorcompiler compiler_so compiler_cxx linker_so linker_exearchiverranlibdarwinr1)z.cz.Cz.ccz.cxxz.cppz.mz.oz.az.soz.dylibz.tbdzlib%s%scygwinz.exec|jd||}|\}}}t||} |j| z} |r| jd|g|r|| dd|r| j|| j ||j xs|duxs t ||} | sy|r.|jtjj| |j| y#t$r} t| d} ~ wwxYw)N-or)_fix_compile_argsrr*extendappendforcermkpathrrdirnamespawnr r ) selfsource output_filemacros include_dirs extra_preargsextra_postargs fixed_argsignorepp_optspp_args preprocessmsgs rrIzUnixCCompiler.preprocesss++D&,G '1$ (>##g-  NND+. / 'GBQK  NN> *v ZZT;$#6T% :T    KK 4 5 $ JJw ! $s# # $s C C4$ C//C4ct|j||z} |j||z|d|gz|zy#t$r}t |d}~wwxYw)Nr6)rr,r=r r ) r>objsrcextcc_argsrDrGr,rJs r_compilezUnixCCompiler._compiles[$T%5%5w7OP  $ JJ{W,T3/??.P Q! $s# # $s9 A A  Ac|j||\}}|j||}|j||r|jtj j ||j|j|gz|z|jz|jr! |j|j|gzyytjd|y#t$r}t|d}~wwxYw)N) output_dirskipping %s (up-to-date))_fix_object_argslibrary_filename _need_linkr;rrr<r=r0objectsr1r r r debug)r>rWoutput_libnamerRrX target_langoutput_filenamerJs rcreate_static_libzUnixCCompiler.create_static_libs#33GZH//:/V ??7O 4 KK8 9 JJt}}'887BT\\Q R{{(JJt{{o->>? II0/ B*("3-'(s%C C6& C11C6c|j||\}}|j|||}|\}}}t||||}t|tt dfs t d| tjj||}|j||r-||jz|zd|gz}| rdg|dd| r| |dd| r|j| |jtjj| |tj k(}|r |j"n |j$dd}| dk(ro|j&rct)|\}}t+|\}}t)|j&\}}t)|j"\}}t-||}||z|z|z}t/||}|j1||zyt7j8d|y#t2$r}t5|d}~wwxYw)Nz%'output_dir' must be a string or Noner6z-grzc++rS)rT _fix_lib_argsr isinstancestrtype TypeErrorrrjoinrVrWr8r;r<r EXECUTABLEr/r.r-rrr$rr=r r r rX)r> target_descrWr[rR libraries library_dirsruntime_library_dirsexport_symbolsrXrCrD build_temprZrElib_optsld_args building_exelinkerr linker_neaix linker_na_compiler_cxx_ne linker_exe_neparamsrJs rlinkzUnixCCompiler.links #33GZH'' dirs rlibrary_dir_optionz UnixCCompiler.library_dir_option czrctjd}tjj t j |d}d|vxsd|vS)NCCrgcczg++)rget_config_varrrrshlexsplit)r>cc_varr+s r_is_gcczUnixCCompiler._is_gccsI))$/77##EKK$7$:; 5EX$55rcVtjdddk(r(ddlm}m}|}|r||ddgk\rd|zSd|zStjdd d k(rd |zStjddd k(r|j rd ndd|zgSt jddk(rd|zSd|zS)Nr2r3r)get_macosx_target_ver split_version z -Wl,-rpath,rxfreebsdz -Wl,-rpath=zhp-uxz-Wl,+sz+sGNULDyesz-Wl,--enable-new-dtags,-Rz-Wl,-R)sysplatformdistutils.utilrrrrr)r>rzrrmacosx_target_vers rruntime_library_dir_optionz(UnixCCompiler.runtime_library_dir_options << x ' K 5 7  ]3D%E"a%P$s**cz! \\"1  * 3& & \\"1  ( LLNs    # #G , 5/4 4c> !rc d|zS)Nz-lry)r>libs rlibrary_optionzUnixCCompiler.library_optionDr|rcftjd}tjd|}tj dk(xr<|xr8|j dxs%|j dxr|j d }|r2tjj|jd|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 CFLAGSz-isysroot\s*(\S+)r3z/System/z/usr/z /usr/local/rN) rrresearchrr startswithrrrcgroup)rzcflagsmatch apply_roots r _library_rootzUnixCCompiler._library_rootGs*))(3 .7 LLH $  z*SNN7+QCNN=4Q0Q 9Crww||EKKNCG4KKrcfddjD}tj|}dtj||D}t t jj|}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' c3DK|]}j|yw))lib_typeN)rU).0rarr>s r z2UnixCCompiler.find_library_file..s)   ! !# ! 5 s zdylib xcode_stub shared staticc3bK|]'\}}tjj||)yw)N)rrrc)rrootlib_names rrz2UnixCCompiler.find_library_file..s+ h GGLLx ( s-/N) rmapr itertoolsproductfilterrrexistsnext)r>dirsrrX lib_namesrootssearchedfounds` ` rfind_library_filezUnixCCompiler.find_library_filejsp. 8>>@ D&&- "+"3"3E9"E  rww~~x0E4  r)NNNNN)NrN) NNNNNrNNNN)r)__name__ __module__ __qualname__ compiler_type executablesrrsrc_extensions obj_extensionstatic_lib_extensionshared_lib_extensiondylib_lib_extensionxcode_stub_lib_extensionstatic_lib_formatshared_lib_formatdylib_lib_formatxcode_stub_lib_format exe_extensionrIrPr\rvr{rrr staticmethodrrryrrr&r&is(MFvI&f5M K ||BQ8#!) H?NM "%?HHH),<, ||x #$J$NRC:!9C~6 &"P L LD&!rr&)__doc__rrrrrrdep_utilr ccompilerrrrerrorsr r r r _logr _macos_compatrrrr$r&ryrrrsP  IIII)$$$ $8g!Ig!r