source: rtems-source-builder/source-builder/pkg-config @ 38ed59a

4.104.95
Last change on this file since 38ed59a was 38ed59a, checked in by Chris Johns <chrisj@…>, on 03/17/16 at 05:39:57

sb: Support --dry-run --with-download for 3rd party RTEMS BSP packages.

The building of 3rd party packages for an RTEMS BSP requires a valid
BSP so the standard method to download the source for releasing does
not work. This change adds support to allow this. The RTEMS BSP support
will not generate an error is no BSP or tools are provided or found.

The change addis logic operators to the %if statement so you can '
'

to 'or' and '&&' to 'and' logic expressions.

A new %log directive has been added to clean up the messages.

A new %{!define ...} has been added to aid checking within logic
expressions.

All command line --with/--without now appear as macros.

Add version.version to get just the RTEMS major and minor version.

Some pkg-config issues have been resolved.

Closes #2655.

  • 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 = '')
91                sys.stdout.flush()
92            print(s, end = '', file = out)
93
94def run(argv):
95
96    class version_action(argparse.Action):
97        def __call__(self, parser, namespace, values, option_string = None):
98            parts = values[0].strip().split('.')
99            for p in parts:
100                if not p.isdigit():
101                    raise error('invalid version value: %s' % (values))
102            setattr(namespace, self.dest, '.'.join(parts))
103
104    ec = 0
105
106    opts = argparse.ArgumentParser(prog = 'pkg-config', description = 'Package Configuration.')
107    opts.add_argument('libraries', metavar='lib', type = str,  help = 'a library', nargs = '*')
108    opts.add_argument('--modversion', dest = 'modversion', action = 'store', default = None,
109                      help = 'Requests that the version information of the libraries.')
110    opts.add_argument('--print-errors', dest = 'print_errors', action = 'store_true',
111                      default = False,
112                      help = 'Print any errors.')
113    opts.add_argument('--short-errors', dest = 'short_errors', action = 'store_true',
114                      default = False,
115                      help = 'Make error messages short.')
116    opts.add_argument('--silence-errors', dest = 'silence_errors', action = 'store_true',
117                      default = False,
118                      help = 'Do not print any errors.')
119    opts.add_argument('--errors-to-stdout', dest = 'errors_to_stdout', action = 'store_true',
120                      default = False,
121                      help = 'Print errors to stdout rather than stderr.')
122    opts.add_argument('--cflags', dest = 'cflags', action = 'store_true',
123                      default = False,
124                      help = 'This prints pre-processor and compile flags required to' \
125                             ' compile the package(s)')
126    opts.add_argument('--libs', dest = 'libs', action = 'store_true',
127                      default = False,
128                      help = 'This option is identical to "--cflags", only it prints the' \
129                             ' link flags.')
130    opts.add_argument('--libs-only-L', dest = 'libs_only_L', action = 'store_true',
131                      default = False,
132                      help = 'This prints the -L/-R part of "--libs".')
133    opts.add_argument('--libs-only-l', dest = 'libs_only_l', action = 'store_true',
134                      default = False,
135                      help = 'This prints the -l part of "--libs".')
136    opts.add_argument('--variable', dest = 'variable', action = 'store',
137                      nargs = 1, default = None,
138                      help = 'This returns the value of a variable.')
139    opts.add_argument('--define-variable', dest = 'define_variable', action = 'store',
140                      nargs = 1, default = None,
141                      help = 'This sets a global value for a variable')
142    opts.add_argument('--uninstalled', dest = 'uninstalled', action = 'store_true',
143                      default = False,
144                      help = 'Ignored')
145    opts.add_argument('--atleast-pkgconfig-version', dest = 'atleast_pkgconfig_version',
146                      action = 'store', nargs = 1, default = None,
147                      help = 'Check the version of package config. Always ok.')
148    opts.add_argument('--exists', dest = 'exists', action = 'store_true',
149                      default = False,
150                      help = 'Test if a library is present')
151    opts.add_argument('--atleast-version', dest = 'atleast_version',
152                      action = version_action, nargs = 1, default = None,
153                      help = 'The package is at least this version.')
154    opts.add_argument('--exact-version', dest = 'exact_version', action = version_action,
155                       nargs = 1, default = None,
156                        help = 'The package is the exact version.')
157    opts.add_argument('--max-version', dest = 'max_version', action = version_action,
158                      nargs = 1, default = None,
159                      help = 'The package is no later than this version.')
160    opts.add_argument('--msvc-syntax', dest = 'msvc_syntax', action = 'store_true',
161                      default = False,
162                      help = 'Ignored')
163    opts.add_argument('--dont-define-prefix', dest = 'dont_define_prefix', action = 'store_true',
164                      default = False,
165                      help = 'Ignored')
166    opts.add_argument('--prefix-variable', dest = 'prefix', action = 'store',
167                      nargs = 1, default = pkgconfig.default_prefix(),
168                      help = 'Define the prefix.')
169    opts.add_argument('--static', dest = 'static', action = 'store_true',
170                      default = False,
171                      help = 'Output libraries suitable for static linking')
172    opts.add_argument('--dump', dest = 'dump', action = 'store_true',
173                      default = False,
174                      help = 'Dump the package if one is found.')
175
176    args = opts.parse_args(argv[1:])
177
178    if (args.exists and (args.exact_version or args.max_version)) or \
179            (args.exact_version and (args.exists or args.max_version)) or \
180            (args.max_version and (args.exists or args.exact_version)):
181        raise error('only one of --exists, --exact-version, or --max-version')
182
183    if args.dont_define_prefix:
184        args.prefix = pkgconfig.default_prefix(False)
185
186    exists = False
187
188    ec = 1
189
190    if args.atleast_pkgconfig_version:
191        ec = 0
192    else:
193        ec, pkg, flags = pkgconfig.check_package(args.libraries, args, log, src)
194        if ec == 0:
195            if args.cflags:
196                if len(flags['cflags']):
197                    print(flags['cflags'])
198                    log('cflags: %s' % (flags['cflags']))
199                else:
200                    log('cflags: empty')
201            if args.libs:
202                if len(flags['libs']):
203                    print(flags['libs'])
204                    log('libs: %s' % (flags['libs']))
205                else:
206                    log('libs: empty')
207
208    #pkgconfig.package.dump_loaded()
209
210    return ec
211
212try:
213    log('-' * 40)
214    log('pkg-config', lf = False)
215    for a in sys.argv[1:]:
216        log(' "%s"' % (a), lf = False)
217    log('')
218    ec = run(sys.argv)
219    log('ec = %d' % (ec))
220except ImportError:
221    print("incorrect package config installation", file = sys.stderr)
222    sys.exit(1)
223except pkgconfig.error as e:
224    print('error: %s' % (e), file = sys.stderr)
225    sys.exit(1)
226sys.exit(ec)
Note: See TracBrowser for help on using the repository browser.