o 6a@sdZgdZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z mZddlmZmZddlmZmZdd lmZdd lmZmZmZmZmZdd lmZdd lmZd dl m!Z!e"Z#Gddde$Z%ddZ&ddZ'ddZ(GdddeZ)dZ*da+da,ddZ-   d6ddZ.d7dd Z/  d6d!d"Z0e1a2       d8d#d$Z3d9d%d&Z4d'd(Z5e6d)ej7j8Z9e6d*ej7j:Z;e6d+ej7j:Zd.d/Z?d0d1Z@e6d2ej7ZAd3d4ZBeCd5kre4dSdS):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. ) FCompiler new_fcompilershow_fcompilersdummy_fortran_fileN)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) _shell_utils)EnvironmentConfigc@s eZdZdS)CompilerNotFoundN)__name__ __module__ __qualname__r r D/usr/lib/python3/dist-packages/numpy/distutils/fcompiler/__init__.pyr(srcCst|rt|S|SN)rr sr r r!flaglist+sr%cCst|rt|St|Sr")rrboolr#r r r!str2bool1sr'cCst|ot|Sr")rr)seqr r r!is_sequence_of_strings6r)c @seZdZdZeddddedfdddedfdddedfdddedfd Zedd d d d ddddd ZedGiddddddedfddddedfdddd edfd!d"ddedfd#d$d%d#edfd&d'ddedfd(d)ddedfd*d+d,d*edfd-d.ddedfd/d0ddedfdd1d2d3edfd4d5ddedfd6d7ddedfd8d9d:d;edfdd?edfd@dAd>d?edfdBdCdDdEedfZ dddddddddFZ ddgZ dZ dGZ dZgZddHgdgdgddIgddJgdgdBdKgddLZdZdMZdNZdNZdZdOZgZgdPZdQZeZdRZdSZdTZdUZiZ gdLZ!dZ"gZ#gZ$dVdWZ%dXdYZ&dZd[Z'd\d]Z(e(d^Z)e(d_Z*e(d`Z+e(daZ,e(d<Z-e(d@Z.e(dbZ/e(dcZ0dddeZ1dfdgZ2dhdiZ3djdkZ4dldmZ5dndoZ6dpdqZ7drdsZ8dtduZ9dvdwZ:dxdyZ;dzd{ZddZ?ddZ@ddZAe?ZBZCe@ZDZEeAZFZGddZHddZIddgfddZJdddZKddZLddZMddZNddZOddZP    dddZQddZRddZSddZTdS)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_sectionr,r-r.r/)zexe.compiler_f77F77f77execNF)zexe.compiler_f90F90f90execNF)zexe.compiler_fixr3r4NF)zexe.version_cmdNNNF)z exe.linker_soLDSHAREDldsharedNF)zexe.linker_exeLDldNF)NARarNF)NRANLIBranlibNF) r0 compiler_f77 compiler_f90 compiler_fix version_cmd linker_so linker_exearchiverr<r0f77z flags.f77F77FLAGSf77flagsTf90z flags.f90F90FLAGSf90flagsfreez flags.free FREEFLAGS freeflagsfixz flags.fixoptz flags.optFOPTopt_f77z flags.opt_f77opt_f90z flags.opt_f90archz flags.archFARCHarch_f77zflags.arch_f77arch_f90zflags.arch_f90z flags.debugFDEBUGfdebug debug_f77zflags.debug_f77 debug_f90zflags.debug_f90flagszself.get_flagsFFLAGSfflagsrAzflags.linker_soLDFLAGSldflagsrBzflags.linker_exer:zflags.arARFLAGSarflags).f.for.F.ftn.f77.f90.F90.f95r z-vz-fixedz-sharedz-cr)r@r=r>r?rArBrCr<z-cz-o z-I) rbrdrerarfrhrcrgz.FORz.oz.azlib%s%s%s%scOs~tj|g|Ri||j|j|_|j|j|_|j|j|_|j|_|j D] }||jvr9d|j|<q-d|_ dS)NF) r__init__distutils_varsclone_environment_hook command_vars flag_vars executablescopy_executable_keys_is_customised)selfargskwer r r!rks     zFCompiler.__init__cCsZ||j}|j|j|j|j|_|j|j|_|j|j|_|j |_ |Sr") __new__ __class____dict__updaterlrmrnrorprqrr)ruobjr r r!__copy__s  zFCompiler.__copy__cCs|Sr")r~rur r r!rrzFCompiler.copycsfdd}t|dS)Ncs|jsJ|jSr")rtrqrkeyr r!fgets  z)FCompiler._command_property..fget)r)property)rrr rr!_command_propertys  zFCompiler._command_propertyr@r=r>r?rCr<cCs|||dSr") set_commandrurvaluer r r!set_executabler*zFCompiler.set_executablecKs"|D] \}}|||qdSr")itemsr)rurwkvr r r! set_commandsszFCompiler.set_commandscCs`||jvrtd||jjft|rt|}|dus)t|dds)J||f||j|<dS)Nz$unknown executable '%s' for class %sr)rs ValueErrorrzrrr r)rqrr r r!r s  $zFCompiler.set_commandcsjsJjfddfdd}dfdd }j}|d}|s9|d }|r3td |ntd ||d |d }|sHtd ||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,|vr|St|}||<|<|Sr"r)exefc_exe) exe_cacher r!cached_find_executable(s z:FCompiler.find_executables..cached_find_executablecs.|durt|std||jjfdSdS)Nz"%s value %r is invalid in class %s)r)rrzr)namerrr r!verify_command_form.s z7FCompiler.find_executables..verify_command_formNc sj|d}|s dStj|}|s||gj}n|gj}t}g}|D] }|dkr1|}n|dkr7|}|r=||vr>q(||||q(|D]} | } | r[| |d<| SqK|ddS)Nzzr) rqgetgetattrropossible_executablessetaddappendr) exe_keyrDrGcmdexe_from_environ possiblesseenunique_possiblesrxrr)rrur r!set_exe3s4      z+FCompiler.find_executables..set_exer>r=z %s: no Fortran 90 compiler foundz%s: f90 nor f77)rGz %s: no Fortran 77 compiler foundr?rA)rDrGrBr@rCr<NN)rt _exe_cache compiler_typerwarnr)rurrctyperGrDr )rrrur!find_executabless*        zFCompiler.find_executablescCdS)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 rr r r!update_executablesgs zFCompiler.update_executablescCs g|jS)z+List of flags common to all compiler types.) pic_flagsrr r r! get_flagsr zFCompiler.get_flagscCs&|j|d}|dur gS|ddS)Nr)rqr)rurrr r r!_get_command_flagsvs zFCompiler._get_command_flagscC |dS)z"List of Fortran 77 specific flags.r=rrr r r! get_flags_f77|rzFCompiler.get_flags_f77cCr)z"List of Fortran 90 specific flags.r>rrr r r! get_flags_f90rzFCompiler.get_flags_f90cCgS)z.List of Fortran 90 free format specific flags.r rr r r!get_flags_freezFCompiler.get_flags_freecCr)z/List of Fortran 90 fixed format specific flags.r?rrr r r! get_flags_fixrzFCompiler.get_flags_fixcCr)z/List of linker flags to build a shared library.rArrr r r!get_flags_linker_sorzFCompiler.get_flags_linker_socCr)z,List of linker flags to build an executable.rBrrr r r!get_flags_linker_exerzFCompiler.get_flags_linker_execCr)zList of archiver flags. rCrrr r r! get_flags_arrzFCompiler.get_flags_arcCr)z0List of architecture independent compiler flags.r rr r r! get_flags_optrzFCompiler.get_flags_optcCr)z.List of architecture dependent compiler flags.r rr r r!get_flags_archrzFCompiler.get_flags_archcCr)z=List of compiler flags to compile with debugging information.r rr r r!get_flags_debugrzFCompiler.get_flags_debugcC|jddS)zList of compiler libraries.N) librariesrr r r! get_librarieszFCompiler.get_librariescCr)z%List of compiler library directories.N) library_dirsrr r r!get_library_dirsrzFCompiler.get_library_dirsrcCs,|jsJtj|||d}|durt|S)N)force ok_status)rtr get_versionr)rurrversionr r r!rs zFCompiler.get_versioncstdjjd_j|j|j|  j dd}j d|}j dd}jj jj ggg}grWtjjjrgtjjjjj}jjrytjjjggg}}}fdd} |s| d ||s| d ||r| d|jj|||} rj| d rƈj|| d r҈j| d j} | r jj} tjdrtdd} tj| dd}tj| dd}|g| d|g} j| | dj }|rjj }j||djj!}|r0jj"}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 %sTr,Fr-r.cs|tj|td|}dfdfdffD]\}}}d||f}|r=|td|ur=|tj|qdS)N get_flags_rDrGz%s_%s)extendrrp)tagrZthis_getrcflagvartrDrFrGrIrMfixflagsrur r!rs z&FCompiler.customize..get_flagsrNrR)r=)r>)r?aixr) standard_libconfig ld_so_aixz python.expz-bI:)rA)rB)rCN)'rinforzrrtrluse_distributionrorprrrr=r>r NativeParsersplitrDrGrJr?rMrZrrAsysplatform startswithrospathjoinrBrCr:set_library_dirsr set_librariesr)rudistr,r-r.rLoflagsaflagsdflagsrr\rAlinker_so_flags python_libr python_exprBlinker_exe_flagsr:r`r rr! customizesz            zFCompiler.customizecCsg}t|jgdD]}t||r%t||}||ddt|fq |t|}| d|j j D]}|dddkrId|dd}t |q7dS)z0Print out the attributes of a compiler instance.)rrr object_switchcompile_switchNz= z%s instance properties:z --z ) listrqkeyshasattrrrreprsortr generate_helprzrprint)rupropsrrpretty_printerlr r r!dump_properties!s"     zFCompiler.dump_propertiesc Csi}t|rt|sd}|j} t|}|jpg} n5t|r6d}|j} | dur0td|jj |f|j p4g} nd}|j } | durItd|jj |f|j pMg} |j ddkr]|j |g} n|j |g} |j slJ|j|g} | rtd |d dd| f||jg} | rtd d| | || | | || }d tj| d ||f}z |j||dWdSty}z t|}t|dd}~ww)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 rzrextra_f90_compile_argsr?rstriprrrrrrrrbasenamespawnstrr )rur}srcextcc_argsextra_postargspp_opts src_flagsflavorcompilerextra_compile_argso_argss_args extra_flagscommandrrxmsgr r r!_compile5sd       zFCompiler._compilecCsg}|jdur$|jddkr||j|gn||j|n td|td|jj|jdurJ|g|D] }|d|j|fq;|Std|td|jj|S)Nrrz'XXX: module_build_dir=%r option ignoredzXXX: Fix module_dir_switch for riz"XXX: module_dirs=%r option ignoredz#XXX: Fix module_include_switch for )module_dir_switchrrrrrzrmodule_include_switch)ru module_dirsmodule_build_diroptionsdr r r!module_optionsgs    zFCompiler.module_optionscCd|S)Nz-lr )rulibr r r!library_optionyrzFCompiler.library_optioncCr)Nz-Lr )rudirr r r!library_dir_option{rzFCompiler.library_dir_optionc Cs|||\}}||||\}}}t||||}t|r%tj||}n|dur-td|||r|j ddkrB|j |g}n|j |g}t|j rV||j g}n||j }|||}| rjdg|dd<| rr| |dd<| ry| | | tj||tjkr|jdd}n|jdd}||}z||WdSty}z t|}t|dd}~wwtd|dS)Nz%'output_dir' must be a string or Nonerrz-grzskipping %s (up-to-date))_fix_object_args _fix_lib_argsrrrrr TypeError _need_linklibrary_switchrobjectsrmkpathdirnamer EXECUTABLErBrArr rr rr.)ru target_descr#output_filename output_dirrrruntime_library_dirsexport_symbolsr. extra_preargsr build_temp target_langlib_optsr ld_argslinkerrrxrr r r!link~sJ         zFCompiler.linkcCs|durdSt|rL|dr|dd}t||}|S|dr5|dd}|j|}|r3|dSdS|drJ|dd}t|d|}|SdS|S) Nzself.zexe.rrzflags.r)rrrrq)rur hook_namehookvarr r r!rns&        zFCompiler._environment_hookcCr)zc Check if the given C compiler can link objects produced by this compiler. Tr )ru ccompilerr r r!can_ccompiler_linkszFCompiler.can_ccompiler_linkcCst)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. )NotImplementedError)rur#r) extra_dll_dirr r r!wrap_unlinkable_objectssz!FCompiler.wrap_unlinkable_objectsr") NNNNNrNNNN)Urrr__doc__rr'rlror%rp language_maplanguage_orderrcompiler_aliasesversion_patternrrqsuggested_f90_compilerrrr"rrrsrc_extensions obj_extensionrshared_lib_extensionstatic_lib_extensionstatic_lib_formatshared_lib_format exe_extensionrrs c_compilerrrrkr~rrrr@r=r>r?rArBrCr<rrrrrrrrrrrrrrrrrget_flags_opt_f77get_flags_opt_f90get_flags_arch_f77get_flags_arch_f90get_flags_debug_f77get_flags_debug_f90rrrrrrrrrr2rnr9r<r r r r!r9s((            O  o2 / r) )win32) gnuintelvabsoftcompaqvintelevgnu95g95intelvemintelemflang)zcygwin.*)rRrSrTrUrVrWrX)zlinux.*)rWintellaheypgnvrTnagvastcompaqintelerZrRrXpathf95nagforfujitsu)zdarwin.*)rWr`rTibmr\rRrXr^)zsunos.*)sunrRrWrX)zirix.*)mipsrRrW)zaix.*)rgrRrW)posixrRrW)ntrk)mac)rWrRr^c Csddlm}tdur dStjtjtd}iaia||D]T}tjtj |\}}d|}t |t j |}t |drs|jD]0}t||}|j||jf}|t|j<|jD]} | tvrmtd| |jt| djf|t| <qXqBqdS) 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)rnfcompiler_classrrrr%__file__fcompiler_aliasessplitextr __import__rmodulesrrorr descriptionr@rr) rnpysfname module_namermodulecnameklassdescaliasr r r!load_all_fcompiler_classess6          rFc Csddlm}|dd}|D]x}d}zNt|||d} | || }|rO| jdurOd}| j} | rOtd|| ft|| |d} | || }|durO| }|r^| jdur^t d| j j Wnt ynt d|Ynty|t d |Ynw|dur|Sq dS) Nr)get_distributionT)always)platr rJz?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)numpy.distutils.corerrrrr>rBrrrrzrrr.r) compiler_typesosnamer requiref90rJrrrrr new_compilerr r r!_find_existing_fcompilersP      rcCst|durtj}|durtj}g}tD]\}}t||s"t||r0|D] }||vr/||q$q|s8|d|S)NrR)rrrr_default_compilersrematchr)rrmatching_compiler_typespatternrctr r r!!available_fcompilers_for_platform:s   rcCs,t||}td|t|||||d}|S)zIDetermine the default Fortran compiler to use for the given platform.z+get_default_fcompiler: matching types: '%s')rrrrJ)rrrr)rrrrJrrr r r!get_default_fcompilerIsrc Cs||f}|tvr dSt|durtj}|durt|||d}|tvr+t|\}} } n1|tvr7t|\}} } n%d|} |durP| d|} | ddt} t | t |dS| |||d}||_ |S)zhGenerate an instance of some FCompiler subclass for the supplied platform/compiler combination. N)rrJz7don't know how to compile Fortran code on platform '%s'z with '%s' compiler.z Supported compilers are: %s),)r/dry_runr) failed_fcompilersrrrrrprrrrrrrrJ) rr r/rrrrJ fcompiler_keyryr|long_descriptionrr r r!r[s4     rc Cs|durGddlm}ddlm}|}tjtjd|_ dgtjdd|_ z|j dWn t y9Ynw||j d<||g}g}g}tsRtt}|D]h}d}tdzt||jd } | || }Wn#ttfy} ztd |ftt| WYd} ~ nd} ~ ww|dur|d |dt|d fqW| |d |dt|d d |fqWtt 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)r r/zshow_fcompilers: %s not found fcompiler=z (%s)cSs"g|] }d|dt|dfqS)rNr)rp).0fcr 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.distr'numpy.distutils.command.config_compilerr+rrrrargv script_name script_argsremovercmdclassparse_config_filesparse_command_linerprrr set_verbosityrr/rrrrr.rrrrrrrr print_helpr) rrr+ro compilers_na compilers_niplatform_compilersr rrrxrr r r!rsn              rcCs,tdd\}}|d||ddS)Nra)suffixz# subroutine dummy() end r)rwriteclose)forr r r!rs  rz.*\.(for|ftn|f77|f)\Zz-\*-\s*fortran\s*-\*-z-\*-\s*f90\s*-\*-z-\*-\s*fix\s*-\*-z[^c*!]\s*[^\s\d\t]cCsd}t|dd{}|}d}t|st|rd}nt|r"d}d}|dkrc|rk|}|rQ|ddkrQ|d8}|ddkrFt|dd sN|d dd krQd}n*|}|dkrs|s(Wd|SWd|SWd|SWd|SWd|S1swY|S) z(Check if file is in free format Fortran.rlatin1encodingi'r! Nr3r&)openreadline _has_f_header_has_fix_header_has_f90_headerrstrip_free_f90_start)fileresultflinenr r r!rsD ,     rcCsDt|dd }|}Wdn1swYt|p!t|S)Nrr)rrrr)rrrr r r!rs rz=(c|)f77flags\s*\(\s*(?P\w+)\s*\)\s*=\s*(?P.*)cCsi}t|dd>}d}|D](}|d7}|dkrn%t|}|s!q |d}|d}t|||<q Wd|SWd|S1sIwY|S) z Search the first 20 lines of fortran 77 code for line pattern `CF77FLAGS()=` Return a dictionary {:}. rrrrfcnamer\N)r _f77flags_rergrouprr )rrZrirmrr\r r r!rs&       r__main__)NNFNr)NNrrrFNr")Dr=__all__rrrdistutils.sysconfigrdistutils.fancy_getoptrdistutils.errorsrr r r r distutils.utilr rnumpy.distutils.ccompilerrrnumpy.distutilsrnumpy.distutils.misc_utilrrrrrnumpy.distutils.exec_commandrr environmentrtype __metaclass__ Exceptionrr%r'r)rrrprrrrrrrrrrrcompileIrrsearchrrrrrrrrrr r r r!sz      1 %  '<