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 | #include <rld-rtems.h> |
---|
20 | |
---|
21 | #include <pkgconfig.h> |
---|
22 | |
---|
23 | namespace rld |
---|
24 | { |
---|
25 | namespace rtems |
---|
26 | { |
---|
27 | static std::string _version = "4.11"; |
---|
28 | static std::string _path; |
---|
29 | static std::string _arch_bsp; |
---|
30 | |
---|
31 | static void |
---|
32 | load_cc () |
---|
33 | { |
---|
34 | path::paths parts; |
---|
35 | std::string rtems_pkgconfig; |
---|
36 | std::string bsp; |
---|
37 | |
---|
38 | if (_path.empty ()) |
---|
39 | throw rld::error ("Not set", "RTEMS path"); |
---|
40 | |
---|
41 | bsp = rtems_arch_bsp (); |
---|
42 | |
---|
43 | parts.push_back ("lib"); |
---|
44 | parts.push_back ("pkgconfig"); |
---|
45 | |
---|
46 | rld::path::path_join (path (), parts, rtems_pkgconfig); |
---|
47 | |
---|
48 | if (!path::check_directory (rtems_pkgconfig)) |
---|
49 | throw rld::error ("Invalid RTEMS path", path ()); |
---|
50 | |
---|
51 | rld::path::path_join (rtems_pkgconfig, bsp + ".pc", rtems_pkgconfig); |
---|
52 | |
---|
53 | if (!path::check_file (rtems_pkgconfig)) |
---|
54 | throw rld::error ("RTEMS BSP not found", arch_bsp ()); |
---|
55 | |
---|
56 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
57 | std::cout << " rtems: " << _arch_bsp << ": " |
---|
58 | << rtems_pkgconfig << std::endl; |
---|
59 | |
---|
60 | pkgconfig::package pkg (rtems_pkgconfig); |
---|
61 | |
---|
62 | /* |
---|
63 | * Check the pc file matches what we ask for. |
---|
64 | */ |
---|
65 | std::string name; |
---|
66 | if (!pkg.get ("name", name)) |
---|
67 | throw rld::error ("RTEMS BSP no name in pkgconfig file", _arch_bsp); |
---|
68 | |
---|
69 | if (name != bsp) |
---|
70 | throw rld::error ("RTEMS BSP does not match the name in pkgconfig file", |
---|
71 | _arch_bsp); |
---|
72 | |
---|
73 | std::string flags; |
---|
74 | |
---|
75 | if (pkg.get ("CPPFLAGS", flags)) |
---|
76 | { |
---|
77 | rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cppflags); |
---|
78 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
79 | std::cout << " rtems: " << arch_bsp () |
---|
80 | << ": CPPFLAGS=" |
---|
81 | << rld::cc::get_flags (rld::cc::ft_cppflags) |
---|
82 | << std::endl; |
---|
83 | } |
---|
84 | |
---|
85 | if (pkg.get ("CFLAGS", flags)) |
---|
86 | { |
---|
87 | rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cflags); |
---|
88 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
89 | { |
---|
90 | std::cout << " rtems: " << arch_bsp () |
---|
91 | << ": CFLAGS=" << rld::cc::get_flags (rld::cc::ft_cflags) |
---|
92 | << std::endl; |
---|
93 | std::cout << " rtems: " << _arch_bsp |
---|
94 | << ": WARNINGS=" << rld::cc::get_flags (rld::cc::fg_warning_flags) |
---|
95 | << std::endl; |
---|
96 | std::cout << " rtems: " << arch_bsp () |
---|
97 | << ": INCLUDES=" << rld::cc::get_flags (rld::cc::fg_include_flags) |
---|
98 | << std::endl; |
---|
99 | std::cout << " rtems: " << arch_bsp () |
---|
100 | << ": MACHINES=" << rld::cc::get_flags (rld::cc::fg_machine_flags) |
---|
101 | << std::endl; |
---|
102 | std::cout << " rtems: " << arch_bsp () |
---|
103 | << ": SPECS=" << rld::cc::get_flags (rld::cc::fg_spec_flags) |
---|
104 | << std::endl; |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | if (pkg.get ("CXXFLAGS", flags)) |
---|
109 | { |
---|
110 | rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cxxflags); |
---|
111 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
112 | std::cout << " rtems: " << arch_bsp () |
---|
113 | << ": CXXFLAGS=" << rld::cc::get_flags (rld::cc::ft_cxxflags) |
---|
114 | << std::endl; |
---|
115 | } |
---|
116 | |
---|
117 | if (pkg.get ("LDFLAGS", flags)) |
---|
118 | { |
---|
119 | rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_ldflags); |
---|
120 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
121 | std::cout << " rtems: " << arch_bsp () |
---|
122 | << ": LDFLAGS=" << rld::cc::get_flags (rld::cc::ft_ldflags) |
---|
123 | << std::endl; |
---|
124 | } |
---|
125 | |
---|
126 | rld::cc::set_exec_prefix (arch ()); |
---|
127 | } |
---|
128 | |
---|
129 | void |
---|
130 | set_version (const std::string& version_) |
---|
131 | { |
---|
132 | _version = version_; |
---|
133 | } |
---|
134 | |
---|
135 | void |
---|
136 | set_arch_bsp (const std::string& arch_bsp_) |
---|
137 | { |
---|
138 | _arch_bsp = arch_bsp_; |
---|
139 | if (!_path.empty ()) |
---|
140 | load_cc (); |
---|
141 | } |
---|
142 | |
---|
143 | void |
---|
144 | set_path (const std::string& path_) |
---|
145 | { |
---|
146 | _path = path_; |
---|
147 | if (!_arch_bsp.empty ()) |
---|
148 | load_cc (); |
---|
149 | } |
---|
150 | |
---|
151 | const std::string |
---|
152 | version () |
---|
153 | { |
---|
154 | return _version; |
---|
155 | } |
---|
156 | |
---|
157 | const std::string |
---|
158 | arch_bsp () |
---|
159 | { |
---|
160 | return _arch_bsp; |
---|
161 | } |
---|
162 | |
---|
163 | const std::string |
---|
164 | arch () |
---|
165 | { |
---|
166 | if (_arch_bsp.empty ()) |
---|
167 | throw rld::error ("No arch/bsp name", "rtems: arch"); |
---|
168 | std::string::size_type slash = _arch_bsp.find_first_of ('/'); |
---|
169 | if (slash == std::string::npos) |
---|
170 | throw rld::error ("Invalid BSP name", _arch_bsp); |
---|
171 | return _arch_bsp.substr (0, slash); |
---|
172 | std::string bsp = _arch_bsp.substr (slash + 1); |
---|
173 | } |
---|
174 | |
---|
175 | const std::string |
---|
176 | bsp () |
---|
177 | { |
---|
178 | if (_arch_bsp.empty ()) |
---|
179 | throw rld::error ("No arch/bsp name", "rtems: bsp"); |
---|
180 | std::string::size_type slash = _arch_bsp.find_first_of ('/'); |
---|
181 | if (slash == std::string::npos) |
---|
182 | throw rld::error ("Invalid BSP name", _arch_bsp); |
---|
183 | return _arch_bsp.substr (slash + 1); |
---|
184 | } |
---|
185 | |
---|
186 | const std::string |
---|
187 | path () |
---|
188 | { |
---|
189 | return _path; |
---|
190 | } |
---|
191 | |
---|
192 | const std::string |
---|
193 | rtems_arch_prefix () |
---|
194 | { |
---|
195 | return arch () + "-rtems" + version (); |
---|
196 | } |
---|
197 | |
---|
198 | const std::string |
---|
199 | rtems_arch_bsp () |
---|
200 | { |
---|
201 | return rtems_arch_prefix () + '-' + bsp (); |
---|
202 | } |
---|
203 | |
---|
204 | } |
---|
205 | } |
---|