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
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
24 print 'usage: %s {--api-version|--cflags|--ldflags|--libs|--libs-for-gn}' % \
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()
37 for flag
in flags
.split():
39 if flag
.startswith('-l'):
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')
60 if len(sys
.argv
) != 2:
65 if mode
== '--api-version':
66 subprocess
.call(['cups-config', '--api-version'])
69 # All other modes get the flags.
70 if mode
not in ('--cflags', '--libs', '--libs-for-gn', '--ldflags'):
74 if mode
== '--libs-for-gn':
78 gn_libs_output
= False
80 flags
= run_cups_config(mode
)
83 # Strip "-l" from beginning of libs, quote, and surround in [ ].
87 print '"%s", ' % lib
[2:]
95 if __name__
== '__main__':