Skip to content

Instantly share code, notes, and snippets.

@abergmeier
Created March 11, 2014 16:08
Show Gist options
  • Save abergmeier/9488990 to your computer and use it in GitHub Desktop.
Save abergmeier/9488990 to your computer and use it in GitHub Desktop.
pkgconfig for use with distutils.setup
def pkgconfig(*packages, **kw):
flag_map = {
'-I': 'include_dirs',
'-L': 'library_dirs',
'-l': 'libraries'}
env = os.environ.copy()
# possible narrowing of PkgConfig environment variables
for token in check_output(['pkg-config', '--libs', '--cflags', ' '.join(packages)], env=env).split():
key = token[:2]
try:
arg = flag_map[key]
value = token[2:]
except KeyError:
arg = 'extra_link_args'
value = token
kw.setdefault(arg, []).append(value)
for key, value in kw.iteritems(): # remove duplicated
kw[key] = list(set(value))
return kw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment