source: rtems-source-builder/source-builder/sb/cmd-pkg-config.py @ 0fd197f

5
Last change on this file since 0fd197f was 0fd197f, checked in by Chris Johns <chrisj@…>, on 05/08/20 at 04:28:09

sb: Disable any trace data

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