source: rtems-tools/linkers/rld-rtems.cpp @ 8807135

4.104.115
Last change on this file since 8807135 was 8807135, checked in by Chris Johns <chrisj@…>, on 09/06/14 at 10:19:45

Refactor the CC flags. Fix the various linkers. The trace linker is compiling.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Copyright (c) 2011-2014, 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
20#include <pkgconfig.h>
21
22namespace rld
23{
24  namespace rtems
25  {
26    std::string version = "4.11";
27    std::string path;
28    bool        installed;
29    std::string arch_bsp;
30
31    const std::string
32    arch (const std::string& ab)
33    {
34      std::string::size_type slash = ab.find_first_of ('/');
35      if (slash == std::string::npos)
36        throw rld::error ("Invalid BSP name", ab);
37      return ab.substr (0, slash);
38      std::string bsp  = ab.substr (slash + 1);
39    }
40
41    const std::string
42    bsp (const std::string& ab)
43    {
44      std::string::size_type slash = ab.find_first_of ('/');
45      if (slash == std::string::npos)
46        throw rld::error ("Invalid BSP name", ab);
47      return ab.substr (slash + 1);
48    }
49
50    const std::string
51    rtems_arch_prefix (const std::string& ab)
52    {
53      return arch (ab) + "-rtems" + version;
54    }
55
56    const std::string
57    rtems_arch_bsp (const std::string& ab)
58    {
59      return rtems_arch_prefix (ab) + '-' + bsp (ab);
60    }
61
62    void
63    load_cc ()
64    {
65      path::paths parts;
66      std::string rtems_pkgconfig;
67      std::string bsp;
68
69      if (path.empty ())
70        throw rld::error ("Not set; see -r", "RTEMS path");
71
72      bsp = rtems_arch_bsp (arch_bsp);
73
74      parts.push_back ("lib");
75      parts.push_back ("pkgconfig");
76
77      rld::path::path_join (path, parts, rtems_pkgconfig);
78
79      if (!path::check_directory (rtems_pkgconfig))
80        throw rld::error ("Invalid RTEMS path", path);
81
82      rld::path::path_join (rtems_pkgconfig, bsp + ".pc", rtems_pkgconfig);
83
84      if (!path::check_file (rtems_pkgconfig))
85        throw rld::error ("RTEMS BSP not found", arch_bsp);
86
87      if (rld::verbose () >= RLD_VERBOSE_INFO)
88        std::cout << " rtems: " << arch_bsp << ": "
89                  << rtems_pkgconfig << std::endl;
90
91      pkgconfig::package pkg (rtems_pkgconfig);
92
93      /*
94       * Check the pc file matches what we ask for.
95       */
96      std::string name;
97      if (!pkg.get ("name", name))
98        throw rld::error ("RTEMS BSP no name in pkgconfig file", arch_bsp);
99
100      if (name != bsp)
101        throw rld::error ("RTEMS BSP does not match the name in pkgconfig file", arch_bsp);
102
103      std::string flags;
104
105      if (pkg.get ("CPPFLAGS", flags))
106      {
107        rld::cc::append_flags (flags, arch (arch_bsp), path, rld::cc::ft_cppflags);
108        if (rld::verbose () >= RLD_VERBOSE_INFO)
109          std::cout << " rtems: " << arch_bsp
110                    << ": CPPFLAGS="
111                    << rld::cc::get_flags (rld::cc::ft_cppflags)
112                    << std::endl;
113      }
114
115      if (pkg.get ("CFLAGS", flags))
116      {
117        rld::cc::append_flags (flags, arch (arch_bsp), path, rld::cc::ft_cflags);
118        if (rld::verbose () >= RLD_VERBOSE_INFO)
119        {
120          std::cout << " rtems: " << arch_bsp
121                    << ": CFLAGS=" << rld::cc::get_flags (rld::cc::ft_cflags)
122                    << std::endl;
123          std::cout << " rtems: " << arch_bsp
124                    << ": WARNINGS=" << rld::cc::get_flags (rld::cc::fg_warning_flags)
125                    << std::endl;
126          std::cout << " rtems: " << arch_bsp
127                    << ": INCLUDES=" << rld::cc::get_flags (rld::cc::fg_include_flags)
128                    << std::endl;
129          std::cout << " rtems: " << arch_bsp
130                    << ": MACHINES=" << rld::cc::get_flags (rld::cc::fg_machine_flags)
131                    << std::endl;
132          std::cout << " rtems: " << arch_bsp
133                    << ": SPECS=" << rld::cc::get_flags (rld::cc::fg_spec_flags)
134                    << std::endl;
135        }
136      }
137
138      if (pkg.get ("CXXFLAGS", flags))
139      {
140        rld::cc::append_flags (flags, arch (arch_bsp), path, rld::cc::ft_cxxflags);
141        if (rld::verbose () >= RLD_VERBOSE_INFO)
142          std::cout << " rtems: " << arch_bsp
143                    << ": CXXFLAGS=" << rld::cc::get_flags (rld::cc::ft_cxxflags)
144                    << std::endl;
145      }
146
147      if (pkg.get ("LDFLAGS", flags))
148      {
149        rld::cc::append_flags (flags, arch (arch_bsp), path, rld::cc::ft_ldflags);
150        if (rld::verbose () >= RLD_VERBOSE_INFO)
151          std::cout << " rtems: " << arch_bsp
152                    << ": LDFLAGS=" << rld::cc::get_flags (rld::cc::ft_ldflags)
153                    << std::endl;
154      }
155
156      rld::cc::set_exec_prefix (arch (arch_bsp));
157    }
158  }
159}
Note: See TracBrowser for help on using the repository browser.