blob: f3c22fae964022b177719d519f54489a29a4a15a [file] [log] [blame]
#!/usr/bin/env python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""cups-config wrapper.
cups-config, at least on Ubuntu Lucid and Natty, dumps all
cflags/ldflags/libs when passed the --libs argument. gyp would like
to keep these separate: cflags are only needed when compiling files
that use cups directly, while libs are only needed on the final link
This can be dramatically simplified or maybe removed (depending on GN
requirements) when this is fixed:
is fixed.
import subprocess
import sys
def usage():
print 'usage: %s {--api-version|--cflags|--ldflags|--libs|--libs-for-gn}' % \
def run_cups_config(mode):
"""Run cups-config with all --cflags etc modes, parse out the mode we want,
and return those flags as a list."""
cups = subprocess.Popen(['cups-config', '--cflags', '--ldflags', '--libs'],
flags = cups.communicate()[0].strip()
flags_subset = []
for flag in flags.split():
flag_mode = None
if flag.startswith('-l'):
flag_mode = '--libs'
elif (flag.startswith('-L') or flag.startswith('-Wl,')):
flag_mode = '--ldflags'
elif (flag.startswith('-I') or flag.startswith('-D')):
flag_mode = '--cflags'
# Be conservative: for flags where we don't know which mode they
# belong in, always include them.
if flag_mode is None or flag_mode == mode:
# Note: cross build is confused by the option, and may trigger linker
# warning causing build error.
if '-lgnutls' in flags_subset:
return flags_subset
def main():
if len(sys.argv) != 2:
return 1
mode = sys.argv[1]
if mode == '--api-version':['cups-config', '--api-version'])
return 0
# All other modes get the flags.
if mode not in ('--cflags', '--libs', '--libs-for-gn', '--ldflags'):
return 1
if mode == '--libs-for-gn':
gn_libs_output = True
mode = '--libs'
gn_libs_output = False
flags = run_cups_config(mode)
if gn_libs_output:
# Strip "-l" from beginning of libs, quote, and surround in [ ].
print '['
for lib in flags:
if lib[:2] == "-l":
print '"%s", ' % lib[2:]
print ']'
print ' '.join(flags)
return 0
if __name__ == '__main__':