3 \7@sddlZddlZddlZddlTddlmZddlmZddlm Z ddl m Z m Z ddl mZmZddlmZGd d d Zd,Zd-ddZd.d/d0d1d2d Zd!d"Zd3d#d$Zd%d&Zd'd(ZdS)4N)*)spawn) move_file)mkpath)newer_pairwise newer_group) split_quotedexecute)logc @seZdZdZdZdZdZdZdZdZ dZ ddddddZ dddgZ dpddZ d d Zd d Zd dZddZdqddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Z drd/d0Z!d1d2Z"d3d4Z#d5d6Z$d7d8Z%dsd9d:Z&dtd;d<Z'd=d>Z(dud?d@Z)dAZ*dBZ+dCZ,dvdDdEZ-dwdFdGZ.dxdHdIZ/dydJdKZ0dLdMZ1dNdOZ2dPdQZ3dzdRdSZ4d{dTdUZ5d|dWdXZ6d}dYdZZ7d~d[d\Z8dd^d_Z9ddadbZ:dcddZ;dedfZdkdlZ?ddndoZ@dS) CCompilerNczc++Zobjc)z.cz.ccz.cppz.cxxz.mrcCsf||_||_||_d|_g|_g|_g|_g|_g|_g|_ x$|j j D]}|j ||j |qHWdS)N) dry_runforceverbose output_dirmacros include_dirs libraries library_dirsruntime_library_dirsobjects executableskeysset_executable)selfrr rkeyr+/usr/lib64/python3.6/distutils/ccompiler.py__init__UszCCompiler.__init__cKs@x:|D]2}||jkr(td||jjf|j|||qWdS)Nz$unknown executable '%s' for class %s)r ValueError __class____name__r)rkwargsrrrrset_executablesys   zCCompiler.set_executablescCs,t|trt||t|n t|||dS)N) isinstancestrsetattrr)rrvaluerrrrs zCCompiler.set_executablecCs0d}x&|jD]}|d|kr |S|d7}q WdS)Nr)r)rnameidefnrrr _find_macros    zCCompiler._find_macrocCsdx^|D]V}t|toFt|dkoFt|dts:|ddkoFt|dtstd|ddqWdS)Nr(rzinvalid macro definition '%s': z.must be tuple (string,), (string, string), or z(string, None))r(r-)r$tuplelenr% TypeError)rZ definitionsr+rrr_check_macro_definitionss    z"CCompiler._check_macro_definitionscCs.|j|}|dk r|j|=|jj||fdS)N)r,rappend)rr)r'r*rrr define_macros zCCompiler.define_macrocCs0|j|}|dk r|j|=|f}|jj|dS)N)r,rr2)rr)r*Zundefnrrrundefine_macros zCCompiler.undefine_macrocCs|jj|dS)N)rr2)rdirrrradd_include_dirszCCompiler.add_include_dircCs|dd|_dS)N)r)rdirsrrrset_include_dirsszCCompiler.set_include_dirscCs|jj|dS)N)rr2)rlibnamerrr add_libraryszCCompiler.add_librarycCs|dd|_dS)N)r)rZlibnamesrrr set_librariesszCCompiler.set_librariescCs|jj|dS)N)rr2)rr5rrradd_library_dirszCCompiler.add_library_dircCs|dd|_dS)N)r)rr7rrrset_library_dirs szCCompiler.set_library_dirscCs|jj|dS)N)rr2)rr5rrradd_runtime_library_dirsz!CCompiler.add_runtime_library_dircCs|dd|_dS)N)r)rr7rrrset_runtime_library_dirssz"CCompiler.set_runtime_library_dirscCs|jj|dS)N)rr2)robjectrrradd_link_object szCCompiler.add_link_objectcCs|dd|_dS)N)r)rrrrrset_link_objects(szCCompiler.set_link_objectscCs|dkr|j}nt|ts"td|dkr2|j}n"t|trL||jpFg}ntd|dkrd|j}n*t|ttfrt||jpg}ntd|dkrg}|j|d|d}t ||}i} xRt t |D]B} || } || } t j j| d} |jt j j| | | f| | <qW||||| fS)Nz%'output_dir' must be a string or Nonez/'macros' (if supplied) must be a list of tuplesz6'include_dirs' (if supplied) must be a list of stringsr) strip_dirrr()rr$r%r0rlistrr.object_filenamesgen_preprocess_optionsranger/ospathsplitextrdirname)rZoutdirrZincdirssourcesdependsZextrarpp_optsbuildr*srcobjextrrr_setup_compile6s8   zCCompiler._setup_compilecCs0|dg}|rdg|dd<|r,||dd<|S)Nz-cz-grr)rrNdebugZbeforecc_argsrrr _get_cc_argsas   zCCompiler._get_cc_argscCs|dkr|j}nt|ts"td|dkr2|j}n"t|trL||jpFg}ntd|dkrd|j}n*t|ttfrt||jpg}ntd|||fS)Nz%'output_dir' must be a string or Nonez/'macros' (if supplied) must be a list of tuplesz6'include_dirs' (if supplied) must be a list of strings)rr$r%r0rrDrr.)rrrrrrr_fix_compile_argsjs   zCCompiler._fix_compile_argscCs|j||d}|ifS)N)r)rE)rrLrrMrrrr _prep_compiles zCCompiler._prep_compilecCsHt|ttfstdt|}|dkr.|j}nt|ts@td||fS)Nz,'objects' must be a list or tuple of stringsz%'output_dir' must be a string or None)r$rDr.r0rr%)rrrrrr_fix_object_argss zCCompiler._fix_object_argscCs|dkr|j}n*t|ttfr2t||jp,g}ntd|dkrJ|j}n*t|ttfrlt||jpfg}ntd|dkr|j}n*t|ttfrt||jpg}ntd|||fS)Nz3'libraries' (if supplied) must be a list of stringsz6'library_dirs' (if supplied) must be a list of stringsz>'runtime_library_dirs' (if supplied) must be a list of strings)rr$rDr.r0rr)rrrrrrr _fix_lib_argss&zCCompiler._fix_lib_argscCs2|jr dS|jr t||dd}n t||}|SdS)NTnewer)Zmissing)rr r)rr output_filer[rrr _need_links  zCCompiler._need_linkc Cst|ts|g}d}t|j}x^|D]V}tjj|\}}|jj|}y |jj |}||krb|}|}Wq$t k rxYq$Xq$W|S)N) r$rDr/language_orderrHrIrJ language_mapgetindexr) rrLZlangrasourcebaserRZextlangZextindexrrrdetect_languages      zCCompiler.detect_languagecCsdS)Nr)rrbr\rr extra_preargsextra_postargsrrr preprocesss zCCompiler.preprocessc Csz|j||||||\}} }} } |j| ||} xH| D]@} y| | \}}Wntk r\w2YnX|j| ||| || q2W| S)N)rSrVKeyError_compile)rrLrrrrTrerfrMrrNrOrUrQrPrRrrrcompiles6  zCCompiler.compilecCsdS)Nr)rrQrPrRrUrfrNrrrriCszCCompiler._compilecCsdS)Nr)rroutput_libnamerrT target_langrrrcreate_static_libIszCCompiler.create_static_libZ shared_objectZshared_library executablecCstdS)N)NotImplementedError)rZ target_descroutput_filenamerrrrexport_symbolsrTrerf build_temprlrrrlinkis9zCCompiler.linkc Cs2|jtj||j|dd||||||| | | | dS)Nshared)lib_type)rsr SHARED_LIBRARYlibrary_filename) rrrkrrrrrqrTrerfrrrlrrrlink_shared_libs  zCCompiler.link_shared_libc Cs(|jtj||||||||| | | | dS)N)rsr SHARED_OBJECT) rrrprrrrrqrTrerfrrrlrrrlink_shared_objects zCCompiler.link_shared_objectc Cs.|jtj||j|||||d||| d| dS)N)rsr EXECUTABLEexecutable_filename) rrZoutput_prognamerrrrrTrerfrlrrrlink_executables  zCCompiler.link_executablecCstdS)N)ro)rr5rrrlibrary_dir_optionszCCompiler.library_dir_optioncCstdS)N)ro)rr5rrrruntime_library_dir_optionsz$CCompiler.runtime_library_dir_optioncCstdS)N)ro)rlibrrrlibrary_optionszCCompiler.library_optionc Csddl}|dkrg}|dkr g}|dkr,g}|dkr8g}|jd|dd\}}tj|d} z.x|D]} | jd| q`W| jd|Wd| jXy|j|g|d} Wntk rd SXy|j| d ||d Wnt t fk rd SXdS) Nrz.cT)textwz#include "%s" z+main (int argc, char **argv) { %s(); } )rFza.out)rr) tempfileZmkstemprHfdopenwritecloserjZ CompileErrorr}Z LinkErrorr0) rfuncnameZincludesrrrrfdZfnamefZinclrrrr has_functions8     zCCompiler.has_functioncCstdS)N)ro)rr7rrTrrrfind_library_file#szCCompiler.find_library_filecCs|dkr d}g}x|D]|}tjj|\}}tjj|d}|tjj|d}||jkrhtd||f|rxtjj|}|jtjj |||j qW|S)Nrr(z"unknown file type '%s' (from '%s')) rHrIrJ splitdriveisabssrc_extensionsZUnknownFileErrorbasenamer2join obj_extension)rZsource_filenamesrCrZ obj_namesZsrc_namercrRrrrrENs    zCCompiler.object_filenamescCs$|rtjj|}tjj|||jS)N)rHrIrrshared_lib_extension)rrrCrrrrshared_object_filename_s z CCompiler.shared_object_filenamecCs(|rtjj|}tjj|||jp"dS)Nr)rHrIrr exe_extension)rrrCrrrrr|es zCCompiler.executable_filenamestaticc Cs`|d krtdt||d}t||d}tjj|\}}|||f} |rPd}tjj||| S) Nrrtdylib xcode_stubz?'lib_type' must be "static", "shared", "dylib", or "xcode_stub"Z _lib_formatZ_lib_extensionr)rrtrr)rgetattrrHrIsplitr) rr9rurCrZfmtrRr5rcfilenamerrrrwks zCCompiler.library_filenamer(cCstj|dS)N)r rT)rmsglevelrrrannounce~szCCompiler.announcecCsddlm}|rt|dS)Nr)DEBUG)Zdistutils.debugrprint)rrrrrr debug_prints zCCompiler.debug_printcCstjjd|dS)Nz warning: %s )sysstderrr)rrrrrwarnszCCompiler.warncCst||||jdS)N)r r )rfuncargsrrrrrr szCCompiler.executecCst||jddS)N)r )rr )rcmdrrrrszCCompiler.spawncCst|||jdS)N)r )rr )rrPdstrrrrszCCompiler.move_filecCst|||jddS)N)r )rr )rr)moderrrrszCCompiler.mkpath)rrr)N)N)NNNNN)NNNrNNN)NrN) NNNNNrNNNN) NNNNNrNNNN) NNNNNrNNNN)NNNNrNNN)NNNN)r)rr)rr)rr)rrr)r()Nr()r)Ar! __module__ __qualname__Z compiler_typerrZstatic_lib_extensionrZstatic_lib_formatZshared_lib_formatrr_r^rr#rr,r1r3r4r6r8r:r;r<r=r>r?rArBrSrVrWrXrYrZr]rdrgrjrirmryrvr{rsrxrzr}r~rrrrrErr|rwrrrr rrrrrrrr s  $   +  "   B  4    * +      r cygwin.*unixposixntmsvccCsV|dkrtj}|dkrtj}x4tD],\}}tj||dk sJtj||dk r"|Sq"WdS)Nr)rHr)rplatform_default_compilersrematch)osnamerpatterncompilerrrrget_default_compilers r unixccompiler UnixCCompilerstandard UNIX-style compiler _msvccompiler MSVCCompilerMicrosoft Visual C++cygwinccompilerCygwinCCompiler'Cygwin port of GNU C Compiler for Win32Mingw32CCompiler(Mingw32 port of GNU C Compiler for Win32 bcppcompiler BCPPCompilerBorland C++ Compiler)rrcygwinZmingw32ZbcppcCs\ddlm}g}x,tjD] }|jd|dt|dfqW|j||}|jddS)Nr) FancyGetoptz compiler=r-zList of available compilers:)Zdistutils.fancy_getoptrcompiler_classrr2sortZ print_help)rZ compilersrZpretty_printerrrrshow_compilerss  rc Cs|dkrtj}y"|dkr t|}t|\}}}Wn8tk rhd|}|dk r\|d|}t|YnXy*d|}t|tj|} t | |} WnBt k rt d|Yn$tk rt d||fYnX| d||S)Nz5don't know how to compile C/C++ code on platform '%s'z with '%s' compilerz distutils.z4can't compile C/C++ code: unable to load module '%s'zBcan't compile C/C++ code: unable to find class '%s' in module '%s') rHr)rrrhZDistutilsPlatformError __import__rmodulesvars ImportErrorZDistutilsModuleError) Zplatrrr rZ module_name class_nameZlong_descriptionrmoduleklassrrr new_compilers2    rcCsg}x|D]}t|to2dt|ko.dkns@td|t|dkr`|jd|dq t|dkr |ddkr|jd|dq |jd|q Wx|D]}|jd|qW|S) Nr(r-zPbad macro definition '%s': each element of 'macros' list must be a 1- or 2-tuplez-U%srz-D%sz-D%s=%sz-I%s)r$r.r/r0r2)rrrNZmacror5rrrrF s &    rFc Csg}x|D]}|j|j|q Wx4|D],}|j|}t|trJ||}q(|j|q(Wx^|D]V}tjj|\}} |r|j|g| } | r|j| q|j d|q^|j|j |q^W|S)Nz6no library file corresponding to '%s' found (skipping)) r2r~rr$rDrHrIrrrr) rrrrZlib_optsr5optrZlib_dirZlib_nameZlib_filerrrgen_lib_options7s$        rrrrrrr)rrr)NN)rrr)rrr)rrr)rrr)rrr)NNrrr)rrHrZdistutils.errorsZdistutils.spawnrZdistutils.file_utilrZdistutils.dir_utilrZdistutils.dep_utilrrZdistutils.utilrr Z distutilsr r rrrrrrFrrrrrsB      --