B s=>]`@sddlZddlZddlZddlTddlmZddlmZddlm Z ddl m Z m Z ddl mZmZddlmZGd d d Zd Zdd d ZddddddZddZdddZddZddZdS)N)*)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 D]}| ||j |qHWdS)N) dry_runforceverbose output_dirmacros include_dirs libraries library_dirsruntime_library_dirsobjects executableskeysset_executable)selfrr rkeyr6/opt/alt/python37/lib/python3.7/distutils/ccompiler.py__init__UszCCompiler.__init__cKs@x:|D]2}||jkr(td||jjf||||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|trHt|dkrHt|dts:|ddkrHt|dtstd|ddqWdS)N)r(r(rzinvalid macro definition '%s': z.must be tuple (string,), (string, string), or z(string, None))r$tuplelenr% TypeError)rZ definitionsr+rrr_check_macro_definitionss    z"CCompiler._check_macro_definitionscCs.||}|dk r|j|=|j||fdS)N)r,rappend)rr)r'r*rrr define_macros zCCompiler.define_macrocCs0||}|dk r|j|=|f}|j|dS)N)r,rr2)rr)r*Zundefnrrrundefine_macros zCCompiler.undefine_macrocCs|j|dS)N)rr2)rdirrrradd_include_dirszCCompiler.add_include_dircCs|dd|_dS)N)r)rdirsrrrset_include_dirsszCCompiler.set_include_dirscCs|j|dS)N)rr2)rlibnamerrr add_libraryszCCompiler.add_librarycCs|dd|_dS)N)r)rZlibnamesrrr set_librariesszCCompiler.set_librariescCs|j|dS)N)rr2)rr5rrradd_library_dirszCCompiler.add_library_dircCs|dd|_dS)N)r)rr7rrrset_library_dirs szCCompiler.set_library_dirscCs|j|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|j|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 | d} |t 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)missing)rr r)rr output_filer[rrr _need_links  zCCompiler._need_linkc Cst|ts|g}d}t|j}x^|D]V}tj|\}}|j|}y |j |}||krb|}|}Wq$t k rxYq$Xq$W|S)N) r$rDr/language_orderrHrIrJ language_mapgetindexr) rrLlangrbsourcebaserRZextlangZextindexrrrdetect_languages      zCCompiler.detect_languagecCsdS)Nr)rrdr]rr extra_preargsextra_postargsrrr preprocesss zCCompiler.preprocessc  Csz|||||||\}} }} } || ||} xH| D]@} y| | \}}Wntk r\w2YnX|| ||| || q2W| S)N)rSrVKeyError_compile)rrLrrrrTrgrhrMrrNrOrUrQrPrRrrrcompiles6  zCCompiler.compilecCsdS)Nr)rrQrPrRrUrhrNrrrrkCszCCompiler._compilecCsdS)Nr)rroutput_libnamerrT target_langrrrcreate_static_libIszCCompiler.create_static_libZ shared_objectZshared_library executablecCstdS)N)NotImplementedError)rZ target_descroutput_filenamerrrrexport_symbolsrTrgrh build_temprnrrrlinkis9zCCompiler.linkc Cs2|tj||j|dd||||||| | | | dS)Nshared)lib_type)rur SHARED_LIBRARYlibrary_filename) rrrmrrrrrsrTrgrhrtrnrrrlink_shared_libs  zCCompiler.link_shared_libc Cs(|tj||||||||| | | | dS)N)rur SHARED_OBJECT) rrrrrrrrrsrTrgrhrtrnrrrlink_shared_objects zCCompiler.link_shared_objectc Cs.|tj|||||||d||| d| dS)N)rur EXECUTABLEexecutable_filename) rrZoutput_prognamerrrrrTrgrhrnrrrlink_executables  zCCompiler.link_executablecCstdS)N)rq)rr5rrrlibrary_dir_optionszCCompiler.library_dir_optioncCstdS)N)rq)rr5rrrruntime_library_dir_optionsz$CCompiler.runtime_library_dir_optioncCstdS)N)rq)rlibrrrlibrary_optionszCCompiler.library_optionc Csddl}|dkrg}|dkr g}|dkr,g}|dkr8g}|jd|dd\}}t|d} z.x|D]} | d| q`W| d|Wd| Xy|j|g|d} Wntk rd SXy|j| d ||d Wnt t fk rd SXdS) Nrz.cT)textwz#include "%s" z=int main (int argc, char **argv) { %s(); return 0; } )rFza.out)rr) tempfileZmkstemprHfdopenwritecloserlZ CompileErrorrZ LinkErrorr0) rfuncnameZincludesrrrrfdZfnamefZinclrrrr has_functions8     zCCompiler.has_functioncCstdS)N)rq)rr7rrTrrrfind_library_file$szCCompiler.find_library_filecCs|dkr d}g}x|D]|}tj|\}}tj|d}|tj|d}||jkrhtd||f|rxtj|}|tj |||j qW|S)Nrr(z"unknown file type '%s' (from '%s')) rHrIrJ splitdriveisabssrc_extensionsZUnknownFileErrorbasenamer2join obj_extension)rZsource_filenamesrCrZ obj_namesZsrc_namererRrrrrEOs    zCCompiler.object_filenamescCs$|rtj|}tj|||jS)N)rHrIrrshared_lib_extension)rrrCrrrrshared_object_filename`s z CCompiler.shared_object_filenamecCs(|rtj|}tj|||jp"dS)Nr)rHrIrr exe_extension)rrrCrrrrr~fs zCCompiler.executable_filenamestaticc Cs`|dkrtdt||d}t||d}tj|\}}|||f} |rPd}tj||| S)N)rrvZdylibZ xcode_stubz?'lib_type' must be "static", "shared", "dylib", or "xcode_stub"Z _lib_formatZ_lib_extensionr)rgetattrrHrIsplitr) rr9rwrCrZfmtrRr5refilenamerrrryls zCCompiler.library_filenamer(cCst|dS)N)r rT)rmsglevelrrrannounceszCCompiler.announcecCsddlm}|rt|dS)Nr)DEBUG)Zdistutils.debugrprint)rrrrrr debug_prints zCCompiler.debug_printcCstjd|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^rfrirlrkror{rxr}rurzr|rrrrrrrErr~ryrrrr rrrrrrrr s  $   +  "   B  4    + +      r ))zcygwin.*unix)posixr)ntmsvccCsV|dkrtj}|dkrtj}x4tD],\}}t||dk sJt||dk r"|Sq"WdS)Nr)rHr)rplatform_default_compilersrematch)Zosnamerpatterncompilerrrrget_default_compilers r)Z unixccompilerZ UnixCCompilerzstandard UNIX-style compiler)Z _msvccompilerZ MSVCCompilerzMicrosoft Visual C++)cygwinccompilerZCygwinCCompilerz'Cygwin port of GNU C Compiler for Win32)rZMingw32CCompilerz(Mingw32 port of GNU C Compiler for Win32)Z bcppcompilerZ BCPPCompilerzBorland C++ Compiler)rrcygwinZmingw32ZbcppcCs\ddlm}g}x,tD] }|d|dt|dfqW|||}|ddS)Nr) FancyGetoptz compiler=r-zList of available compilers:)Zdistutils.fancy_getoptrcompiler_classrr2sort 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)rrrjZDistutilsPlatformError __import__rmodulesvars ImportErrorZDistutilsModuleError) Zplatrrr rZ module_name class_nameZlong_descriptionrmoduleklassrrr new_compilers2    rcCsg}x|D]}t|tr2dt|kr0dks>ntd|t|dkr^|d|dq t|dkr |ddkr|d|dq |d|q Wx|D]}|d|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]}|||q Wx4|D],}||}t|trJ||}q(||q(Wx^|D]V}tj|\}} |r||g| } | r|| q| d|q^|| |q^W|S)Nz6no library file corresponding to '%s' found (skipping)) r2rrr$rDrHrIrrrr) rrrrZlib_optsr5optrZlib_dirZlib_nameZlib_filerrrgen_lib_options8s$        r)NN)NNrrr)rrHrZdistutils.errorsZdistutils.spawnrZdistutils.file_utilrZdistutils.dir_utilrZdistutils.dep_utilrrZdistutils.utilrr Z distutilsr r rrrrrrFrrrrrs4      --