
    #	h                     ^    S SK r S SKrS SKrSSKJr  S r\ R                  " 5       4S jrS rg)    N   )PkgConfigErrorc                    UR                  5        Ho  u  p#X ;  a  X0U'   M  [        X   [        5      (       d  [        SU< S35      e[        U[        5      (       d  [        SU< S35      eX   R	                  U5        Mq     U $ )zMerge values from cffi config flags cfg2 to cf1

Example:
    merge_flags({"libraries": ["one"]}, {"libraries": ["two"]})
    {"libraries": ["one", "two"]}
zcfg1[z] should be a list of stringszcfg2[)items
isinstancelist	TypeErrorextend)cfg1cfg2keyvalues       @/var/www/html/env/lib/python3.13/site-packages/cffi/pkgconfig.pymerge_flagsr      sq     jjl
?Idi..# OPPeT**# OPPIU# # K    c                    SS/nUR                  U5        UR                  U 5         [        R                  " U[        R                  [        R                  S9nUR                  5       u  pgUR                  S:w  a+   UR                  U5      n[        UR                  5       5      e[        R                  S:  a'  [        U[        5      (       d   UR                  U5      n[         R"                  S:w  a  SU;   a  [        SU< S	U < SU< 35      eU$ ! [         a+  n[        S[        U5      R                  5       < 35      eSnAff = f! [         a     Nf = f! [         a    [        SU< S	U < S
U< SU< 35      ef = f)z5Calls pkg-config and returns the output if found
    z
pkg-configz--print-errors)stdoutstderrzcannot run pkg-config: Nr   )   zpkg-config  z5 returned bytes that cannot be decoded with encoding z:
\z3 returned an unsupported backslash-escaped output:
)append
subprocessPopenPIPEEnvironmentErrorr   strstripcommunicate
returncodedecode	Exceptionsysversion_infor   UnicodeDecodeErrorosaltsep)libnameflagencodingapceboutberrs           r   callr0      s[    
'(AHHTNHHWNa

P !JD	}}	;;x(D TZZ\**
4
4(=(=	B;;x(D 
yyDTT\"GT3 4 	4 K/  NCFLLNLMMN  		 " 	B "&4"A B B	Bs5   2D =E E 
E
&EE

EE&Fc                    ^^^^^	^
 S mS mS mS mS m	S m
UUUUU	U
4S jn0 nU  H  nU" U5      n[        X$5        M     U$ )a  Return compiler line flags for FFI.set_source based on pkg-config output

Usage
    ...
    ffibuilder.set_source("_foo", pkgconfig = ["libfoo", "libbar >= 1.8.3"])

If pkg-config is installed on build machine, then arguments include_dirs,
library_dirs, libraries, define_macros, extra_compile_args and
extra_link_args are extended with an output of pkg-config for libfoo and
libbar.

Raises PkgConfigError in case the pkg-config call fails.
c                     U R                  5        Vs/ s H  oR                  S5      (       d  M  USS  PM!     sn$ s  snf )N-I   split
startswithstringxs     r   get_include_dirs.flags_from_pkgconfig.<locals>.get_include_dirsK   1    %||~D~!d1C!"~DDD   <	<c                     U R                  5        Vs/ s H  oR                  S5      (       d  M  USS  PM!     sn$ s  snf )N-Lr4   r5   r8   s     r   get_library_dirs.flags_from_pkgconfig.<locals>.get_library_dirsN   r=   r>   c                     U R                  5        Vs/ s H  oR                  S5      (       d  M  USS  PM!     sn$ s  snf )N-lr4   r5   r8   s     r   get_libraries+flags_from_pkgconfig.<locals>.get_librariesQ   r=   r>   c                     S nU R                  5        Vs/ s H"  o"R                  S5      (       d  M  U" U5      PM$     sn$ s  snf )Nc                 V    U SS  n SU ;   a  [        U R                  SS5      5      $ U S 4$ )Nr4   =r   )tupler6   )r:   s    r   _macro8flags_from_pkgconfig.<locals>.get_macros.<locals>._macroV   s3    !"AaxQWWS!_--4y r   -Dr5   )r9   rK   r:   s      r   
get_macros(flags_from_pkgconfig.<locals>.get_macrosU   s6    	! $*<<>H>a\\$5G	q	>HHHs
   AAc                     U R                  5        Vs/ s H4  oR                  S5      (       a  M  UR                  S5      (       a  M2  UPM6     sn$ s  snf )Nr3   rM   r5   r8   s     r   get_other_cflags.flags_from_pkgconfig.<locals>.get_other_cflags^   F    !<<> E>ad1C12d1C > E 	E E   AAAc                     U R                  5        Vs/ s H4  oR                  S5      (       a  M  UR                  S5      (       a  M2  UPM6     sn$ s  snf )Nr@   rD   r5   r8   s     r   get_other_libs,flags_from_pkgconfig.<locals>.get_other_libsb   rS   rT   c                    > [         R                  " 5       n[        U S5      n[        U S5      nT" U5      T" U5      T" U5      T" U5      T" U5      T	" U5      S.$ )Nz--cflagsz--libs)include_dirslibrary_dirs	librariesdefine_macrosextra_compile_argsextra_link_args)r#   getfilesystemencodingr0   )
r(   fse
all_cflagsall_libsr;   rE   rA   rN   rQ   rV   s
       r   kwargs$flags_from_pkgconfig.<locals>.kwargsg   sc    '')':.
*,Z8,X6&x0'
3"2:">-h7 	r   )r   )libsrc   retr(   	lib_flagsr;   rE   rA   rN   rQ   rV   s        @@@@@@r   flags_from_pkgconfigrh   <   sZ    EEEIEE
  C7O	C#  Jr   )	r#   r&   r   errorr   r   r_   r0   rh    r   r   <module>rk      s,      !& "%!:!:!< D=r   