o
    ldS                     @  s  d dl mZ 	 d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z
ddlmZ ddlmZ ddlmZ e
jrOddlmZ ddlmZ d	d
lmZ neZg dgdZg g g g g g dZg dgdgdgdgdgdgdZdgdgdgdgdgdgdgdgdgdgd
Zg d gd!gd"gd#gd"d$gd%Zd&gd'gd(gd)Zi d*g d+d,g d-d.g d/d0d1gd2d3d4gd5d6gd7g d8d9g d:d;d<gd=d>gd?d@gdAdBdCgdDg dEdFg dGdHdIgdJg dKdLdMgdNdOgg dPdQZg dRdSdTgdUgdVgdWZg dXdYgdZgd[gd\d]gd^gg d_g d`g dadbdcgdddegg dfg dgdhZdigdjgdkdlgdmZ ej!ddnd|dudvZ"G dwdx dxeej#dyZ$G dzd{ d{e$Z%dS )}    )annotationsN   )mesonlib)mlog	OptionKey)ImmutableListProtocol)Environment   )Compilerz-g)FT)plaindebugZdebugoptimizedreleaseZminsizeZcustomz-O0z-Ogz-O1z-O2z-O3z-Os)r   0g123sz-mmmxz-mssez-msse2z-msse3z-mssse3z-msse4.1z-msse4.2z-mavxz-mavx2z
-mfpu=neon)
ZmmxZsseZsse2Zsse3Zssse3Zsse41Zsse42ZavxZavx2Zneonz-fvisibility=defaultz-fvisibility=internalz-fvisibility=hiddenz-fvisibility=protectedz-fvisibility-inlines-hidden) defaultZinternalhiddenZ	protectedinlineshiddenz-fdiagnostics-color=autoz-fdiagnostics-color=alwaysz-fdiagnostics-color=never)autoalwaysnever0.0.0)z-Wcast-qualz-Wconversionz-Wfloat-equalz
-Wformat=2z-Winlinez-Wmissing-declarationsz-Wredundant-declsz-Wshadowz-Wundefz-Wuninitializedz-Wwrite-stringsz3.0.0)z-Wdisabled-optimizationz-Wpackedz-Wpaddedz3.3.0)z-Wmulticharz-Wswitch-defaultz-Wswitch-enumz-Wunused-macrosz4.0.0z-Wmissing-include-dirs4.1.0z-Wunsafe-loop-optimizationsz-Wstack-protectorz4.2.0z-Wstrict-overflow=5z4.3.0)z-Warray-bounds=2z-Wlogical-opz-Wstrict-aliasing=3z-Wvla4.6.0)z-Wdouble-promotionz-Wsuggest-attribute=constz-Wsuggest-attribute=noreturnz-Wsuggest-attribute=purez-Wtrampolines4.7.0z-Wvector-operation-performance4.8.0z-Wsuggest-attribute=format4.9.0z-Wdate-time5.1.0z-Wformat-signednessz-Wnormalized=nfc6.1.0)z-Wduplicated-condz-Wnull-dereferencez-Wshift-negative-valuez-Wshift-overflow=2z-Wunused-const-variable=27.1.0)z-Wallocaz-Walloc-zeroz-Wformat-overflow=2z-Wformat-truncation=2z-Wstringop-overflow=3z7.2.0z-Wduplicated-branches8.1.0)z-Wcast-align=strictz-Wsuggest-attribute=coldz-Wsuggest-attribute=malloc9.1.0z-Wattribute-alias=2z-Wanalyzer-too-complexz-Warith-conversion)z-Wbidi-chars=ucnz-Wopenacc-parallelismz-Wtrivial-auto-var-init)10.1.0z12.1.0)z-Wbad-function-castz-Wmissing-prototypesz-Wnested-externsz-Wstrict-prototypesz-Wold-style-definitionz-Winit-selfz-Wc++-compatz-Wunsuffixed-float-constants)r   z3.4.0r   z4.5.0)z-Wctor-dtor-privacyz-Weffc++z-Wnon-virtual-dtorz-Wold-style-castz-Woverloaded-virtualz-Wsign-promoz-Wstrict-null-sentinelz
-Wnoexceptz-Wzero-as-null-pointer-constantz	-Wabi-tagz-Wuseless-castz-Wconditionally-supported)z-Wsuggest-final-methodsz-Wsuggest-final-typesz-Wsuggest-override)z-Wmultiple-inheritancez-Wplacement-new=2z-Wvirtual-inheritance)z-Waligned-new=allz-Wnoexcept-typez
-Wregisterz-Wcatch-value=3z-Wextra-semiz-Wdeprecated-copy-dtorz-Wredundant-move)z-Wcomma-subscriptz-Wmismatched-tagsz-Wredundant-tagsz
-Wvolatile)z!-Wdeprecated-enum-enum-conversionz"-Wdeprecated-enum-float-conversionz-Winvalid-imported-macros)r   z4.0.1r   r   r    r!   r"   r#   r$   r%   r&   r'   z11.1.0z
-Wselectorz-Wundeclared-selectorz-Wassign-interceptz-Wstrict-selector-match)r   z3.3r   )maxsizecompilerT.Tuple[str, ...]langstrreturn'ImmutableListProtocol[str]'c           
      C  s  ddddd}||vrg S || }t j }d|d< t| d| d	d
dg }tj|tj|d\}}}d}g }|dD ]2}	|		d}	|dkrN|	dkrMd}q<|dkr_|	dkrYd}q<|
|	 q<|dkrn|	dkri n|
|	 q<|s}tdjd|d |dd |D 7 }|S )Nczc++zobjective-czobjective-c++)r/   cppobjcobjcppCLC_ALL-xz-Ez-v-)stderrenvr   
z 
	z"#include "..." search starts here:   z"#include <...> search starts here:r
   zEnd of search list.z1No include directory found parsing "{cmd}" output )cmdc                 S  s   g | ]}t j|qS  )ospathnormpath).0xr=   r=   ~home/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/compilers/mixins/gnu.py
<listcomp>n  s    z0gnulike_default_include_dirs.<locals>.<listcomp>)r>   environcopylistr   Z
Popen_safe
subprocessSTDOUTsplitstripappendr   warningformatjoin)
r)   r+   Zlang_mapr8   r<   _stdoutZparse_statepathsliner=   r=   rC   gnulike_default_include_dirsK  sB   


rT   c                   @  sf  e Zd ZdZdZdbddZdcdd	Zdcd
dZddddZe	j
deddZdfddZe	j
dgddZdhddZdidd Zdcd!d"Ze	j
dcd#d$Zdjd&d'Zdkd)d*Zdgd+d,Zdcd-d.Zdcd/d0Zdld2d3Zdmd6d7Ze dnd:d;Zdod=d>Zdpd@dAZdBdCdDdqdHdIZdrdJdKZdsdMdNZ dtdQdRZ!dcdSdTZ"dudWdXZ#e$dvd[d\Z%dcd]d^Z&dcd_d`Z'daS )wGnuLikeCompilera   
    GnuLikeCompiler is a common interface to all compilers implementing
    the GNU-style commandline interface. This includes GCC, Clang
    and ICC. Certain functionality between them is different and requires
    that the actual concrete subclass define their own implementation.
    z-Wl,r-   Nonec                 C  s   dd dD | _ | j s| j s| j s| j td | j r)| j r1| j td | j s>| j td | jd | jd d S )	Nc                 S  s   h | ]}t |qS r=   r   )rA   or=   r=   rC   	<setcomp>}  s    z+GnuLikeCompiler.__init__.<locals>.<setcomp>)Zb_pchZb_ltoZb_pgoZ
b_coverageZb_ndebugZb_staticpicZb_pieZb_lundefZ
b_asneededZ
b_sanitizer   Zsx)	base_optionsinfo
is_windows	is_cygwinZ
is_openbsdaddr   Zis_hurdZcan_compile_suffixesselfr=   r=   rC   __init__|  s   
zGnuLikeCompiler.__init__T.List[str]c                 C  s(   | j  s| j  s| j  rg S dgS )Nz-fPIC)rZ   r[   r\   Z	is_darwinr^   r=   r=   rC   get_pic_args  s   zGnuLikeCompiler.get_pic_argsc                 C     dgS )Nz-fPIEr=   r^   r=   r=   rC   get_pie_args     zGnuLikeCompiler.get_pie_args	buildtyper,   c                 C     t | S N)gnulike_buildtype_args)r_   rf   r=   r=   rC   get_buildtype_args     z"GnuLikeCompiler.get_buildtype_argsoptimization_levelc                 C     d S rh   r=   r_   rl   r=   r=   rC   get_optimization_args     z%GnuLikeCompiler.get_optimization_argsis_debugboolc                 C  rg   rh   )clike_debug_args)r_   rq   r=   r=   rC   get_debug_args  rk   zGnuLikeCompiler.get_debug_argsc                 C  rm   rh   r=   r^   r=   r=   rC   get_pch_suffix  rp   zGnuLikeCompiler.get_pch_suffixfnameT.Tuple[str, str]c                 C  s   t j||fS rh   )r>   r?   dirname)r_   rv   r=   r=   rC   split_shlib_to_parts     z$GnuLikeCompiler.split_shlib_to_partsinstruction_setT.Optional[T.List[str]]c                 C  s   t |d S rh   )gnulike_instruction_set_argsget)r_   r{   r=   r=   rC   get_instruction_set_args  s   z(GnuLikeCompiler.get_instruction_set_argsc                 C  s   t t| jdd| j S )NF)Zccache)rT   tupleZget_exelistlanguagerF   r^   r=   r=   rC   get_default_include_dirs  s   z(GnuLikeCompiler.get_default_include_dirsc                 C  rm   rh   r=   r^   r=   r=   rC   openmp_flags  rp   zGnuLikeCompiler.openmp_flagsvistypec                 C  s   |dkr| j dvrd}t| S )Nr   >   r0   r2   r   )r   gnu_symbol_visibility_args)r_   r   r=   r=   rC   r     s   z*GnuLikeCompiler.gnu_symbol_visibility_argsdefsfilec                 C  s0   t |ts	td| j s| j r|gS g S )Nz%Module definitions file should be str)
isinstancer,   RuntimeErrorrZ   r[   r\   )r_   r   r=   r=   rC   gen_vs_module_defs_args  s
   
z'GnuLikeCompiler.gen_vs_module_defs_argsc                 C     dS )Ngccr=   r^   r=   r=   rC   get_argument_syntax     z#GnuLikeCompiler.get_argument_syntaxc                 C  rc   )Nz-fprofile-generater=   r^   r=   r=   rC   get_profile_generate_args  re   z)GnuLikeCompiler.get_profile_generate_argsc                 C  rc   )Nz-fprofile-user=   r^   r=   r=   rC   get_profile_use_args  re   z$GnuLikeCompiler.get_profile_use_argsvaluec                 C  s   |rdgS dgS )Nz	-mwindowsz	-mconsoler=   )r_   r   r=   r=   rC   get_gui_app_args  rz   z GnuLikeCompiler.get_gui_app_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
   -Iz-L)	enumerater>   r?   r@   rO   )r_   r   r   idxir=   r=   rC   &compute_parameters_with_absolute_paths  s
    .z6GnuLikeCompiler.compute_parameters_with_absolute_pathsr8   'Environment'c                 C  sF   dg}| j d||d ddd}|jW  d    S 1 sw   Y  d S )Nz--print-search-dirsr   compileT)
extra_argsdependenciesmodeZwant_output)_build_wrapperrQ   )r_   r8   r   pr=   r=   rC   _get_search_dirs  s   
$z GnuLikeCompiler._get_search_dirspathstrc           	   	   C  s   t j}|dkrtdd|}dd ||D }g }|D ]6}t|}| }| rR||vr4|	| zt|
  }||vrG|	| W q tyQ   Y qw q|S )N;z	:([^/\\])z;\1c                 S  s   g | ]}|r|qS r=   r=   )rA   r   r=   r=   rC   rD     s    z:GnuLikeCompiler._split_fetch_real_dirs.<locals>.<listcomp>)r>   pathsepresubrJ   pathlibPathas_posixexistsrL   resolveFileNotFoundError)	r_   r   r   rR   resultr   ZpobjZ
unresolvedresolvedr=   r=   rC   _split_fetch_real_dirs  s*   
	

	z&GnuLikeCompiler._split_fetch_real_dirsnamec                 C  sF   |  |}|dD ]}||d r | |ddd   S q
g S )zP
        Get dirs from the compiler, either `libraries:` or `programs:`
        r9   :=r:   )r   rJ   
startswithr   )r_   r8   r   ZstdorS   r=   r=   rC   get_compiler_dirs  s   
z!GnuLikeCompiler.get_compiler_dirsr   r   threadsr   r   intr   c                C  rc   )Nz-fltor=   r_   r   r   r=   r=   rC   get_lto_compile_args     z$GnuLikeCompiler.get_lto_compile_argsc                 C  s,   |dkrg S d| g}d|v r| d |S )Nnonez-fsanitize=addressz-fno-omit-frame-pointer)rL   )r_   r   argsr=   r=   rC   sanitizer_compile_args  s   

z&GnuLikeCompiler.sanitizer_compile_argstargetc                 C  s   d|gS )N-or=   )r_   r   r=   r=   rC   get_output_args  rk   zGnuLikeCompiler.get_output_args	outtargetoutfilec                 C  s   dd|d|gS )Nz-MDz-MQz-MFr=   )r_   r   r   r=   r=   rC   get_dependency_gen_args     z'GnuLikeCompiler.get_dependency_gen_argsc                 C  rc   )Nz-cr=   r^   r=   r=   rC   get_compile_only_args  re   z%GnuLikeCompiler.get_compile_only_argsr?   	is_systemc                 C  s    |sd}|rd| gS d| gS )N.z-isystemr   r=   )r_   r?   r   r=   r=   rC   get_include_args  s
   

z GnuLikeCompiler.get_include_argslinkerversionc                 C  s&   |dvrt d| dd| gS )N>   ZbfdZgoldZlldz?Unsupported linker, only bfd, gold, and lld are supported, not r   z	-fuse-ld=)r   ZMesonExceptionclsr   r   r=   r=   rC   use_linker_args#  s
   
zGnuLikeCompiler.use_linker_argsc                 C  rc   )Nz
--coverager=   r^   r=   r=   rC   get_coverage_args*  re   z!GnuLikeCompiler.get_coverage_argsc                 C  s   |   ddg S )Nr5   zassembler-with-cpp)Zget_preprocess_only_argsr^   r=   r=   rC   get_preprocess_to_file_args-  s   z+GnuLikeCompiler.get_preprocess_to_file_argsN)r-   rV   r-   ra   )rf   r,   r-   ra   rl   r,   r-   ra   )rq   rr   r-   ra   r-   r,   )rv   r,   r-   rw   )r{   r,   r-   r|   )r   r,   r-   ra   )r   r,   r-   ra   )r   rr   r-   ra   )r   ra   r   r,   r-   ra   )r8   r   r-   r,   )r   r,   r-   ra   )r8   r   r   r,   r-   ra   r   r   r   r,   r-   ra   )r   r,   r-   ra   )r   r,   r-   ra   )r   r,   r   r,   r-   ra   )r?   r,   r   rr   r-   ra   r   r,   r   r,   r-   ra   )(__name__
__module____qualname____doc__ZLINKER_PREFIXr`   rb   rd   rj   abcabstractmethodro   rt   ru   ry   r   r   r   r   r   r   r   r   r   r   	functools	lru_cacher   r   r   r   r   r   r   r   r   classmethodr   r   r   r=   r=   r=   rC   rU   r  sL    

















%






rU   )	metaclassc                      s   e Zd ZdZdZd> fddZd?ddZd@ fddZdAddZdBddZ	dCddZ
dDddZdEddZdFd d!ZdGd(d)ZdHd+d,ZdId/d0Zd1d2d3dJ fd6d7ZedK fd:d;ZdF fd<d=Z  ZS )LGnuCompilerz
    GnuCompiler represents an actual GCC in its many incarnations.
    Compilers imitating GCC (Clang/Intel) should use the GnuLikeCompiler ABC.
    r   definesT.Optional[T.Dict[str, str]]c                   s0   t    |pi | _| jtdtdh d S )NZ
b_coloroutZb_lto_threads)superr`   r   rY   updater   )r_   r   	__class__r=   rC   r`   ;  s   

zGnuCompiler.__init__	colortyper,   r-   ra   c                 C  s"   t | jdrt| d d  S g S )Nz>=4.9.0)r   version_comparer   gnu_color_args)r_   r   r=   r=   rC   get_colorout_args@  s   zGnuCompiler.get_colorout_argslevelc                   s4   t  |}t| jdrd|v rd||d< |S )Nz<4.8.0z
-Wpedanticz	-pedantic)r   get_warn_argsr   r   r   index)r_   r   r   r   r=   rC   r   E  s   zGnuCompiler.get_warn_argswarn_args_by_versionT.Dict[str, T.List[str]]c                 C  s4   g }|  D ]\}}t| jd| r||7 }q|S )Nz>=)itemsr   r   r   )r_   r   r   r   Z	warn_argsr=   r=   rC   supported_warn_argsN  s   zGnuCompiler.supported_warn_argsdefinerr   c                 C  s
   || j v S rh   r   r_   r   r=   r=   rC   has_builtin_defineU  s   
zGnuCompiler.has_builtin_defineT.Optional[str]c                 C  s   || j v r
| j | S d S rh   r   r   r=   r=   rC   get_builtin_defineX  s   

zGnuCompiler.get_builtin_definerl   c                 C  rg   rh   )gnu_optimization_argsrn   r=   r=   rC   ro   ]  rk   z!GnuCompiler.get_optimization_argsc                 C  r   )NZgchr=   r^   r=   r=   rC   ru   `  r   zGnuCompiler.get_pch_suffixc                 C  rc   )Nz-fopenmpr=   r^   r=   r=   rC   r   c  re   zGnuCompiler.openmp_flagsr   r8   r   coder   T.Tuple[bool, bool]c                 C  sv   |  |||d |%}|jdk}| jdv rd|jv rd}| jdv r'd|jv r'd}W d    n1 s1w   Y  ||jfS )Nr   >   r0   r2   zis valid for C/ObjCF>   r/   r1   zis valid for C++/ObjC++)r   
returncoder   r7   cached)r_   r   r8   r   r   r   r   r=   r=   rC   has_argumentsf  s   

zGnuCompiler.has_argumentsr   c                 C  rc   )Nz-Werror=attributesr=   )r_   r   r=   r=   rC   !get_has_func_attribute_extra_argss  r   z-GnuCompiler.get_has_func_attribute_extra_argsprelink_nameobj_listc                 C  s   dd|g| S )Nz-rr   r=   )r_   r   r   r=   r=   rC   get_prelink_argsx  r   zGnuCompiler.get_prelink_argsr   r   r   r   r   c                  sN   |dkrt | jdrdgS dt  gS |dkr d| gS t j|dS )Nr   z>= 10.0z
-flto=autoz-flto=)r   )r   r   r   multiprocessing	cpu_countr   r   r   r   r=   rC   r   {  s   z GnuCompiler.get_lto_compile_argsr   r   c                   s(   |dkrt |drdgS t ||S )NZmoldz>=12.0.1z-fuse-ld=mold)r   r   r   r   r   r   r=   rC   r     s   zGnuCompiler.use_linker_argsc                   s   t   dg S )Nz-fprofile-correction)r   r   r^   r   r=   rC   r     rz   z GnuCompiler.get_profile_use_args)r   r   )r   r,   r-   ra   )r   r,   r-   ra   )r   r   r-   ra   )r   r,   r-   rr   )r   r,   r-   r   r   r   r   )
r   ra   r8   r   r   r,   r   r,   r-   r   )r   r,   r-   ra   )r   r,   r   ra   r-   ra   r   r   )r   r   r   r   idr`   r   r   r   r   r   ro   ru   r   r   r   r   r   r   r   r   __classcell__r=   r=   r   rC   r   4  s&    

	








r   )r)   r*   r+   r,   r-   r.   )&
__future__r   r   r   r>   r  r   r   rH   typingTr   r   r   r   TYPE_CHECKINGZ_typingr   environmentr	   	compilersr   objectrs   ri   r   r}   r   r   Zgnu_common_warning_argsZgnu_c_warning_argsZgnu_cpp_warning_argsZgnu_objc_warning_argsr   rT   ABCMetarU   r   r=   r=   r=   rC   <module>   sH  

 #)0369=DKNSWj	C
& C