/
pkg_config.py
39 lines (31 loc) · 1.03 KB
/
pkg_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import subprocess
import sys
def main():
is_raw = sys.argv[1] == 'raw'
stdout = None if is_raw else subprocess.PIPE
if sys.argv[2] == '--libs':
part_prefix = '-L'
elif sys.argv[2] == '--cflags':
part_prefix = '-I'
else:
raise 'Specify either --libs or --cflags as the second argument.'
try:
process = subprocess.Popen(['pkg-config'] + sys.argv[2:], stdout=stdout, stderr=open(os.devnull, 'wb'))
except OSError:
# pkg-config is probably not installed
return
if is_raw:
process.wait()
return
for part in process.communicate()[0].strip().split():
if part.startswith(part_prefix):
print os.path.realpath(os.path.join(part[2:], sys.argv[1]))
return
if __name__ == '__main__':
main()