U C^ݜ@sdZddlmZmZmZddddgZddlZddlZddlZddl Z ddl m Z dd l m Z dd lmZdd lmZmZmZmZmZdd lmZmZdd lmZmZddlmZddlmZm Z m!Z!m"Z"m#Z#ddl$m%Z%ddl&m'Z'ddlm(Z(ddl)m*Z*e+Z,Gddde-Z.ddZ/ddZ0ddZ1GdddeZ2dZ3da4da5dd Z6d8d"d#Z7d9d$d%Z8d:d&d'Z9e:a;d;d(dZe?d+ej@jAZBe?d,ej@jCZDe?d-ej@jCZEe?d.ej@jCZFe?d/ej@jAZGd0d1ZHd2d3ZIe?d4ej@ZJd5d6ZKeLd7kre=dS)=anumpy.distutils.fcompiler Contains FCompiler, an abstract base class that defines the interface for the numpy.distutils Fortran compiler abstraction model. Terminology: To be consistent, where the term 'executable' is used, it means the single file, like 'gcc', that is executed, and should be a string. In contrast, 'command' means the entire command line, like ['gcc', '-c', 'file.c'], and should be a list. But note that FCompiler.executables is actually a dictionary of commands. )divisionabsolute_importprint_function FCompiler new_fcompilershow_fcompilersdummy_fortran_fileN) open_latin1)get_python_lib) FancyGetopt)DistutilsModuleErrorDistutilsExecError CompileError LinkErrorDistutilsPlatformError) split_quoted strtobool) CCompilergen_lib_options)log) is_string all_strings is_sequencemake_temp_fileget_shared_lib_extensionfind_executable) get_exception) _shell_utils)EnvironmentConfigc@s eZdZdS)CompilerNotFoundN)__name__ __module__ __qualname__r%r%E/tmp/pip-install-6_kvzl1k/numpy/numpy/distutils/fcompiler/__init__.pyr!.sr!cCst|rt|S|SdSN)rrsr%r%r&flaglist1sr*cCst|rt|St|Sr')rrboolr(r%r%r&str2bool7sr,cCst|ot|Sr')rr)seqr%r%r&is_sequence_of_strings<sr.c@sxeZdZdZeddddedfdddedfdddedfdddedfd Zedd d d d ddddd Zeddddedfdddedfdddedfdddedfddd edfd!ddedfd"ddedfd#d$d%edfd&ddedfd'ddedfd(d)d*edfd+ddedfd,ddedfd-d.d/edfd0d1d2edfd3d1d2edfd4d5d6edfd7Z d8d8d8d8d8d9d9d9d:Z d9d8gZ dZ d;Z dZgZd8dgd9gd?d@gddAZdZdBZdCZdCZdZdDZgZdEdFdGdHdIdJdKdLdMg ZdNZeZdOZdPZdQZdRZiZ dSdTdUdVdWdXdYdZgZ!dZ"gZ#gZ$d[d\Z%d]d^Z&d_d`Z'dadbZ(e(dSZ)e(dTZ*e(dUZ+e(dVZ,e(dWZ-e(dXZ.e(dYZ/e(dZZ0dcddZ1dedfZ2dgdhZ3didjZ4dkdlZ5dmdnZ6dodpZ7dqdrZ8dsdtZ9dudvZ:dwdxZ;dydzZddZ?ddZ@ddZAe?ZBZCe@ZDZEeAZFZGddZHddZIddgfddZJdddZKddZLddZMddZNddZOddZPdddZQddZRddZSddZTdS)ra0Abstract base class to define the interface that must be implemented by real Fortran compiler classes. Methods that subclasses may redefine: update_executables(), find_executables(), get_version() get_flags(), get_flags_opt(), get_flags_arch(), get_flags_debug() get_flags_f77(), get_flags_opt_f77(), get_flags_arch_f77(), get_flags_debug_f77(), get_flags_f90(), get_flags_opt_f90(), get_flags_arch_f90(), get_flags_debug_f90(), get_flags_fix(), get_flags_linker_so() DON'T call these methods (except get_version) after constructing a compiler instance or inside any other method. All methods, except update_executables() and find_executables(), may call the get_version() method. After constructing a compiler instance, always call customize(dist=None) method that finalizes compiler construction and makes the following attributes available: compiler_f77 compiler_f90 compiler_fix linker_so archiver ranlib libraries library_dirs config_fcNnooptFnoarchdebugverbose)distutils_sectionr0r1r2r3)zexe.compiler_f77ZF77Zf77execNF)zexe.compiler_f90F90f90execNF)zexe.compiler_fixr5r6NF)zexe.version_cmdNNNF)z exe.linker_soLDSHAREDldsharedNF)zexe.linker_exeZLDZldNF)NARarNF)NZRANLIBranlibNF) r4 compiler_f77 compiler_f90 compiler_fix version_cmd linker_so linker_exearchiverr;z flags.f77ZF77FLAGSf77flagsTz flags.f90ZF90FLAGSf90flagsz flags.freeZ FREEFLAGS freeflagsz flags.fixz flags.optZFOPToptz flags.opt_f77z flags.opt_f90z flags.archZFARCHarchzflags.arch_f77zflags.arch_f90z flags.debugZFDEBUGZfdebugzflags.debug_f77zflags.debug_f90zself.get_flagsZFFLAGSfflagszflags.linker_soLDFLAGSZldflagszflags.linker_exezflags.arARFLAGSarflags)r4f77f90freefixrFZopt_f77Zopt_f90rGZarch_f77Zarch_f90r2Z debug_f77Z debug_f90flagsr@rAr:rLrM).f.for.F.ftn.f77.f90.F90.f95r%z-vz-fixedz-sharedr:z-cr)r?r<r=r>r@rArBr;z-cz-o z-IrRrTrUrQrVrXrSrWz.FORz.oz.azlib%s%s%s%sr?r<r=r>r@rArBr;cOsxtj|f|||j|j|_|j|j|_|j|j|_|j|_|j D]}||jkrTd|j|<qTd|_ dS)NF) r__init__distutils_varsclone_environment_hook command_vars flag_vars executablescopy_executable_keys_is_customised)selfargskwer%r%r&r[s    zFCompiler.__init__cCsZ||j}|j|j|j|j|_|j|j|_|j|j|_|j |_ |Sr') __new__ __class____dict__updater\r]r^r_r`rarb)reobjr%r%r&__copy__s  zFCompiler.__copy__cCs|Sr')rnrer%r%r&rbszFCompiler.copycsfdd}t|dS)Ncs|js t|jSr')rdAssertionErrorrarokeyr%r&fgets z)FCompiler._command_property..fget)rs)property)rrrsr%rqr&_command_propertys zFCompiler._command_propertycCs|||dSr') set_commandrerrvaluer%r%r&set_executableszFCompiler.set_executablecKs"|D]\}}|||qdSr')itemsrv)rergkvr%r%r& set_commands szFCompiler.set_commandscCs`||jkrtd||jjft|r.t|}|dksRt|ddsRt||f||j|<dS)Nz$unknown executable '%s' for class %sr) rc ValueErrorrjr"rrr.rprarwr%r%r&rvs  $zFCompiler.set_commandcsjs tjfddfdd}dfdd }j}|d}|st|d }|rftd |qtd |n*|d |d }|std ||d|d |d||d|d||d|d||d|d|ddS)a3Go through the self.executables dictionary, and attempt to find and assign appropriate executables. Executable names are looked for in the environment (environment variables, the distutils.cfg, and command line), the 0th-element of the command list, and the self.possible_executables list. Also, if the 0th element is "" or "", the Fortran 77 or the Fortran 90 compiler executable is used, unless overridden by an environment setting. Subclasses should call this if overridden. cs,|kr|St|}||<|<|Sr'r)exefc_exe) exe_cacher%r&cached_find_executable.s z:FCompiler.find_executables..cached_find_executablecs*|dk r&t|s&td||jjfdS)Nz"%s value %r is invalid in class %s)r.r~rjr")namerxror%r&verify_command_form4s  z7FCompiler.find_executables..verify_command_formNc sj|d}|sdStj|}|s6||gj}n |gj}t}g}|D]@}|dkrb|}n |dkrn|}|rP||kr|qP||||qP|D] } | } | r| |d<| Sq|ddS)Nzzr) ragetgetattrr_possible_executablessetaddappendrv) Zexe_keyrLrMcmdZexe_from_environZ possiblesseenZunique_possiblesrhrr)rrer%r&set_exe9s2       z+FCompiler.find_executables..set_exer=r<z %s: no Fortran 90 compiler foundz%s: f90 nor f77)rMz %s: no Fortran 77 compiler foundr>r@)rLrMrAr?rBr;)NN)rdrp _exe_cache compiler_typerwarnr!)rerrctyperMrLr%)rrrer&find_executabless*      zFCompiler.find_executablescCsdS)aqCalled at the beginning of customisation. Subclasses should override this if they need to set up the executables dictionary. Note that self.find_executables() is run afterwards, so the self.executables dictionary values can contain or as the command, which will be replaced by the found F77 or F90 compiler. Nr%ror%r%r&update_executablesms zFCompiler.update_executablescCs g|jS)z+List of flags common to all compiler types.) pic_flagsror%r%r& get_flagsxszFCompiler.get_flagscCs&|j|d}|dkrgS|ddS)Nr)rar)rerrrr%r%r&_get_command_flags|szFCompiler._get_command_flagscCs |dS)z"List of Fortran 77 specific flags.r<rror%r%r& get_flags_f77szFCompiler.get_flags_f77cCs |dS)z"List of Fortran 90 specific flags.r=rror%r%r& get_flags_f90szFCompiler.get_flags_f90cCsgS)z.List of Fortran 90 free format specific flags.r%ror%r%r&get_flags_freeszFCompiler.get_flags_freecCs |dS)z/List of Fortran 90 fixed format specific flags.r>rror%r%r& get_flags_fixszFCompiler.get_flags_fixcCs |dS)z/List of linker flags to build a shared library.r@rror%r%r&get_flags_linker_soszFCompiler.get_flags_linker_socCs |dS)z,List of linker flags to build an executable.rArror%r%r&get_flags_linker_exeszFCompiler.get_flags_linker_execCs |dS)zList of archiver flags. rBrror%r%r& get_flags_arszFCompiler.get_flags_arcCsgS)z0List of architecture independent compiler flags.r%ror%r%r& get_flags_optszFCompiler.get_flags_optcCsgS)z.List of architecture dependent compiler flags.r%ror%r%r&get_flags_archszFCompiler.get_flags_archcCsgS)z=List of compiler flags to compile with debugging information.r%ror%r%r&get_flags_debugszFCompiler.get_flags_debugcCs|jddS)zList of compiler libraries.N) librariesror%r%r& get_librariesszFCompiler.get_librariescCs|jddS)z%List of compiler library directories.N) library_dirsror%r%r&get_library_dirsszFCompiler.get_library_dirsrcCs,|js ttj|||d}|dkr(t|S)N)force ok_status)rdrpr get_versionr!)rerrversionr%r%r&rs  zFCompiler.get_versioncstdjjd_j|j|j|  j dd}j d|}j dd}jj jj ggg}grtjjjrtjjjjj}jjrtjjjggg}}}fdd} |s:| d ||s:| d ||rJ| d|jj|||} rxj| d rj|| d rj| d j} | r jj} tjdrtdd} tj| dd}tj| dd}|g| d|g} j| | dj }|rDjj }j||djj!}|rljj"}j|g|d#$%&dS)aCustomize Fortran compiler. This method gets Fortran compiler specific information from (i) class definition, (ii) environment, (iii) distutils config files, and (iv) command line (later overrides earlier). This method should be always called after constructing a compiler instance. But not in __init__ because Distribution instance is needed for (iii) and (iv). z customize %sTr0Fr1r2cs|tj|td|}dfdfdffD]>\}}}d||f}|r<|td|k r<|tj|q.get_flagsrFrG)r<)r=)r>aixr) standard_libconfig ld_so_aixz python.expz-bI:)r@)rA)rBN)'rinforjr"rdr\Zuse_distributionr_r`rrrr<r=rZ NativeParsersplitrLrMrNr>rOrPr}r@sysplatform startswithr ospathjoinrArBr:Zset_library_dirsrZ set_librariesr)redistr0r1r2rEZoflagsZaflagsZdflagsrrHr@Zlinker_so_flagsZ python_librZ python_exprAZlinker_exe_flagsr:rKr%rr& customizesz             zFCompiler.customizecCsg}t|jdddddgD]0}t||r t||}||ddt|fq |t|}| d|j j D],}|dd d krd |d d}t |qtdS) z0Print out the attributes of a compiler instance.rrr object_switchcompile_switchNz= z%s instance properties:z --z ) listrakeyshasattrrrreprsortr generate_helprjr"print)repropsrrr|pretty_printerlr%r%r&dump_properties's$    zFCompiler.dump_propertiescCsi}t|r2t|s2d}|j} t|}|jp.g} njt|rld}|j} | dkr`td|jj |f|j phg} n0d}|j } | dkrtd|jj |f|j pg} |j ddkr|j |g} n|j |g} |j st|j|g} | rtd |d dd| f||jg} | r0td d| | || | | || }d tj| d ||f}z|j||dWn(tk rtt}t|YnXdS)zCompile 'src' to product 'obj'.z:f77z:f90Nz%f90 not supported by %s needed for %sz:fixz-f90 (fixed) not supported by %s needed for %s zextra %s options: %rrz%using compile options from source: %rz%s: %sr)display) is_f_filehas_f90_headerr< get_f77flagsextra_f77_compile_argsis_free_formatr=r rjr"extra_f90_compile_argsr>rstriprrprrrrrrrbasenamespawnstrrr)rermsrcextZcc_argsextra_postargsZpp_optsZ src_flagsZflavorcompilerextra_compile_argso_argsZs_args extra_flagscommandrmsgr%r%r&_compile;s`       zFCompiler._compilecCsg}|jdk rH|jddkr2||j|gqb||j|ntd|td|jj|jdk r|g|D]}|d|j|fqvntd|td|jj|S)Nrrz'XXX: module_build_dir=%r option ignoredzXXX: Fix module_dir_switch for rYz"XXX: module_dirs=%r option ignoredz#XXX: Fix module_include_switch for )module_dir_switchrrrrrjr"module_include_switch)reZ module_dirsZmodule_build_diroptionsdr%r%r&module_optionsms    zFCompiler.module_optionscCsd|S)Nz-lr%)relibr%r%r&library_optionszFCompiler.library_optioncCsd|S)Nz-Lr%)redirr%r%r&library_dir_optionszFCompiler.library_dir_optioncCs|||\}}||||\}}}t||||}t|rJtj||}n|dk rZtd|||rr|j ddkr|j |g}n|j |g}t|j r||j g}n ||j }|||}| rdg|dd<| r| |dd<| r| | | tj||tjkr"|jdd}n|jdd}||}z||Wn(tk rntt}t|YnXn td|dS)Nz%'output_dir' must be a string or Nonerrz-grzskipping %s (up-to-date))Z_fix_object_argsZ _fix_lib_argsrrrrr TypeErrorZ _need_linklibrary_switchrobjectsrmkpathdirnamerZ EXECUTABLErAr@rr rrrrr2)reZ target_descrZoutput_filename output_dirrrruntime_library_dirsexport_symbolsr2Z extra_preargsr build_tempZ target_langZlib_optsrZld_argsZlinkerrrr%r%r&linksF        zFCompiler.linkcCs|dkr dSt|r|dr:|dd}t||}|S|drl|dd}|j|}|rf|dSdSq|dr|dd}t|d|}|Sn|SdS) Nzself.zexe.rrzflags.r)rrrra)rer hook_namehookvarr%r%r&r^s$        zFCompiler._environment_hookcCsdS)zc Check if the given C compiler can link objects produced by this compiler. Tr%)reZ ccompilerr%r%r&can_ccompiler_linkszFCompiler.can_ccompiler_linkcCs tdS)a Convert a set of object files that are not compatible with the default linker, to a file that is compatible. Parameters ---------- objects : list List of object files to include. output_dir : str Output directory to place generated object files. extra_dll_dir : str Output directory to place extra DLL files that need to be included on Windows. Returns ------- converted_objects : list of str List of converted object files. Note that the number of output files is not necessarily the same as inputs. N)NotImplementedError)rerrZ extra_dll_dirr%r%r&wrap_unlinkable_objectssz!FCompiler.wrap_unlinkable_objects)N) NNNNNrNNNN)Ur"r#r$__doc__r r,r\r_r*r`Z language_mapZlanguage_orderrcompiler_aliasesZversion_patternrrasuggested_f90_compilerrrrrrrZsrc_extensionsZ obj_extensionrshared_lib_extensionZstatic_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionrrc c_compilerrrr[rnrbrur?r<r=r>r@rArBr;ryr}rvrrrrrrrrrrrrrrZget_flags_opt_f77Zget_flags_opt_f90Zget_flags_arch_f77Zget_flags_arch_f90Zget_flags_debug_f77Zget_flags_debug_f90rrrrrrrrrrr^rrr%r%r%r&r?s(                        O  o2 /) )win32) gnuintelvabsoftcompaqvintelevgnu95g95ZintelvemintelemZflang)zcygwin.*)rrrrrr r )zlinux.*)r intelZlaheypgrnagZvastZcompaqZinteler rr Zpathf95Znagfor)zdarwin.*)r rribmr rr r )zsunos.*)sunrr r )zirix.*)Zmipsrr )zaix.*)rrr )posixrr )ntr)mac)r rr c Csddlm}tdk rdStjtjtd}iaia||D]}tjtj |\}}d|}t |t j |}t |dr>|jD]`}t||}|j||jf}|t|j<|jD]2} | tkrtd| |jt| djf|t| <qqq>dS) zcCache all the FCompiler classes found in modules in the numpy.distutils.fcompiler package. r)globNz*.pyznumpy.distutils.fcompiler. compilersz#alias %r defined for both %s and %sr)rfcompiler_classrrrr__file__fcompiler_aliasessplitextr __import__rmodulesrrrr descriptionrr~r") rZpysfname module_namermodulecnameklassdescaliasr%r%r&load_all_fcompiler_classess0         r%Fc Csddlm}|dd}|D]}d}zt|||d} | || }|r| jdkrd}| j} | rtd|| ft|| |d} | || }|dk r| }|r| jdkrt d| j j Wn>t k rt d|Yn tk rt d |YnX|dk r|SqdS) Nr)get_distributionT)always)platrrz?Trying %r compiler as suggested by %r compiler for f90 support.z2%s does not support compiling f90 codes, skipping.zH_find_existing_fcompiler: compiler_type='%s' raised DistutilsModuleErrorz6_find_existing_fcompiler: compiler_type='%s' not found)Znumpy.distutils.corer&rrrr=rrrr~rjr"r r2r!) Zcompiler_typesosnamer requiref90rr&rrr|rZ new_compilerr%r%r&_find_existing_fcompilersJ      r+cCst|dkrtj}|dkrtj}g}tD]<\}}t||sDt||r$|D]}||krH||qHq$|sp|d|S)Nr)rrrr_default_compilersrematchr)r)rmatching_compiler_typespatternrctr%r%r&!available_fcompilers_for_platform@s  r2cCs,t||}td|t|||||d}|S)zIDetermine the default Fortran compiler to use for the given platform.z+get_default_fcompiler: matching types: '%s')r)rr*r)r2rrr+)r)rr*rr/rr%r%r&get_default_fcompilerOsr3c Cs||f}|tkrdSt|dkr(tj}|dkr>t|||d}|tkrVt|\}} } nb|tkrnt|\}} } nJd|} |dk r| d|} | ddt} t | t |dS| |||d}||_ |S)zhGenerate an instance of some FCompiler subclass for the supplied platform/compiler combination. N)r*rz7don't know how to compile Fortran code on platform '%s'z with '%s' compiler.z Supported compilers are: %s),)r3dry_runr) failed_fcompilersr%rrr3rrrrrrrr) r(rr3r5rr*rZ fcompiler_keyrr"long_descriptionrr%r%r&ras4     c Cs|dkrddlm}ddlm}|}tjtjd|_ dgtjdd|_ z|j dWnt k rtYnX||j d<||g}g}g}tstt}|D]}d}tdz$t||jd } | || }Wn>ttfk r$t} td |ftt| YnX|dkrN|d |dt|d fq| |d |dt|d d |fqt t!t"t!|}dd|D}|#|#|#t$|} | %dt$|} | %d|rt$|} | %dt&ddS)zbPrint list of available compilers (used by the "--help-fcompiler" option to "config_fc"). Nr) Distribution)r/r/rz--help-fcompiler)rr3zshow_fcompilers: %s not found fcompiler=z (%s)cSs"g|]}d|dt|dfqS)r:Nr;)r).0Zfcr%r%r& sz#show_fcompilers..zFortran compilers found:z5Compilers available for this platform, but not found:z)Compilers not available on this platform:z>For compiler details, run 'config_fc --verbose' setup command.)'distutils.distr8Z'numpy.distutils.command.config_compilerr/rrrrargv script_name script_argsremover~cmdclassparse_config_filesparse_command_linerr%r2r set_verbosityrr3rrr r!rr2rrrrrrrr print_helpr) rr8r/rZ compilers_naZ compilers_niZplatform_compilersrr|rrhrr%r%r&rsj             cCs,tdd\}}|d||ddS)NrQ)suffixz# subroutine dummy() end r9)rwriteclose)forr%r%r&rs z.*[.](for|ftn|f77|f)\Zz-[*]-\s*fortran\s*-[*]-z-[*]-\s*f90\s*-[*]-z-[*]-\s*fix\s*-[*]-z[^c*!]\s*[^\s\d\t]cCsd}t|d}|}d}t|r(d}nt|r8d}d}|dkr|r|}|r|ddkr|d8}|ddkrt|dds|d dd krd}q|}q8||S) z(Check if file is in free format Fortran.rri'r! Nrr&)r readline _has_f_header_has_f90_headerrstrip_free_f90_startrJ)fileresultflinenr%r%r&rs&  , rcCs*t|d}|}|t|p(t|S)NrL)r rPrJrR_has_fix_header)rrWrXr%r%r&rs rz=(c|)f77flags\s*\(\s*(?P\w+)\s*\)\s*=\s*(?P.*)cCsti}t|d}d}|D]P}|d7}|dkr.qht|}|s>q|d}|d}t|||<q||S)z Search the first 20 lines of fortran 77 code for line pattern `CF77FLAGS()=` Return a dictionary {:}. rLrrfcnamerH)r _f77flags_rer.grouprrrJ)rrPrWirXmr\rHr%r%r&rs  r__main__)NNFN)NN)NNFN)NNrrrFN)N)Mr __future__rrr__all__rrr-typesZ numpy.compatr distutils.sysconfigr distutils.fancy_getoptr distutils.errorsr r rrrdistutils.utilrrZnumpy.distutils.ccompilerrrZnumpy.distutilsrZnumpy.distutils.misc_utilrrrrrZnumpy.distutils.exec_commandrZnumpy.distutils.compatrr environmentr type __metaclass__ Exceptionr!r*r,r.rr,rrr%r+r2r3rr6rrrcompileIr.rsearchrQrRrZrTrrr]rr"r%r%r%r&s        1 %   ' =