summaryrefslogtreecommitdiffstats
path: root/source-builder/pkg-config
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2014-02-11 10:18:35 +1100
committerChris Johns <chrisj@rtems.org>2014-02-11 10:18:35 +1100
commitc4fefdeb551d8beb8fb8188609924d9bdf468e70 (patch)
tree577708235ad136f6ac2c6a80422ef3d4166047e0 /source-builder/pkg-config
parentconfig: Add support to build qemu. (diff)
downloadrtems-source-builder-c4fefdeb551d8beb8fb8188609924d9bdf468e70.tar.bz2
sb: Add pkg-config support.
Add a pkg-config look alike command so packages that use pkg-config can build if pkg-config is not present on a host. Add support to query package config from configuration scripts.
Diffstat (limited to 'source-builder/pkg-config')
-rwxr-xr-xsource-builder/pkg-config244
1 files changed, 244 insertions, 0 deletions
diff --git a/source-builder/pkg-config b/source-builder/pkg-config
new file mode 100755
index 0000000..6d603c7
--- /dev/null
+++ b/source-builder/pkg-config
@@ -0,0 +1,244 @@
+#! /usr/bin/env python
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2014 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+import argparse
+import os
+import sys
+
+base = os.path.dirname(sys.argv[0])
+sys.path.insert(0, base + '/sb')
+
+try:
+ import pkgconfig
+except ImportError:
+ print >> sys.stderr, "Incorrect Source Builder installation"
+ sys.exit(1)
+
+#
+# Make trace true to get a file of what happens and what is being asked.
+#
+trace = True
+trace_stdout = False
+logfile = 'pkg-config.log'
+out = None
+
+#
+# Write all the package source parsed to a single file.
+#
+trace_src = True
+if trace_src:
+ src = open('pkg-src.txt', 'w')
+
+def log(s, lf = True):
+ global trace, logfile, out
+ if trace:
+ if out is None:
+ if logfile:
+ out = open(logfile, 'a')
+ else:
+ out = sys.stdout
+ if lf:
+ if out != sys.stdout and trace_stdout:
+ print s
+ print >> out, s
+ else:
+ if out != sys.stdout and trace_stdout:
+ print s,
+ print >> out, s,
+
+def _check_package(lib_check, args):
+ ec = 1
+ pkg = None
+ flags = { 'cflags': '',
+ 'libs': '' }
+ libs = pkgconfig.package.splitter(lib_check)
+ for lib in libs:
+ log('pkg: %s' % (lib))
+ pkg = pkgconfig.package(lib[0], prefix = args.prefix, output = log, src = src)
+ if args.dump:
+ log(pkg)
+ if pkg.exists():
+ if len(lib) == 1:
+ if args.exact_version:
+ if pkg.check('=', args.exact_version):
+ ec = 0
+ elif args.atleast_version:
+ if pkg.check('>=', args.atleast_version):
+ ec = 0
+ elif args.max_version:
+ if pkg.check('<=', args.max_version):
+ ec = 0
+ else:
+ ec = 0
+ else:
+ if len(lib) != 3:
+ raise error('invalid package check: %s' % (' '.join(lib)))
+ if pkg.check(lib[1], lib[2]):
+ ec = 0
+ if ec == 0:
+ flags['cflags'] += pkg.get('cflags')
+ flags['libs'] += pkg.get('libs', private = False)
+ break
+ if ec > 0:
+ break
+ return ec, pkg, flags
+
+def run(argv):
+
+ class version_action(argparse.Action):
+ def __call__(self, parser, namespace, values, option_string = None):
+ parts = values[0].strip().split('.')
+ for p in parts:
+ if not p.isdigit():
+ raise error('invalid version value: %s' % (values))
+ setattr(namespace, self.dest, '.'.join(parts))
+
+ ec = 0
+
+ opts = argparse.ArgumentParser(prog = 'pkg-config', description = 'Package Configuration.')
+ opts.add_argument('libraries', metavar='lib', type = str, help = 'a library', nargs = '*')
+ opts.add_argument('--modversion', dest = 'modversion', action = 'store', default = None,
+ help = 'Requests that the version information of the libraries.')
+ opts.add_argument('--print-errors', dest = 'print_errors', action = 'store_true',
+ default = False,
+ help = 'Print any errors.')
+ opts.add_argument('--short-errors', dest = 'short_errors', action = 'store_true',
+ default = False,
+ help = 'Make error messages short.')
+ opts.add_argument('--silence-errors', dest = 'silence_errors', action = 'store_true',
+ default = False,
+ help = 'Do not print any errors.')
+ opts.add_argument('--errors-to-stdout', dest = 'errors_to_stdout', action = 'store_true',
+ default = False,
+ help = 'Print errors to stdout rather than stderr.')
+ opts.add_argument('--cflags', dest = 'cflags', action = 'store_true',
+ default = False,
+ help = 'This prints pre-processor and compile flags required to' \
+ ' compile the package(s)')
+ opts.add_argument('--libs', dest = 'libs', action = 'store_true',
+ default = False,
+ help = 'This option is identical to "--cflags", only it prints the' \
+ ' link flags.')
+ opts.add_argument('--libs-only-L', dest = 'libs_only_L', action = 'store_true',
+ default = False,
+ help = 'This prints the -L/-R part of "--libs".')
+ opts.add_argument('--libs-only-l', dest = 'libs_only_l', action = 'store_true',
+ default = False,
+ help = 'This prints the -l part of "--libs".')
+ opts.add_argument('--variable', dest = 'variable', action = 'store',
+ nargs = 1, default = None,
+ help = 'This returns the value of a variable.')
+ opts.add_argument('--define-variable', dest = 'define_variable', action = 'store',
+ nargs = 1, default = None,
+ help = 'This sets a global value for a variable')
+ opts.add_argument('--uninstalled', dest = 'uninstalled', action = 'store_true',
+ default = False,
+ help = 'Ignored')
+ opts.add_argument('--atleast-pkgconfig-version', dest = 'atleast_pkgconfig_version',
+ action = 'store', nargs = 1, default = None,
+ help = 'Check the version of package config. Always ok.')
+ opts.add_argument('--exists', dest = 'exists', action = 'store_true',
+ default = False,
+ help = 'Test if a library is present')
+ opts.add_argument('--atleast-version', dest = 'atleast_version',
+ action = version_action, nargs = 1, default = None,
+ help = 'The package is at least this version.')
+ opts.add_argument('--exact-version', dest = 'exact_version', action = version_action,
+ nargs = 1, default = None,
+ help = 'The package is the exact version.')
+ opts.add_argument('--max-version', dest = 'max_version', action = version_action,
+ nargs = 1, default = None,
+ help = 'The package is no later than this version.')
+ opts.add_argument('--msvc-syntax', dest = 'msvc_syntax', action = 'store_true',
+ default = False,
+ help = 'Ignored')
+ opts.add_argument('--dont-define-prefix', dest = 'dont_define_prefix', action = 'store_true',
+ default = False,
+ help = 'Ignored')
+ opts.add_argument('--prefix-variable', dest = 'prefix', action = 'store',
+ nargs = 1, default = pkgconfig.default_prefix(),
+ help = 'Define the prefix.')
+ opts.add_argument('--static', dest = 'static', action = 'store_true',
+ default = False,
+ help = 'Output libraries suitable for static linking')
+ opts.add_argument('--dump', dest = 'dump', action = 'store_true',
+ default = False,
+ help = 'Dump the package if one is found.')
+
+ args = opts.parse_args(argv[1:])
+
+ if (args.exists and (args.exact_version or args.max_version)) or \
+ (args.exact_version and (args.exists or args.max_version)) or \
+ (args.max_version and (args.exists or args.exact_version)):
+ raise error('only one of --exists, --exact-version, or --max-version')
+
+ exists = False
+
+ ec = 1
+
+ if args.atleast_pkgconfig_version:
+ ec = 0
+ else:
+ for lib in args.libraries:
+ ec, pkg, flags = _check_package(lib, args)
+ if ec == 0:
+ if args.cflags:
+ if len(flags['cflags']):
+ print flags['cflags']
+ log('cflags: %s' % (flags['cflags']))
+ else:
+ log('cflags: empty')
+ if args.libs:
+ if len(flags['libs']):
+ print flags['libs']
+ log('libs: %s' % (flags['libs']))
+ else:
+ log('libs: empty')
+
+ #pkgconfig.package.dump_loaded()
+
+ return ec
+
+try:
+ log('-' * 40)
+ log('pkg-config', lf = False)
+ for a in sys.argv[1:]:
+ log(' "%s"' % (a), lf = False)
+ log('')
+ ec = run(sys.argv)
+ log('ec = %d' % (ec))
+except ImportError:
+ print >> sys.stderr, "incorrect package config installation"
+ sys.exit(1)
+except pkgconfig.error, e:
+ print >> sys.stderr, 'error: %s' % (e)
+ sys.exit(1)
+sys.exit(ec)