[7ccb6701] | 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> |
---|
[b28e8b3] | 19 | #include <rld-rtems.h> |
---|
[7ccb6701] | 20 | |
---|
| 21 | #include <pkgconfig.h> |
---|
| 22 | |
---|
| 23 | namespace rld |
---|
| 24 | { |
---|
| 25 | namespace rtems |
---|
| 26 | { |
---|
[efc4f09] | 27 | static std::string _version = RTEMS_VERSION; |
---|
[b28e8b3] | 28 | static std::string _path; |
---|
| 29 | static std::string _arch_bsp; |
---|
[7ccb6701] | 30 | |
---|
[b28e8b3] | 31 | static void |
---|
[7ccb6701] | 32 | load_cc () |
---|
| 33 | { |
---|
| 34 | path::paths parts; |
---|
| 35 | std::string rtems_pkgconfig; |
---|
| 36 | std::string bsp; |
---|
| 37 | |
---|
[b28e8b3] | 38 | if (_path.empty ()) |
---|
| 39 | throw rld::error ("Not set", "RTEMS path"); |
---|
[7ccb6701] | 40 | |
---|
[b28e8b3] | 41 | bsp = rtems_arch_bsp (); |
---|
[7ccb6701] | 42 | |
---|
| 43 | parts.push_back ("lib"); |
---|
| 44 | parts.push_back ("pkgconfig"); |
---|
| 45 | |
---|
[b28e8b3] | 46 | rld::path::path_join (path (), parts, rtems_pkgconfig); |
---|
[7ccb6701] | 47 | |
---|
| 48 | if (!path::check_directory (rtems_pkgconfig)) |
---|
[b28e8b3] | 49 | throw rld::error ("Invalid RTEMS path", path ()); |
---|
[7ccb6701] | 50 | |
---|
| 51 | rld::path::path_join (rtems_pkgconfig, bsp + ".pc", rtems_pkgconfig); |
---|
| 52 | |
---|
| 53 | if (!path::check_file (rtems_pkgconfig)) |
---|
[b28e8b3] | 54 | throw rld::error ("RTEMS BSP not found", arch_bsp ()); |
---|
[7ccb6701] | 55 | |
---|
| 56 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
[b28e8b3] | 57 | std::cout << " rtems: " << _arch_bsp << ": " |
---|
[7ccb6701] | 58 | << rtems_pkgconfig << std::endl; |
---|
| 59 | |
---|
| 60 | pkgconfig::package pkg (rtems_pkgconfig); |
---|
| 61 | |
---|
[8807135] | 62 | /* |
---|
| 63 | * Check the pc file matches what we ask for. |
---|
| 64 | */ |
---|
| 65 | std::string name; |
---|
| 66 | if (!pkg.get ("name", name)) |
---|
[b28e8b3] | 67 | throw rld::error ("RTEMS BSP no name in pkgconfig file", _arch_bsp); |
---|
[8807135] | 68 | |
---|
| 69 | if (name != bsp) |
---|
[b28e8b3] | 70 | throw rld::error ("RTEMS BSP does not match the name in pkgconfig file", |
---|
| 71 | _arch_bsp); |
---|
[8807135] | 72 | |
---|
[7ccb6701] | 73 | std::string flags; |
---|
| 74 | |
---|
| 75 | if (pkg.get ("CPPFLAGS", flags)) |
---|
| 76 | { |
---|
[b28e8b3] | 77 | rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cppflags); |
---|
[7ccb6701] | 78 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
[b28e8b3] | 79 | std::cout << " rtems: " << arch_bsp () |
---|
[8807135] | 80 | << ": CPPFLAGS=" |
---|
| 81 | << rld::cc::get_flags (rld::cc::ft_cppflags) |
---|
| 82 | << std::endl; |
---|
[7ccb6701] | 83 | } |
---|
| 84 | |
---|
| 85 | if (pkg.get ("CFLAGS", flags)) |
---|
| 86 | { |
---|
[b28e8b3] | 87 | rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cflags); |
---|
[7ccb6701] | 88 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
| 89 | { |
---|
[b28e8b3] | 90 | std::cout << " rtems: " << arch_bsp () |
---|
[8807135] | 91 | << ": CFLAGS=" << rld::cc::get_flags (rld::cc::ft_cflags) |
---|
| 92 | << std::endl; |
---|
[b28e8b3] | 93 | std::cout << " rtems: " << _arch_bsp |
---|
[8807135] | 94 | << ": WARNINGS=" << rld::cc::get_flags (rld::cc::fg_warning_flags) |
---|
| 95 | << std::endl; |
---|
[b28e8b3] | 96 | std::cout << " rtems: " << arch_bsp () |
---|
[8807135] | 97 | << ": INCLUDES=" << rld::cc::get_flags (rld::cc::fg_include_flags) |
---|
| 98 | << std::endl; |
---|
[b28e8b3] | 99 | std::cout << " rtems: " << arch_bsp () |
---|
[8807135] | 100 | << ": MACHINES=" << rld::cc::get_flags (rld::cc::fg_machine_flags) |
---|
| 101 | << std::endl; |
---|
[b28e8b3] | 102 | std::cout << " rtems: " << arch_bsp () |
---|
[8807135] | 103 | << ": SPECS=" << rld::cc::get_flags (rld::cc::fg_spec_flags) |
---|
| 104 | << std::endl; |
---|
[7ccb6701] | 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | if (pkg.get ("CXXFLAGS", flags)) |
---|
| 109 | { |
---|
[b28e8b3] | 110 | rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cxxflags); |
---|
[7ccb6701] | 111 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
[b28e8b3] | 112 | std::cout << " rtems: " << arch_bsp () |
---|
[8807135] | 113 | << ": CXXFLAGS=" << rld::cc::get_flags (rld::cc::ft_cxxflags) |
---|
| 114 | << std::endl; |
---|
[7ccb6701] | 115 | } |
---|
| 116 | |
---|
| 117 | if (pkg.get ("LDFLAGS", flags)) |
---|
| 118 | { |
---|
[b28e8b3] | 119 | rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_ldflags); |
---|
[7ccb6701] | 120 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
[b28e8b3] | 121 | std::cout << " rtems: " << arch_bsp () |
---|
[8807135] | 122 | << ": LDFLAGS=" << rld::cc::get_flags (rld::cc::ft_ldflags) |
---|
| 123 | << std::endl; |
---|
[7ccb6701] | 124 | } |
---|
[8807135] | 125 | |
---|
[b28e8b3] | 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); |
---|
[7ccb6701] | 173 | } |
---|
[b28e8b3] | 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 | |
---|
[7ccb6701] | 204 | } |
---|
| 205 | } |
---|