OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """cups-config wrapper. | 6 """cups-config wrapper. |
7 | 7 |
8 cups-config, at least on Ubuntu Lucid and Natty, dumps all | 8 cups-config, at least on Ubuntu Lucid and Natty, dumps all |
9 cflags/ldflags/libs when passed the --libs argument. gyp would like | 9 cflags/ldflags/libs when passed the --libs argument. gyp would like |
10 to keep these separate: cflags are only needed when compiling files | 10 to keep these separate: cflags are only needed when compiling files |
11 that use cups directly, while libs are only needed on the final link | 11 that use cups directly, while libs are only needed on the final link |
12 line. | 12 line. |
13 | 13 |
14 TODO(evan): remove me once | 14 This can be dramatically simplified or maybe removed (depending on GN |
| 15 requirements) when this is fixed: |
15 https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/163704 | 16 https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/163704 |
16 is fixed. | 17 is fixed. |
17 """ | 18 """ |
18 | 19 |
19 import subprocess | 20 import subprocess |
20 import sys | 21 import sys |
21 | 22 |
22 def usage(): | 23 def usage(): |
23 print 'usage: %s {--cflags|--ldflags|--libs}' % sys.argv[0] | 24 print 'usage: %s {--api-version|--cflags|--ldflags|--libs|--libs-for-gn}' % \ |
| 25 sys.argv[0] |
24 | 26 |
25 | 27 |
26 def run_cups_config(mode): | 28 def run_cups_config(mode): |
27 """Run cups-config with all --cflags etc modes, parse out the mode we want, | 29 """Run cups-config with all --cflags etc modes, parse out the mode we want, |
28 and return those flags as a list.""" | 30 and return those flags as a list.""" |
29 | 31 |
30 cups = subprocess.Popen(['cups-config', '--cflags', '--ldflags', '--libs'], | 32 cups = subprocess.Popen(['cups-config', '--cflags', '--ldflags', '--libs'], |
31 stdout=subprocess.PIPE) | 33 stdout=subprocess.PIPE) |
32 flags = cups.communicate()[0].strip() | 34 flags = cups.communicate()[0].strip() |
33 | 35 |
(...skipping 19 matching lines...) Expand all Loading... |
53 | 55 |
54 return flags_subset | 56 return flags_subset |
55 | 57 |
56 | 58 |
57 def main(): | 59 def main(): |
58 if len(sys.argv) != 2: | 60 if len(sys.argv) != 2: |
59 usage() | 61 usage() |
60 return 1 | 62 return 1 |
61 | 63 |
62 mode = sys.argv[1] | 64 mode = sys.argv[1] |
63 if mode not in ('--cflags', '--libs', '--ldflags'): | 65 if mode == '--api-version': |
| 66 subprocess.call(['cups-config', '--api-version']) |
| 67 return 0 |
| 68 |
| 69 # All other modes get the flags. |
| 70 if mode not in ('--cflags', '--libs', '--libs-for-gn', '--ldflags'): |
64 usage() | 71 usage() |
65 return 1 | 72 return 1 |
| 73 |
| 74 if mode == '--libs-for-gn': |
| 75 gn_libs_output = True |
| 76 mode = '--libs' |
| 77 else: |
| 78 gn_libs_output = False |
| 79 |
66 flags = run_cups_config(mode) | 80 flags = run_cups_config(mode) |
67 print ' '.join(flags) | 81 |
| 82 if gn_libs_output: |
| 83 # Strip "-l" from beginning of libs, quote, and surround in [ ]. |
| 84 print '[' |
| 85 for lib in flags: |
| 86 if lib[:2] == "-l": |
| 87 print '"%s", ' % lib[2:] |
| 88 print ']' |
| 89 else: |
| 90 print ' '.join(flags) |
| 91 |
68 return 0 | 92 return 0 |
69 | 93 |
70 | 94 |
71 if __name__ == '__main__': | 95 if __name__ == '__main__': |
72 sys.exit(main()) | 96 sys.exit(main()) |
OLD | NEW |