o
    e
]                     @  s  d dl mZ d dlZd dlZddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZmZmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZ d dlmZmZmZmZ ejrddlm Z m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z- G dd dee	Z.G dd dee.Z/G dd dee.Z0G dd de.Z1G dd de.Z2G dd  d ee.Z3G d!d" d"e3Z4G d#d$ d$ee.Z5G d%d& d&e5Z6G d'd( d(e.Z7G d)d* d*ee.Z8G d+d, d,ee.Z9G d-d. d.ee.Z:G d/d0 d0e:Z;G d1d2 d2e.Z<G d3d4 d4e.Z=dS )5    )annotationsN   )coredata   )clike_debug_argsCompilerCompileCheckMode)CLikeCompiler)GnuCompilergnulike_buildtype_argsgnu_optimization_args)IntelGnuLikeCompilerIntelVisualStudioLikeCompiler)ClangCompiler)ElbrusCompiler)PGICompiler)version_compareMesonExceptionLibType	OptionKey)MutableKeyedOptionDictTypeKeyedOptionDictType)
Dependency)MachineInfo)Environment)DynamicLinker)MachineChoice)ExternalProgramc                      s   e Zd ZdZ			dTdUddZddddVd d!ZdWd%d&ZdXd*d+ZdYd-d.ZdZd0d1Z	d[d3d4Z
d\ fd5d6Zd]d8d9Zd^d;d<Zd_d?d@Zd`dBdCZejdDfdadJdKZdbdMdNZdbdOdPZdc fdRdSZ  ZS )dFortranCompilerZfortranNexelistT.List[str]versionstrfor_machiner   is_crossboolinfo'MachineInfo'exe_wrapperT.Optional['ExternalProgram']linkerT.Optional['DynamicLinker']full_versionT.Optional[str]c	           	      C  s,   t j| g |||||||d	 t| | d S )N)r$   r,   r*   )r   __init__r	   	selfr   r!   r#   r$   r&   r(   r*   r,    r1   A/usr/lib/python3.10/site-packages/mesonbuild/compilers/fortran.pyr.   5   s   zFortranCompiler.__init__)
extra_argsdependenciesfuncnameprefixenv'Environment'r3   T.Optional[T.List[str]]r4    T.Optional[T.List['Dependency']]returnT.Tuple[bool, bool]c                C  s   t d)NzFortran does not have "has_function" capability.
It is better to test if a Fortran capability is working like:

meson.get_compiler('fortran').links('block; end block; end program')

that example is to see if the compiler has Fortran 2008 Block element.)r   )r0   r5   r6   r7   r3   r4   r1   r1   r2   has_function=   s   zFortranCompiler.has_functionmoder   !T.Tuple[T.List[str], T.List[str]]c                 C  s,   |j | j| j}|j | j| j}||fS N)r   Zget_external_argsr#   languageZget_external_link_args)r0   r7   r>   ZcargsZlargsr1   r1   r2   _get_basic_compiler_argsE   s   z(FortranCompiler._get_basic_compiler_argswork_direnvironmentNonec                 C  s   d}d}|  ||||S )Nzsanitycheckf.f90zFprogram main; print *, "Fortran compilation is working."; end program
)Z_sanity_check_impl)r0   rC   rD   Zsource_namecoder1   r1   r2   sanity_checkJ   s   zFortranCompiler.sanity_check	buildtypec                 C     t | S r@   )r   )r0   rH   r1   r1   r2   get_buildtype_argsO      z"FortranCompiler.get_buildtype_argsoptimization_levelc                 C  rI   r@   )r   )r0   rL   r1   r1   r2   get_optimization_argsR   rK   z%FortranCompiler.get_optimization_argsis_debugc                 C  rI   r@   )r   )r0   rN   r1   r1   r2   get_debug_argsU   rK   zFortranCompiler.get_debug_argsc                   s   dgt    S )N-cpp)superget_preprocess_only_argsr0   	__class__r1   r2   rR   X   s   z(FortranCompiler.get_preprocess_only_argsT.Tuple[str, ...]c                 C     dS )N)-Ir1   rS   r1   r1   r2   get_module_incdir_args[      z&FortranCompiler.get_module_incdir_argspathc                 C     d|gS )Nz-moduler1   r0   r[   r1   r1   r2   get_module_outdir_args^   rK   z&FortranCompiler.get_module_outdir_argsparameter_list	build_dirc              
   C  sd   t |D ]+\}}|d d dks|d d dkr/|d d tjtj||dd   ||< q|S )Nr   rX   -L)	enumerateosr[   normpathjoin)r0   r_   r`   idxir1   r1   r2   &compute_parameters_with_absolute_pathsa   s
    .z6FortranCompiler.compute_parameters_with_absolute_pathsmodule_namec                 C  sh   d|v r,|  }| jdv r|ddd }|S | jdv r&|ddd }|S |d }|S |  d }|S )N_>   zintel-clgccintel@z.smod>   Zpgiflang-z.mod)loweridreplace)r0   ri   sfilenamer1   r1   r2   module_name_to_filenamei   s   

z'FortranCompiler.module_name_to_filenameTlibname
extra_dirslibtyper   lib_prefix_warningc                 C  s   d}|  ||||||S Nzstop; end program)Z_find_library_impl)r0   rv   r7   rw   rx   ry   rF   r1   r1   r2   find_libraryw   s   zFortranCompiler.find_libraryargsc                 C     |  ||dS rz   )Z_has_multi_argumentsr0   r|   r7   r1   r1   r2   has_multi_arguments|      z#FortranCompiler.has_multi_argumentsc                 C  r}   rz   )Z_has_multi_link_argumentsr~   r1   r1   r2   has_multi_link_arguments   r   z(FortranCompiler.has_multi_link_arguments'MutableKeyedOptionDictType'c                   s:   t   }td| j| jd}||tddgdi |S )Nstdmachinelangz Fortran language standard to usenone)rQ   get_optionsr   r#   rA   updater   ZUserComboOptionr0   optskeyrT   r1   r2   r      s   
zFortranCompiler.get_optionsNNNr   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   )r5   r"   r6   r"   r7   r8   r3   r9   r4   r:   r;   r<   )r7   r8   r>   r   r;   r?   )rC   r"   rD   r8   r;   rE   )rH   r"   r;   r    )rL   r"   r;   r    )rN   r%   r;   r    r;   r    r;   rV   r[   r"   r;   r    )r_   r    r`   r"   r;   r    )ri   r"   r;   r"   )rv   r"   r7   r8   rw   r    rx   r   ry   r%   r;   r9   )r|   r    r7   r8   r;   r<   r;   r   )__name__
__module____qualname__rA   r.   r=   rB   rG   rJ   rM   rO   rR   rY   r^   rh   ru   r   ZPREFER_SHAREDr{   r   r   r   __classcell__r1   r1   rT   r2   r   1   s0    	










r   c                   @  sf   e Zd Z				d5d6ddZd7ddZd8ddZd9d d!Zd:d#d$Zd;d'd(Zddd)d*d<d3d4Z	dS )=GnuFortranCompilerNr   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   definesT.Optional[T.Dict[str, str]]r*   r+   r,   r-   c
                 C  sZ   t j| ||||||||	d	 t| | dg}
g |
|
dg |
g d |
g d d| _d S )Nr*   r,   -Wall-Wextra)r   z
-Wpedanticz-fimplicit-none0123Z
everything)r   r.   r
   	warn_args)r0   r   r!   r#   r$   r&   r(   r   r*   r,   default_warn_argsr1   r1   r2   r.      s   

zGnuFortranCompiler.__init__r;   r   c                 C  sd   t | }g d}t| jdr|dg7 }t| jdr|dg7 }td| j| jd}dg| || _|S )	N)legacyf95f2003z>=4.4.0f2008z>=8.0.0f2018r   r   r   )r   r   r   r!   r   r#   rA   choicesr0   r   Zfortran_stdsr   r1   r1   r2   r      s   


zGnuFortranCompiler.get_optionsoptions'KeyedOptionDictType'c                 C  s<   g }t d| j| jd}|| }|jdkr|d|j  |S )Nr   r   r   z-std=r   r#   rA   valueappend)r0   r   r|   r   r   r1   r1   r2   get_option_compile_args   s   
z*GnuFortranCompiler.get_option_compile_args	outtargetoutfilec                 C     g S r@   r1   r0   r   r   r1   r1   r2   get_dependency_gen_args   s   z*GnuFortranCompiler.get_dependency_gen_argsr[   c                 C  
   d| gS Nz-Jr1   r]   r1   r1   r2   r^         
z)GnuFortranCompiler.get_module_outdir_argsr7   r8   c                 C  2   g }|  |dD ]
}|d|  q|ddg S )N	librariesra   z
-lgfortranz-lmZget_compiler_dirsr   r0   r7   Zsearch_dirsdr1   r1   r2   language_stdlib_only_link_flags   s   z2GnuFortranCompiler.language_stdlib_only_link_flagsF)r3   r4   disable_cachehnamer6   r3   IT.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]]r4   r:   r   r<   c                C  s(   | d| d}| j ||||tj|dS )z
        Derived from mixins/clike.py:has_header, but without C-style usage of
        __has_include which breaks with GCC-Fortran 10:
        https://github.com/mesonbuild/meson/issues/7017
        z
#include <>)r3   r4   r>   r   )Zcompilesr   Z
PREPROCESS)r0   r   r6   r7   r3   r4   r   rF   r1   r1   r2   
has_header   s   	
zGnuFortranCompiler.has_headerNNNNr   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   r   r   r*   r+   r,   r-   r   r   r   r;   r    r   r"   r   r"   r;   r    r   r7   r8   r;   r    )r   r"   r6   r"   r7   r8   r3   r   r4   r:   r   r%   r;   r<   )
r   r   r   r.   r   r   r   r^   r   r   r1   r1   r1   r2   r      s    




r   c                   @  s4   e Zd Z				ddddZdddZd ddZdS )!ElbrusFortranCompilerNr   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   r   r   r*   r+   r,   r-   c
           
      C  s*   t j| ||||||||	d	 t|  d S )Nr   )r   r.   r   )
r0   r   r!   r#   r$   r&   r(   r   r*   r,   r1   r1   r2   r.      s   zElbrusFortranCompiler.__init__r;   r   c                 C  s8   t | }g d}td| j| jd}dg| || _|S )N)r   r   r   Zgnur   Zf2008tsr   r   r   r   r   r   r#   rA   r   r   r1   r1   r2   r      s
   
z!ElbrusFortranCompiler.get_optionsr[   c                 C  r   r   r1   r]   r1   r1   r2   r^      r   z,ElbrusFortranCompiler.get_module_outdir_argsr   r   r   r   )r   r   r   r.   r   r^   r1   r1   r1   r2   r      s    
	r   c                   @  s:   e Zd ZdZdZ			ddddZdddZdddZdS ) G95FortranCompiler-Wl,Zg95Nr   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   c	           
      C  sN   t j| ||||||||d	 dg}	g |	|	dg |	ddg |	ddg d| _d S )Nr   r   r   z	-pedanticr   r   r.   r   
r0   r   r!   r#   r$   r&   r(   r*   r,   r   r1   r1   r2   r.      s   

zG95FortranCompiler.__init__r[   r;   c                 C  r   )Nz-fmod=r1   r]   r1   r1   r2   r^      r   z)G95FortranCompiler.get_module_outdir_argsc                 C  r   r@   r1   rS   r1   r1   r2   get_no_warn_args   s   z#G95FortranCompiler.get_no_warn_argsr   r   r   r   )r   r   r   LINKER_PREFIXrq   r.   r^   r   r1   r1   r1   r2   r      s    
r   c                   @  sP   e Zd ZdZdZddd	Zdd
dZdddZdddZdddZ	dddZ
dS )SunFortranCompilerr   sunr   r"   r   r;   r    c                 C     dgS Nz-fppr1   r   r1   r1   r2   r   
     z*SunFortranCompiler.get_dependency_gen_argsc                 C  r   r@   r1   rS   r1   r1   r2   get_always_args  rZ   z"SunFortranCompiler.get_always_argslevelc                 C  r   r@   r1   )r0   r   r1   r1   r2   get_warn_args  rZ   z SunFortranCompiler.get_warn_argsrV   c                 C  rW   )N)z-Mr1   rS   r1   r1   r2   rY     rZ   z)SunFortranCompiler.get_module_incdir_argsr[   c                 C  r   )Nz-moddir=r1   r]   r1   r1   r2   r^     r   z)SunFortranCompiler.get_module_outdir_argsc                 C  r   )Nz-xopenmpr1   rS   r1   r1   r2   openmp_flags  r   zSunFortranCompiler.openmp_flagsNr   r   )r   r"   r;   r    r   r   )r   r   r   r   rq   r   r   r   rY   r^   r   r1   r1   r1   r2   r     s    




r   c                   @  sX   e Zd ZdZdZ			d(d)ddZd*ddZd+ddZd,ddZd-d"d#Z	d.d&d'Z
dS )/IntelFortranCompilerZf90fforZftnZfpprl   Nr   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   c	           
      C  sT   t j| ||||||||d	 t|  g d}	g |	|	ddg ddgddgd| _d S )Nr   )-warnZgeneralr   Ztruncated_sourcer   Zunusedallr   )r   r.   r   r   r   r1   r1   r2   r.   "  s   

zIntelFortranCompiler.__init__r;   r   c                 C  .   t | }td| j| jd}g d|| _|S Nr   r   )r   r   r   r   r   r   r   r   r1   r1   r2   r   3     
z IntelFortranCompiler.get_optionsr   r   c                 C  P   g }t d| j| jd}|| }dddddd}|jdkr&|d	||j   |S )
Nr   r   r   r   f03f08f18r   r   r   r   r   z-stand=r   r0   r   r|   r   r   Zstdsr1   r1   r2   r   9     
z,IntelFortranCompiler.get_option_compile_argsc                 C     ddgS )NrP   z-EPr1   rS   r1   r1   r2   rR   B  rK   z-IntelFortranCompiler.get_preprocess_only_argsr7   r8   c                 C  r   )Nz-lifcorez-limfr1   r0   r7   r1   r1   r2   r   E     z4IntelFortranCompiler.language_stdlib_only_link_flagsr   r   c                 C  s   d| dgS )Nz	-gen-dep=z-gen-depformat=maker1   r   r1   r1   r2   r   I     z,IntelFortranCompiler.get_dependency_gen_argsr   r   r   r   r   r   r   )r   r   r   file_suffixesrq   r.   r   r   rR   r   r   r1   r1   r1   r2   r     s    


	
r   c                   @     e Zd ZdZdS )IntelLLVMFortranCompilerz
intel-llvmNr   r   r   rq   r1   r1   r1   r2   r   M      r   c                   @  sF   e Zd ZdZdgZ			d"d#ddZd$ddZd%ddZd&d d!ZdS )'IntelClFortranCompilerr   z/nologoNr   r    r!   r"   r#   r   r$   r%   r&   r'   targetr(   r)   r*   r+   r,   r-   c
                 C  sP   t j| ||||||||	d	 t| | ddg}
g |
|
dg dgdgd| _d S )Nr   z/warn:generalz/warn:truncated_sourcez/warn:unusedz	/warn:allr   )r   r.   r   r   )r0   r   r!   r#   r$   r&   r   r(   r*   r,   r   r1   r1   r2   r.   W  s   zIntelClFortranCompiler.__init__r;   r   c                 C  r   r   r   r   r1   r1   r2   r   h  r   z"IntelClFortranCompiler.get_optionsr   r   c                 C  r   )
Nr   r   r   r   r   r   r   r   z/stand:r   r   r1   r1   r2   r   n  r   z.IntelClFortranCompiler.get_option_compile_argsr[   c                 C  r   )Nz/module:r1   r]   r1   r1   r2   r^   w  r   z-IntelClFortranCompiler.get_module_outdir_argsr   )r   r    r!   r"   r#   r   r$   r%   r&   r'   r   r"   r(   r)   r*   r+   r,   r-   r   r   r   )	r   r   r   r   Zalways_argsr.   r   r   r^   r1   r1   r1   r2   r   R  s    

	r   c                   @  r   )IntelLLVMClFortranCompilerzintel-llvm-clNr   r1   r1   r1   r2   r   {  r   r   c                   @  ,   e Zd ZdZ			ddddZdddZdS )PathScaleFortranCompilerZ	pathscaleNr   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   c	           
      C  8   t j| ||||||||d	 dg}	g |	|	|	|	d| _d S Nr   z	-fullwarnr   r   r   r1   r1   r2   r.        z!PathScaleFortranCompiler.__init__r;   c                 C  r   Nz-mpr1   rS   r1   r1   r2   r     r   z%PathScaleFortranCompiler.openmp_flagsr   r   r   r   r   r   rq   r.   r   r1   r1   r1   r2   r         r   c                   @  s(   e Zd Z			ddddZdddZdS )PGIFortranCompilerNr   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   c	           
      C  N   t j| ||||||||d	 t|  dg}	g |	|	|	dg |	dg d| _d S Nr   -Minform=informz-Mdclchkr   r   r.   r   r   r   r1   r1   r2   r.        
zPGIFortranCompiler.__init__r7   r8   r;   c                 C  s   g dS )N)
-lpgf90rtlz-lpgf90z-lpgf90_rpm1z-lpgf902r  z
-lpgftnrtlz-lrtr1   r   r1   r1   r2   r     r   z2PGIFortranCompiler.language_stdlib_only_link_flagsr   r   r   )r   r   r   r.   r   r1   r1   r1   r2   r     s    r   c                   @  s"   e Zd ZdZ			ddddZdS )NvidiaHPC_FortranCompilerZ
nvidia_hpcNr   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   c	           
      C  r   r   r  r   r1   r1   r2   r.     r  z"NvidiaHPC_FortranCompiler.__init__r   r   )r   r   r   rq   r.   r1   r1   r1   r2   r    s    r  c                   @  s,   e Zd ZdZ			ddddZdddZdS )FlangFortranCompilerrn   Nr   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   c	           
      C  sD   t j| ||||||||d	 t| i  dg}	g |	|	|	|	d| _d S )Nr   r  r   )r   r.   r   r   r   r1   r1   r2   r.     s   zFlangFortranCompiler.__init__r7   r8   r;   c                 C  r   )Nr   ra   z-lflangz-lpgmathr   r   r1   r1   r2   r     s   z4FlangFortranCompiler.language_stdlib_only_link_flagsr   r   r   )r   r   r   rq   r.   r   r1   r1   r1   r2   r    s    r  c                   @  r   )ArmLtdFlangFortranCompilerZarmltdflangNr   r1   r1   r1   r2   r    r   r  c                   @  r   )Open64FortranCompilerZopen64Nr   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   c	           
      C  r   r   r   r   r1   r1   r2   r.     r   zOpen64FortranCompiler.__init__r;   c                 C  r   r   r1   rS   r1   r1   r2   r     r   z"Open64FortranCompiler.openmp_flagsr   r   r   r   r1   r1   r1   r2   r    r   r  c                   @  sl   e Zd ZdZ			d%d&ddZd'ddZd(ddZed)ddZd'ddZ	d'dd Z
d'd!d"Zd'd#d$ZdS )*NAGFortranCompilerZnagforNr   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   c	           	      C  s4   t j| ||||||||d	 dgg g g g d| _d S )Nr   z-w=allr   r   r/   r1   r1   r2   r.     s   zNAGFortranCompiler.__init__r;   c                 C  s   |  | jS r@   )get_nagfor_quietr!   rS   r1   r1   r2   r     r   z"NAGFortranCompiler.get_always_argsr[   c                 C  r\   )Nz-mdirr1   r]   r1   r1   r2   r^     rK   z)NAGFortranCompiler.get_module_outdir_argsc                 C  s   t | drdgS g S )Nz>=7100z-quiet)r   )r!   r1   r1   r2   r
    s   z#NAGFortranCompiler.get_nagfor_quietc                 C  r   )Nz-PICr1   rS   r1   r1   r2   get_pic_args  r   zNAGFortranCompiler.get_pic_argsc                 C  r   r   r1   rS   r1   r1   r2   rR     r   z+NAGFortranCompiler.get_preprocess_only_argsc                 C  s   |   S r@   )r   rS   r1   r1   r2   get_std_exe_link_args  rK   z(NAGFortranCompiler.get_std_exe_link_argsc                 C  r   )Nz-openmpr1   rS   r1   r1   r2   r   !  r   zNAGFortranCompiler.openmp_flagsr   r   r   r   )r!   r"   r;   r    )r   r   r   rq   r.   r   r^   staticmethodr
  r  rR   r  r   r1   r1   r1   r2   r	    s    




r	  )>
__future__r   typingTrc    r   	compilersr   r   r   Zmixins.cliker	   Z
mixins.gnur
   r   r   Zmixins.intelr   r   Zmixins.clangr   Zmixins.elbrusr   Z
mixins.pgir   Zmesonbuild.mesonlibr   r   r   r   TYPE_CHECKINGr   r   r4   r   Z	envconfigr   rD   r   Zlinkers.linkersr   Zmesonlibr   Zprogramsr   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r	  r1   r1   r1   r2   <module>   sH   ^F0)