| 1 | import sys |
|---|
| 2 | import os |
|---|
| 3 | from commands import getstatusoutput, getoutput |
|---|
| 4 | |
|---|
| 5 | def pkgc_version_check(name, longname, req_version): |
|---|
| 6 | is_installed = not os.system('pkg-config --exists %s' % name) |
|---|
| 7 | if not is_installed: |
|---|
| 8 | print "Could not find %s" % longname |
|---|
| 9 | return 0 |
|---|
| 10 | |
|---|
| 11 | orig_version = getoutput('pkg-config --modversion %s' % name) |
|---|
| 12 | version = map(int, orig_version.split('.')) |
|---|
| 13 | pkc_version = map(int, req_version.split('.')) |
|---|
| 14 | |
|---|
| 15 | if version >= pkc_version: |
|---|
| 16 | return True |
|---|
| 17 | else: |
|---|
| 18 | print "Warning: Too old version of %s" % longname |
|---|
| 19 | print " Need %s, but %s is installed" % \ |
|---|
| 20 | (pkc_version, orig_version) |
|---|
| 21 | return False |
|---|
| 22 | |
|---|
| 23 | def pkc_get_dirs(names, option, flag): |
|---|
| 24 | retval = [] |
|---|
| 25 | for name in names: |
|---|
| 26 | output = getoutput(' '.join(['pkg-config', option, name])) |
|---|
| 27 | retval.extend(output.replace(flag, '').split()) |
|---|
| 28 | return retval |
|---|
| 29 | |
|---|
| 30 | def pkc_get_include_dirs(*names): |
|---|
| 31 | return pkc_get_dirs(names, '--cflags-only-I', '-I') |
|---|
| 32 | |
|---|
| 33 | def pkc_get_libraries(*names): |
|---|
| 34 | return pkc_get_dirs(names, '--libs-only-l', '-l') |
|---|
| 35 | |
|---|
| 36 | def pkc_get_library_dirs(*names): |
|---|
| 37 | return pkc_get_dirs(names, '--libs-only-L', '-L') |
|---|