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

Last change on this file since ad54d1d was 650c6f9, checked in by Chris Johns <chrisj@…>, on 08/25/20 at 11:21:50

sb: Use shebang env python

Closes #4037

  • Property mode set to 100755
File size: 8.9 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])
38
39try:
40    import argparse
41except:
42    sys.path.insert(0, base + '/sb/imports')
43    try:
44        import argparse
45    except:
46        print("Incorrect Source Builder installation", file = sys.stderr)
47        sys.exit(1)
48
49import sb.pkgconfig
50
51#
52# Make trace true to get a file of what happens and what is being asked.
53#
54trace = False
55trace_stdout = False
56logfile = 'pkg-config.log'
57out = None
58srcfd = None
59
60#
61# Write all the package source parsed to a single file.
62#
63trace_src = False
64if trace_src:
65    srcfd = open('pkg-src.txt', 'w')
66
67def src(text):
68    if srcfd:
69        srcfd.writelines(text)
70
71def log(s, lf = True):
72    global trace, logfile, out
73    if trace:
74        if out is None:
75            if logfile:
76                out = open(logfile, 'a')
77            else:
78                out = sys.stdout
79        if lf:
80            if out != sys.stdout and trace_stdout:
81                print(s)
82            print(s, file = out)
83        else:
84            if out != sys.stdout and trace_stdout:
85                print(s, end = '')
86                sys.stdout.flush()
87            print(s, end = '', file = out)
88
89def run(argv):
90
91    class version_action(argparse.Action):
92        def __call__(self, parser, namespace, values, option_string = None):
93            parts = values[0].strip().split('.')
94            for p in parts:
95                if not p.isdigit():
96                    raise error('invalid version value: %s' % (values))
97            setattr(namespace, self.dest, '.'.join(parts))
98
99    ec = 0
100
101    opts = argparse.ArgumentParser(prog = 'pkg-config', description = 'Package Configuration.')
102    opts.add_argument('libraries', metavar='lib', type = str,  help = 'a library', nargs = '*')
103    opts.add_argument('--modversion', dest = 'modversion', action = 'store', default = None,
104                      help = 'Requests that the version information of the libraries.')
105    opts.add_argument('--print-errors', dest = 'print_errors', action = 'store_true',
106                      default = False,
107                      help = 'Print any errors.')
108    opts.add_argument('--short-errors', dest = 'short_errors', action = 'store_true',
109                      default = False,
110                      help = 'Make error messages short.')
111    opts.add_argument('--silence-errors', dest = 'silence_errors', action = 'store_true',
112                      default = False,
113                      help = 'Do not print any errors.')
114    opts.add_argument('--errors-to-stdout', dest = 'errors_to_stdout', action = 'store_true',
115                      default = False,
116                      help = 'Print errors to stdout rather than stderr.')
117    opts.add_argument('--cflags', dest = 'cflags', action = 'store_true',
118                      default = False,
119                      help = 'This prints pre-processor and compile flags required to' \
120                             ' compile the package(s)')
121    opts.add_argument('--libs', dest = 'libs', action = 'store_true',
122                      default = False,
123                      help = 'This option is identical to "--cflags", only it prints the' \
124                             ' link flags.')
125    opts.add_argument('--libs-only-L', dest = 'libs_only_L', action = 'store_true',
126                      default = False,
127                      help = 'This prints the -L/-R part of "--libs".')
128    opts.add_argument('--libs-only-l', dest = 'libs_only_l', action = 'store_true',
129                      default = False,
130                      help = 'This prints the -l part of "--libs".')
131    opts.add_argument('--variable', dest = 'variable', action = 'store',
132                      nargs = 1, default = None,
133                      help = 'This returns the value of a variable.')
134    opts.add_argument('--define-variable', dest = 'define_variable', action = 'store',
135                      nargs = 1, default = None,
136                      help = 'This sets a global value for a variable')
137    opts.add_argument('--uninstalled', dest = 'uninstalled', action = 'store_true',
138                      default = False,
139                      help = 'Ignored')
140    opts.add_argument('--atleast-pkgconfig-version', dest = 'atleast_pkgconfig_version',
141                      action = 'store', nargs = 1, default = None,
142                      help = 'Check the version of package config. Always ok.')
143    opts.add_argument('--exists', dest = 'exists', action = 'store_true',
144                      default = False,
145                      help = 'Test if a library is present')
146    opts.add_argument('--atleast-version', dest = 'atleast_version',
147                      action = version_action, nargs = 1, default = None,
148                      help = 'The package is at least this version.')
149    opts.add_argument('--exact-version', dest = 'exact_version', action = version_action,
150                       nargs = 1, default = None,
151                        help = 'The package is the exact version.')
152    opts.add_argument('--max-version', dest = 'max_version', action = version_action,
153                      nargs = 1, default = None,
154                      help = 'The package is no later than this version.')
155    opts.add_argument('--msvc-syntax', dest = 'msvc_syntax', action = 'store_true',
156                      default = False,
157                      help = 'Ignored')
158    opts.add_argument('--dont-define-prefix', dest = 'dont_define_prefix', action = 'store_true',
159                      default = False,
160                      help = 'Ignored')
161    opts.add_argument('--prefix-variable', dest = 'prefix', action = 'store',
162                      nargs = 1, default = sb.pkgconfig.default_prefix(),
163                      help = 'Define the prefix.')
164    opts.add_argument('--static', dest = 'static', action = 'store_true',
165                      default = False,
166                      help = 'Output libraries suitable for static linking')
167    opts.add_argument('--dump', dest = 'dump', action = 'store_true',
168                      default = False,
169                      help = 'Dump the package if one is found.')
170
171    args = opts.parse_args(argv)
172
173    if (args.exists and (args.exact_version or args.max_version)) or \
174            (args.exact_version and (args.exists or args.max_version)) or \
175            (args.max_version and (args.exists or args.exact_version)):
176        raise error('only one of --exists, --exact-version, or --max-version')
177
178    if args.dont_define_prefix:
179        args.prefix = sb.pkgconfig.default_prefix(False)
180
181    exists = False
182
183    ec = 1
184
185    if args.atleast_pkgconfig_version:
186        ec = 0
187    else:
188        ec, pkg, flags = sb.pkgconfig.check_package(args.libraries, args, log, src)
189        if ec == 0:
190            if args.cflags:
191                if len(flags['cflags']):
192                    print(flags['cflags'])
193                    log('cflags: %s' % (flags['cflags']))
194                else:
195                    log('cflags: empty')
196            if args.libs:
197                if len(flags['libs']):
198                    print(flags['libs'])
199                    log('libs: %s' % (flags['libs']))
200                else:
201                    log('libs: empty')
202
203    #pkgconfig.package.dump_loaded()
204
205    return ec
206
207try:
208    log('-' * 40)
209    log('pkg-config', lf = False)
210    for a in sys.argv[2:]:
211        log(' "%s"' % (a), lf = False)
212    log('')
213    ec = run(sys.argv[1:])
214    log('ec = %d' % (ec))
215except ImportError:
216    print("incorrect package config installation", file = sys.stderr)
217    sys.exit(1)
218except sb.pkgconfig.error as e:
219    print('error: %s' % (e), file = sys.stderr)
220    sys.exit(1)
221sys.exit(ec)
Note: See TracBrowser for help on using the repository browser.