source: rtems-source-builder/source-builder/pkg-config @ 0ffee19

4.104.114.95
Last change on this file since 0ffee19 was 0ffee19, checked in by Chris Johns <chrisj@…>, on 06/15/14 at 05:40:34

sb: Add support for building RTEMS 3rd party packages.

Remove the 'opt' from various macros and shell variables.

Add pkgconfig to the checks to make it clear the check is a
pkgconfig check.

Add NTP support as the first package to be built using the RSB.

Split the RTEMS URL's out from the base bset file into a separate
file that be included by other files.

Add an RTEMS BSP configuration file to help abstract the process
of building 3rd party packages.

Clean the cross and canadian cross support up so we can cleanly support
cross and canadian cross building.

Refactor the pkgconfig support and clean up the PC file handling of
loading modules.

Add support for %{?..} to return false if a macro is %{nil}.

Add %{pkgconfig ..} support to allow better control of access RTEMS
pkgconfig files.

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