OLD | NEW |
1 #!/usr/bin/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 TODO(evan): remove me once |
15 https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/163704 | 15 https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/163704 |
16 is fixed. | 16 is fixed. |
17 """ | 17 """ |
18 | 18 |
19 import subprocess | 19 import subprocess |
20 import sys | 20 import sys |
21 | 21 |
22 def usage(): | 22 def usage(): |
23 print 'usage: %s {--cflags|--ldflags|--libs}' % sys.argv[0] | 23 print 'usage: %s {--cflags|--ldflags|--libs}' % sys.argv[0] |
24 sys.exit(1) | 24 |
25 | 25 |
26 def run_cups_config(mode): | 26 def run_cups_config(mode): |
27 """Run cups-config with all --cflags etc modes, parse out the mode we want, | 27 """Run cups-config with all --cflags etc modes, parse out the mode we want, |
28 and return those flags as a list.""" | 28 and return those flags as a list.""" |
29 | 29 |
30 cups = subprocess.Popen(['cups-config', '--cflags', '--ldflags', '--libs'], | 30 cups = subprocess.Popen(['cups-config', '--cflags', '--ldflags', '--libs'], |
31 stdout=subprocess.PIPE) | 31 stdout=subprocess.PIPE) |
32 flags = cups.communicate()[0].strip() | 32 flags = cups.communicate()[0].strip() |
33 | 33 |
34 flags_subset = [] | 34 flags_subset = [] |
35 for flag in flags.split(): | 35 for flag in flags.split(): |
36 flag_mode = None | 36 flag_mode = None |
37 if flag.startswith('-l'): | 37 if flag.startswith('-l'): |
38 flag_mode = '--libs' | 38 flag_mode = '--libs' |
39 elif (flag.startswith('-L') or flag.startswith('-Wl,')): | 39 elif (flag.startswith('-L') or flag.startswith('-Wl,')): |
40 flag_mode = '--ldflags' | 40 flag_mode = '--ldflags' |
41 elif (flag.startswith('-I') or flag.startswith('-D')): | 41 elif (flag.startswith('-I') or flag.startswith('-D')): |
42 flag_mode = '--cflags' | 42 flag_mode = '--cflags' |
43 | 43 |
44 # Be conservative: for flags where we don't know which mode they | 44 # Be conservative: for flags where we don't know which mode they |
45 # belong in, always include them. | 45 # belong in, always include them. |
46 if flag_mode is None or flag_mode == mode: | 46 if flag_mode is None or flag_mode == mode: |
47 flags_subset.append(flag) | 47 flags_subset.append(flag) |
48 | 48 |
49 return flags_subset | 49 return flags_subset |
50 | 50 |
51 if len(sys.argv) != 2: | 51 |
| 52 def main(): |
| 53 if len(sys.argv) != 2: |
52 usage() | 54 usage() |
| 55 return 1 |
53 | 56 |
54 mode = sys.argv[1] | 57 mode = sys.argv[1] |
55 if mode not in ('--cflags', '--libs', '--ldflags'): | 58 if mode not in ('--cflags', '--libs', '--ldflags'): |
56 usage() | 59 usage() |
57 flags = run_cups_config(mode) | 60 return 1 |
58 print ' '.join(flags) | 61 flags = run_cups_config(mode) |
| 62 print ' '.join(flags) |
| 63 return 0 |
| 64 |
| 65 |
| 66 if __name__ == '__main__': |
| 67 sys.exit(main()) |
OLD | NEW |