[Ozone-Drm] Add support for async content protection
[chromium-blink-merge.git] / printing / cups_config_helper.py
blobf3c22fae964022b177719d519f54489a29a4a15a
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
6 """cups-config wrapper.
8 cups-config, at least on Ubuntu Lucid and Natty, dumps all
9 cflags/ldflags/libs when passed the --libs argument. gyp would like
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
12 line.
14 This can be dramatically simplified or maybe removed (depending on GN
15 requirements) when this is fixed:
16 https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/163704
17 is fixed.
18 """
20 import subprocess
21 import sys
23 def usage():
24 print 'usage: %s {--api-version|--cflags|--ldflags|--libs|--libs-for-gn}' % \
25 sys.argv[0]
28 def run_cups_config(mode):
29 """Run cups-config with all --cflags etc modes, parse out the mode we want,
30 and return those flags as a list."""
32 cups = subprocess.Popen(['cups-config', '--cflags', '--ldflags', '--libs'],
33 stdout=subprocess.PIPE)
34 flags = cups.communicate()[0].strip()
36 flags_subset = []
37 for flag in flags.split():
38 flag_mode = None
39 if flag.startswith('-l'):
40 flag_mode = '--libs'
41 elif (flag.startswith('-L') or flag.startswith('-Wl,')):
42 flag_mode = '--ldflags'
43 elif (flag.startswith('-I') or flag.startswith('-D')):
44 flag_mode = '--cflags'
46 # Be conservative: for flags where we don't know which mode they
47 # belong in, always include them.
48 if flag_mode is None or flag_mode == mode:
49 flags_subset.append(flag)
51 # Note: cross build is confused by the option, and may trigger linker
52 # warning causing build error.
53 if '-lgnutls' in flags_subset:
54 flags_subset.remove('-lgnutls')
56 return flags_subset
59 def main():
60 if len(sys.argv) != 2:
61 usage()
62 return 1
64 mode = sys.argv[1]
65 if mode == '--api-version':
66 subprocess.call(['cups-config', '--api-version'])
67 return 0
69 # All other modes get the flags.
70 if mode not in ('--cflags', '--libs', '--libs-for-gn', '--ldflags'):
71 usage()
72 return 1
74 if mode == '--libs-for-gn':
75 gn_libs_output = True
76 mode = '--libs'
77 else:
78 gn_libs_output = False
80 flags = run_cups_config(mode)
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)
92 return 0
95 if __name__ == '__main__':
96 sys.exit(main())