
    Yh                     \    d dl Z d dlZd dlZddlmZ d Z e j                         fdZd Zy)    N   )PkgConfigErrorc                     |j                         D ]d  \  }}|| vr|| |<   t        | |   t              st        d|d      t        |t              st        d|d      | |   j	                  |       f | S )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/django-portfolio.reubendavern.link/venv/lib/python3.12/site-packages/cffi/pkgconfig.pymerge_flagsr      sz     jjl $
Ud?DId3i.# OPPeT*# OPPIU#$ K    c                    ddg}|j                  |       |j                  |        	 t        j                  |t        j                  t        j                        }|j                         \  }}|j                  dk7  r+	 |j                  |      }t        |j                               t        j                  dk\  r"t        |t              s	 |j                  |      }t         j"                  dk7  rd|v rt        d|d	| d|      |S # t        $ r*}t        dt        |      j                               d}~ww xY w# t        $ r Y w xY w# t        $ r t        d|d	| d
|d|      w xY w)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      sZ    
'(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   4D ?E E 	D>%D99D>	EE!E1c                    	
 d d d d d 	d 
	
fd}i }| D ]  } ||      }t        ||        |S )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                 r    | j                         D cg c]  }|j                  d      s|dd   c}S c c}w )N-I   split
startswithstringxs     r   get_include_dirsz.flags_from_pkgconfig.<locals>.get_include_dirsK   -    %||~D!d1C!"DDD   44c                 r    | j                         D cg c]  }|j                  d      s|dd   c}S c c}w )N-Lr4   r5   r8   s     r   get_library_dirsz.flags_from_pkgconfig.<locals>.get_library_dirsN   r<   r=   c                 r    | j                         D cg c]  }|j                  d      s|dd   c}S c c}w )N-lr4   r5   r8   s     r   get_librariesz+flags_from_pkgconfig.<locals>.get_librariesQ   r<   r=   c                 ~    d }| j                         D cg c]  }|j                  d      s ||       c}S c c}w )Nc                 R    | dd  } d| v rt        | j                  dd            S | d fS )Nr4   =r   )tupler6   )r:   s    r   _macroz8flags_from_pkgconfig.<locals>.get_macros.<locals>._macroV   s3    !"AaxQWWS!_--4y r   -Dr5   )r9   rH   r:   s      r   
get_macrosz(flags_from_pkgconfig.<locals>.get_macrosU   s2    	! $*<<>HaQ\\$5Gq	HHHs   :
:c                     | j                         D cg c]'  }|j                  d      r|j                  d      s|) c}S c c}w )Nr3   rI   r5   r8   s     r   get_other_cflagsz.flags_from_pkgconfig.<locals>.get_other_cflags^   B    !<<> Ead1C12d1C  E 	E E
   AAc                     | j                         D cg c]'  }|j                  d      r|j                  d      s|) c}S c c}w )Nr?   rB   r5   r8   s     r   get_other_libsz,flags_from_pkgconfig.<locals>.get_other_libsb   rM   rN   c                     t        j                         }t        | d      }t        | d      } |       |       |       |       |       	|      d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;   rC   r@   rJ   rL   rP   s
       r   kwargsz$flags_from_pkgconfig.<locals>.kwargsg   sc    '')':.
*,Z8,X6&x0'
3"2:">-h7 	r   )r   )libsr\   retr(   	lib_flagsr;   rC   r@   rJ   rL   rP   s        @@@@@@r   flags_from_pkgconfigr`   <   sa    EEEIEE
  C $7O	C#$ Jr   )	r#   r&   r   errorr   r   rX   r0   r`    r   r   <module>rc      s.      !& ";!:!:!< D=r   