def pkgconfig(*packages, **kw):
config = kw.setdefault('<STR_LIT>', {})<EOL>optional_args = kw.setdefault('<STR_LIT>', '<STR_LIT>')<EOL>flag_map = {'<STR_LIT>': ['<STR_LIT>', <NUM_LIT:2>],<EOL>'<STR_LIT>': ['<STR_LIT>', <NUM_LIT:2>],<EOL>'<STR_LIT>': ['<STR_LIT>', <NUM_LIT:2>],<EOL>'<STR_LIT>': ['<STR_LIT>', <NUM_LIT:0>],<EOL>'<STR_LIT>': ['<STR_LIT>', <NUM_LIT:0>],<EOL>}<EOL>for package in packages:<EOL><INDENT>for distutils_key, (pkg_option, n) in flag_map.items():<EOL><INDENT>items = subprocess.check_output(['<STR_LIT>', optional_args, pkg_option, package]).decode('<STR_LIT:utf8>').split()<EOL>config.setdefault(distutils_key, []).extend([i[n:] for i in items])<EOL><DEDENT><DEDENT>return config<EOL>
Query pkg-config for library compile and linking options. Return configuration in distutils
Extension format.

Usage:

pkgconfig('opencv')

pkgconfig('opencv', 'libavformat')

pkgconfig('opencv', optional='--static')

pkgconfig('opencv', config=c)

returns e.g.

{'extra_compile_args': [],
 'extra_link_args': [],
 'include_dirs': ['/usr/include/ffmpeg'],
 'libraries': ['avformat'],
 'library_dirs': []}

 Intended use:

 distutils.core.Extension('pyextension', sources=['source.cpp'], **c)

 Set PKG_CONFIG_PATH environment variable for nonstandard library locations.

based on work of Micah Dowty (http://code.activestate.com/recipes/502261-python-distutils-pkg-config/)