Created
March 11, 2014 16:08
-
-
Save abergmeier/9488990 to your computer and use it in GitHub Desktop.
pkgconfig for use with distutils.setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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