source: rtems-source-builder/source-builder/pkg-config @ f88fcf3

4.11
Last change on this file since f88fcf3 was f88fcf3, checked in by Chris Johns <chrisj@…>, on Mar 7, 2016 at 12:56:02 AM

sb: Update code base to support Python3 and Python2.

Fix Windows support to allow MSYS2 Python to be used.

Updates #2619.

  • Property mode set to 100755
File size: 9.1 KB
Line 
1#! /usr/bin/env python
2#
3# RTEMS Tools Project (http://www.rtems.org/)
4# Copyright 2014-2016 Chris Johns (chrisj@rtems.org)
5# All rights reserved.
6#
7# This file is part of the RTEMS Tools package in 'rtems-tools'.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions are met:
11#
12# 1. Redistributions of source code must retain the above copyright notice,
13# this list of conditions and the following disclaimer.
14#
15# 2. Redistributions in binary form must reproduce the above copyright notice,
16# this list of conditions and the following disclaimer in the documentation
17# and/or other materials provided with the distribution.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29# POSSIBILITY OF SUCH DAMAGE.
30#
31
32from __future__ import print_function
33
34import os
35import sys
36
37base = os.path.dirname(sys.argv[0])
38sys.path.insert(0, base + '/sb')
39
40try:
41    import argparse
42except:
43    sys.path.insert(0, base + '/sb/imports')
44    try:
45        import argparse
46    except:
47        print("Incorrect Source Builder installation", file = sys.stderr)
48        sys.exit(1)
49
50try:
51    import pkgconfig
52except ImportError:
53    print("Incorrect Source Builder installation", file = sys.stderr)
54    sys.exit(1)
55
56#
57# Make trace true to get a file of what happens and what is being asked.
58#
59trace = True
60trace_stdout = False
61logfile = 'pkg-config.log'
62out = None
63srcfd = None
64
65#
66# Write all the package source parsed to a single file.
67#
68trace_src = True
69if trace_src:
70    srcfd = open('pkg-src.txt', 'w')
71
72def src(text):
73    if srcfd:
74        srcfd.writelines(text)
75
76def log(s, lf = True):
77    global trace, logfile, out
78    if trace:
79        if out is None:
80            if logfile:
81                out = open(logfile, 'a')
82            else:
83                out = sys.stdout
84        if lf:
85            if out != sys.stdout and trace_stdout:
86                print(s)
87            print(s, file = out)
88        else:
89            if out != sys.stdout and trace_stdout:
90                print(s, end = '', flush = True)
91            print(out, s, end = '', flush = True)
92
93def run(argv):
94
95    class version_action(argparse.Action):
96        def __call__(self, parser, namespace, values, option_string = None):
97            parts = values[0].strip().split('.')
98            for p in parts:
99                if not p.isdigit():
100                    raise error('invalid version value: %s' % (values))
101            setattr(namespace, self.dest, '.'.join(parts))
102
103    ec = 0
104
105    opts = argparse.ArgumentParser(prog = 'pkg-config', description = 'Package Configuration.')
106    opts.add_argument('libraries', metavar='lib', type = str,  help = 'a library', nargs = '*')
107    opts.add_argument('--modversion', dest = 'modversion', action = 'store', default = None,
108                      help = 'Requests that the version information of the libraries.')
109    opts.add_argument('--print-errors', dest = 'print_errors', action = 'store_true',
110                      default = False,
111                      help = 'Print any errors.')
112    opts.add_argument('--short-errors', dest = 'short_errors', action = 'store_true',
113                      default = False,
114                      help = 'Make error messages short.')
115    opts.add_argument('--silence-errors', dest = 'silence_errors', action = 'store_true',
116                      default = False,
117                      help = 'Do not print any errors.')
118    opts.add_argument('--errors-to-stdout', dest = 'errors_to_stdout', action = 'store_true',
119                      default = False,
120                      help = 'Print errors to stdout rather than stderr.')
121    opts.add_argument('--cflags', dest = 'cflags', action = 'store_true',
122                      default = False,
123                      help = 'This prints pre-processor and compile flags required to' \
124                             ' compile the package(s)')
125    opts.add_argument('--libs', dest = 'libs', action = 'store_true',
126                      default = False,
127                      help = 'This option is identical to "--cflags", only it prints the' \
128                             ' link flags.')
129    opts.add_argument('--libs-only-L', dest = 'libs_only_L', action = 'store_true',
130                      default = False,
131                      help = 'This prints the -L/-R part of "--libs".')
132    opts.add_argument('--libs-only-l', dest = 'libs_only_l', action = 'store_true',
133                      default = False,
134                      help = 'This prints the -l part of "--libs".')
135    opts.add_argument('--variable', dest = 'variable', action = 'store',
136                      nargs = 1, default = None,
137                      help = 'This returns the value of a variable.')
138    opts.add_argument('--define-variable', dest = 'define_variable', action = 'store',
139                      nargs = 1, default = None,
140                      help = 'This sets a global value for a variable')
141    opts.add_argument('--uninstalled', dest = 'uninstalled', action = 'store_true',
142                      default = False,
143                      help = 'Ignored')
144    opts.add_argument('--atleast-pkgconfig-version', dest = 'atleast_pkgconfig_version',
145                      action = 'store', nargs = 1, default = None,
146                      help = 'Check the version of package config. Always ok.')
147    opts.add_argument('--exists', dest = 'exists', action = 'store_true',
148                      default = False,
149                      help = 'Test if a library is present')
150    opts.add_argument('--atleast-version', dest = 'atleast_version',
151                      action = version_action, nargs = 1, default = None,
152                      help = 'The package is at least this version.')
153    opts.add_argument('--exact-version', dest = 'exact_version', action = version_action,
154                       nargs = 1, default = None,
155                        help = 'The package is the exact version.')
156    opts.add_argument('--max-version', dest = 'max_version', action = version_action,
157                      nargs = 1, default = None,
158                      help = 'The package is no later than this version.')
159    opts.add_argument('--msvc-syntax', dest = 'msvc_syntax', action = 'store_true',
160                      default = False,
161                      help = 'Ignored')
162    opts.add_argument('--dont-define-prefix', dest = 'dont_define_prefix', action = 'store_true',
163                      default = False,
164                      help = 'Ignored')
165    opts.add_argument('--prefix-variable', dest = 'prefix', action = 'store',
166                      nargs = 1, default = pkgconfig.default_prefix(),
167                      help = 'Define the prefix.')
168    opts.add_argument('--static', dest = 'static', action = 'store_true',
169                      default = False,
170                      help = 'Output libraries suitable for static linking')
171    opts.add_argument('--dump', dest = 'dump', action = 'store_true',
172                      default = False,
173                      help = 'Dump the package if one is found.')
174
175    args = opts.parse_args(argv[1:])
176
177    if (args.exists and (args.exact_version or args.max_version)) or \
178            (args.exact_version and (args.exists or args.max_version)) or \
179            (args.max_version and (args.exists or args.exact_version)):
180        raise error('only one of --exists, --exact-version, or --max-version')
181
182    if args.dont_define_prefix:
183        args.prefix = pkgconfig.default_prefix(False)
184
185    exists = False
186
187    ec = 1
188
189    if args.atleast_pkgconfig_version:
190        ec = 0
191    else:
192        ec, pkg, flags = pkgconfig.check_package(args.libraries, args, log, src)
193        if ec == 0:
194            if args.cflags:
195                if len(flags['cflags']):
196                    print(flags['cflags'])
197                    log('cflags: %s' % (flags['cflags']))
198                else:
199                    log('cflags: empty')
200            if args.libs:
201                if len(flags['libs']):
202                    print(flags['libs'])
203                    log('libs: %s' % (flags['libs']))
204                else:
205                    log('libs: empty')
206
207    #pkgconfig.package.dump_loaded()
208
209    return ec
210
211try:
212    log('-' * 40)
213    log('pkg-config', lf = False)
214    for a in sys.argv[1:]:
215        log(' "%s"' % (a), lf = False)
216    log('')
217    ec = run(sys.argv)
218    log('ec = %d' % (ec))
219except ImportError:
220    print("incorrect package config installation", file = sys.stderr)
221    sys.exit(1)
222except pkgconfig.error, e:
223    print('error: %s' % (e), file = sys.stderr)
224    sys.exit(1)
225sys.exit(ec)
Note: See TracBrowser for help on using the repository browser.