source: rtems-tools/rtemstoolkit/rld-rtems.cpp @ 7c032b0

5
Last change on this file since 7c032b0 was 0c0b2d4, checked in by Chris Johns <chrisj@…>, on 04/03/16 at 05:37:01

rtemstoolkit: Add version number parsing to get major, minor, revision.

Add support to return the major, minor or revision numbers as numbers.

  • Property mode set to 100644
File size: 7.0 KB
Line 
1/*
2 * Copyright (c) 2011-2016, Chris Johns <chrisj@rtems.org>
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <rld.h>
18#include <rld-cc.h>
19#include <rld-rtems.h>
20
21#include <pkgconfig.h>
22
23namespace rld
24{
25  namespace rtems
26  {
27    static std::string _version = RTEMS_VERSION;
28    static std::string _path;
29    static std::string _arch_bsp;
30
31    static uint64_t _version_major = 0;
32    static uint64_t _version_minor = 0;
33    static uint64_t _version_revision = 0;
34
35    static void
36    load_cc ()
37    {
38      path::paths parts;
39      std::string rtems_pkgconfig;
40      std::string bsp;
41
42      if (_path.empty ())
43        throw rld::error ("Not set", "RTEMS path");
44
45      bsp = rtems_arch_bsp ();
46
47      parts.push_back ("lib");
48      parts.push_back ("pkgconfig");
49
50      rld::path::path_join (path (), parts, rtems_pkgconfig);
51
52      if (!path::check_directory (rtems_pkgconfig))
53        throw rld::error ("Invalid RTEMS path", path ());
54
55      rld::path::path_join (rtems_pkgconfig, bsp + ".pc", rtems_pkgconfig);
56
57      if (!path::check_file (rtems_pkgconfig))
58        throw rld::error ("RTEMS BSP not found", arch_bsp ());
59
60      if (rld::verbose () >= RLD_VERBOSE_INFO)
61        std::cout << " rtems: " << _arch_bsp << ": "
62                  << rtems_pkgconfig << std::endl;
63
64      pkgconfig::package pkg (rtems_pkgconfig);
65
66      /*
67       * Check the pc file matches what we ask for.
68       */
69      std::string name;
70      if (!pkg.get ("name", name))
71        throw rld::error ("RTEMS BSP no name in pkgconfig file", _arch_bsp);
72
73      if (name != bsp)
74        throw rld::error ("RTEMS BSP does not match the name in pkgconfig file",
75                          _arch_bsp);
76
77      std::string flags;
78
79      if (pkg.get ("CPPFLAGS", flags))
80      {
81        rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cppflags);
82        if (rld::verbose () >= RLD_VERBOSE_INFO)
83          std::cout << " rtems: " << arch_bsp ()
84                    << ": CPPFLAGS="
85                    << rld::cc::get_flags (rld::cc::ft_cppflags)
86                    << std::endl;
87      }
88
89      if (pkg.get ("CFLAGS", flags))
90      {
91        rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cflags);
92        if (rld::verbose () >= RLD_VERBOSE_INFO)
93        {
94          std::cout << " rtems: " << arch_bsp ()
95                    << ": CFLAGS=" << rld::cc::get_flags (rld::cc::ft_cflags)
96                    << std::endl;
97          std::cout << " rtems: " << _arch_bsp
98                    << ": WARNINGS=" << rld::cc::get_flags (rld::cc::fg_warning_flags)
99                    << std::endl;
100          std::cout << " rtems: " << arch_bsp ()
101                    << ": INCLUDES=" << rld::cc::get_flags (rld::cc::fg_include_flags)
102                    << std::endl;
103          std::cout << " rtems: " << arch_bsp ()
104                    << ": MACHINES=" << rld::cc::get_flags (rld::cc::fg_machine_flags)
105                    << std::endl;
106          std::cout << " rtems: " << arch_bsp ()
107                    << ": SPECS=" << rld::cc::get_flags (rld::cc::fg_spec_flags)
108                    << std::endl;
109        }
110      }
111
112      if (pkg.get ("CXXFLAGS", flags))
113      {
114        rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cxxflags);
115        if (rld::verbose () >= RLD_VERBOSE_INFO)
116          std::cout << " rtems: " << arch_bsp ()
117                    << ": CXXFLAGS=" << rld::cc::get_flags (rld::cc::ft_cxxflags)
118                    << std::endl;
119      }
120
121      if (pkg.get ("LDFLAGS", flags))
122      {
123        rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_ldflags);
124        if (rld::verbose () >= RLD_VERBOSE_INFO)
125          std::cout << " rtems: " << arch_bsp ()
126                    << ": LDFLAGS=" << rld::cc::get_flags (rld::cc::ft_ldflags)
127                    << std::endl;
128      }
129
130      rld::cc::set_exec_prefix (arch ());
131    }
132
133    void
134    set_version (const std::string& version_)
135    {
136      _version = version_;
137      rld::version_parse (_version,
138                          _version_major,
139                          _version_minor,
140                          _version_revision);
141    }
142
143    void
144    set_arch_bsp (const std::string& arch_bsp_)
145    {
146      _arch_bsp = arch_bsp_;
147      if (!_path.empty ())
148        load_cc ();
149    }
150
151    void
152    set_path (const std::string& path_)
153    {
154      _path = path_;
155      if (!_arch_bsp.empty ())
156        load_cc ();
157    }
158
159    const std::string
160    version ()
161    {
162      return _version;
163    }
164
165    uint64_t
166    version_major ()
167    {
168      if (_version_major == 0)
169        rld::version_parse (_version,
170                            _version_major,
171                            _version_minor,
172                            _version_revision);
173      return _version_major;
174    }
175
176    uint64_t
177    version_minor ()
178    {
179      if (_version_minor == 0)
180        rld::version_parse (_version,
181                            _version_major,
182                            _version_minor,
183                            _version_revision);
184      return _version_minor;
185    }
186
187    uint64_t
188    version_revision ()
189    {
190      if (_version_revision == 0)
191        rld::version_parse (_version,
192                            _version_major,
193                            _version_minor,
194                            _version_revision);
195      return _version_revision;
196    }
197
198    const std::string
199    arch_bsp ()
200    {
201      return _arch_bsp;
202    }
203
204    const std::string
205    arch ()
206    {
207      if (_arch_bsp.empty ())
208        throw rld::error ("No arch/bsp name", "rtems: arch");
209      std::string::size_type slash = _arch_bsp.find_first_of ('/');
210      if (slash == std::string::npos)
211        throw rld::error ("Invalid BSP name", _arch_bsp);
212      return _arch_bsp.substr (0, slash);
213      std::string bsp  = _arch_bsp.substr (slash + 1);
214    }
215
216    const std::string
217    bsp ()
218    {
219      if (_arch_bsp.empty ())
220        throw rld::error ("No arch/bsp name", "rtems: bsp");
221      std::string::size_type slash = _arch_bsp.find_first_of ('/');
222      if (slash == std::string::npos)
223        throw rld::error ("Invalid BSP name", _arch_bsp);
224      return _arch_bsp.substr (slash + 1);
225    }
226
227    const std::string
228    path ()
229    {
230      return _path;
231    }
232
233    const std::string
234    rtems_arch_prefix ()
235    {
236      return arch () + "-rtems" + version ();
237    }
238
239    const std::string
240    rtems_arch_bsp ()
241    {
242      return rtems_arch_prefix () + '-' + bsp ();
243    }
244
245  }
246}
Note: See TracBrowser for help on using the repository browser.