|
| 1 | +import sys, os |
1 | 2 | from distutils.core import setup, Extension |
2 | | -import subprocess |
| 3 | +from subprocess import Popen, PIPE |
| 4 | + |
| 5 | +def call(*cmd): |
| 6 | + cmd = Popen(cmd, |
| 7 | + stdout=PIPE, stderr=PIPE, |
| 8 | + universal_newlines=True) |
| 9 | + if cmd.wait() == 0: |
| 10 | + return cmd.returncode, cmd.stdout.read() |
| 11 | + else: |
| 12 | + return cmd.returncode, cmd.stderr.read() |
3 | 13 |
|
4 | 14 | def pkgconfig(package, **kw): |
5 | 15 | flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'} |
6 | | - output = subprocess.check_output(['pkg-config', '--libs', '--cflags', package], |
7 | | - universal_newlines=True) |
8 | | - for token in output.split(): |
| 16 | + status, result = call('pkg-config', '--libs', '--cflags', package) |
| 17 | + if status != 0: |
| 18 | + return status, result |
| 19 | + for token in result.split(): |
9 | 20 | kw.setdefault(flag_map.get(token[:2]), []).append(token[2:]) |
10 | | - return kw |
| 21 | + return status, kw |
11 | 22 |
|
12 | | -def lib(name, fallback): |
13 | | - try: |
14 | | - return pkgconfig(name) |
15 | | - except subprocess.CalledProcessError: |
16 | | - return pkgconfig(fallback) |
| 23 | +def lib(*names): |
| 24 | + if '--version' in sys.argv: |
| 25 | + return {} |
| 26 | + results = [] |
| 27 | + for name in names: |
| 28 | + status, result = pkgconfig(name) |
| 29 | + if status == 0: |
| 30 | + return result |
| 31 | + results.append(result) |
| 32 | + sys.stderr.write('Cannot find ' + ' or '.join(names) + ':\n\n' |
| 33 | + + '\n'.join(results) + '\n') |
| 34 | + sys.exit(status) |
17 | 35 |
|
18 | 36 | version = '230' |
19 | 37 | defines = [('PACKAGE_VERSION', '"{}"'.format(version))] |
|
0 commit comments