source: rtems-tools/rtemstoolkit/rld.h @ a248471

5
Last change on this file since a248471 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: 6.4 KB
Line 
1/*
2 * Copyright (c) 2011, 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 * @file
18 *
19 * @ingroup rtems-ld
20 *
21 * @brief RTEMS Linker readies the RTEMS object files for dynamic linking.
22 *
23 */
24
25#if !defined (_RLD_H_)
26#define _RLD_H_
27
28#include <algorithm>
29#include <cctype>
30#include <functional>
31#include <iostream>
32#include <list>
33#include <locale>
34#include <sstream>
35#include <string>
36
37/**
38 * Path handling for Windows.
39 */
40#if __WIN32__
41#define RLD_PATH_SEPARATOR        '\\'
42#define RLD_PATH_SEPARATOR_STR    "\\"
43#define RLD_PATHSTR_SEPARATOR     ';'
44#define RLD_PATHSTR_SEPARATOR_STR ";"
45#define RLD_DRIVE_SEPARATOR       (1)
46#define RLD_LINE_SEPARATOR        "\r\n"
47#else
48#define RLD_PATH_SEPARATOR        '/'
49#define RLD_PATH_SEPARATOR_STR    "/"
50#define RLD_PATHSTR_SEPARATOR     ':'
51#define RLD_PATHSTR_SEPARATOR_STR ":"
52#define RLD_DRIVE_SEPARATOR       (0)
53#define RLD_LINE_SEPARATOR        "\n"
54#endif
55
56namespace rld
57{
58  /**
59   * Forward declarations.
60   */
61  namespace files
62  {
63    class file;
64    class image;
65    class archive;
66    class object;
67    class cache;
68    typedef std::list < object* > object_list;
69  }
70}
71
72#include <rld-elf-types.h>
73#include <rld-symbols.h>
74#include <rld-elf.h>
75#include <rld-files.h>
76
77/**
78 * The debug levels.
79 */
80#define RLD_VERBOSE_OFF        (0)
81#define RLD_VERBOSE_INFO       (1)
82#define RLD_VERBOSE_DETAILS    (2)
83#define RLD_VERBOSE_TRACE      (3)
84#define RLD_VERBOSE_TRACE_SYMS (4)
85#define RLD_VERBOSE_TRACE_FILE (5)
86#define RLD_VERBOSE_FULL_DEBUG (6)
87
88namespace rld
89{
90  /**
91   * General error.
92   */
93  struct error
94  {
95    const std::string what;
96    const std::string where;
97
98    error (const std::ostringstream& what, const std::string& where) :
99      what (what.str ()), where (where) {
100    }
101
102    error (const std::string& what, const std::string& where) :
103      what (what), where (where) {
104    }
105  };
106
107  /**
108   * A convenience macro to make where a file and line number.
109   */
110  #define rld_error_at(_what) \
111    rld::error (_what, std::string (__FILE__) + ":" + to_string (__LINE__))
112
113  /**
114   * Convert a supported type to a string.
115   */
116  template <class T>
117  std::string to_string (T t, std::ios_base & (*f)(std::ios_base&) = std::dec)
118  {
119    std::ostringstream oss;
120    oss << f << t;
121    return oss.str();
122  }
123
124  /**
125   * A container of strings.
126   */
127  typedef std::vector < std::string > strings;
128
129  /**
130   * Does a string start with another string ?
131   */
132  bool starts_with(const std::string& s1, const std::string& s2);
133
134  /**
135   * Trim from start.
136   */
137  const std::string ltrim (const std::string& s);
138
139  /**
140   * Trim from end.
141   */
142  const std::string rtrim (const std::string& s);
143
144  /**
145   * Trim from both ends.
146   */
147  const std::string trim (const std::string& s);
148
149  /**
150   * Dequote a string.
151   */
152  const std::string dequote (const std::string& s);
153
154  /**
155   * Find and replace.
156   */
157  const std::string find_replace(const std::string& sin,
158                                 const std::string& out,
159                                 const std::string& in);
160
161  /**
162   * Split the string in a contain of strings based on the the
163   * delimiter. Optionally trim any white space or include empty string.
164   *
165   * @todo The split should optionally honour string quoting.
166   */
167  const strings split (strings&           se,
168                       const std::string& s,
169                       char               delimiter = ' ',
170                       bool               strip_quotes = true,
171                       bool               strip_whitespace = true,
172                       bool               empty = false);
173
174  /**
175   * Join the strings together with the separator.
176   */
177  const std::string join (const strings& ss, const std::string& separator);
178
179  /**
180   * Convert a string to lower case.
181   */
182  const std::string tolower (const std::string& sin);
183
184  /**
185   * Parse version string of format major.minor.revision where revieion can be
186   * a git hash.
187   */
188  void version_parse (const std::string& str,
189                      uint64_t&          major,
190                      uint64_t&          minor,
191                      uint64_t&          revision);
192
193  /**
194   * Increment the verbose level.
195   */
196  void verbose_inc ();
197
198  /**
199   * Return the verbose level. Setting the flag more than once raises the
200   * level.
201   */
202  int verbose (int level = 0);
203
204  /**
205   * The version string.
206   */
207  const std::string version ();
208
209  /**
210   * Get the major version number.
211   */
212  uint64_t version_major ();
213
214  /**
215   * Get the minor version number.
216   */
217  uint64_t version_minor ();
218
219  /**
220   * Get the revision version number.
221   */
222  uint64_t version_revision ();
223
224  /**
225   * Container of strings to hold the results of a split.
226   */
227  typedef std::vector < std::string > strings;
228
229  /**
230   * Set the command line.
231   */
232  void set_cmdline (int argc, char* argv[]);
233
234  /**
235   * Get the command line.
236   */
237  const std::string get_cmdline ();
238
239  /**
240   * Set the progname.
241   */
242  void set_progname (const std::string& progname);
243
244  /**
245   * Get the progname. This is an absolute path.
246   */
247  const std::string get_progname ();
248
249  /**
250   * Get the program name.
251   */
252  const std::string get_program_name ();
253
254  /**
255   * Get the program path.
256   */
257  const std::string get_program_path ();
258
259  /**
260   * Get the current install prefix. If the path to the executable has 'bin' as
261   * the executable's parent directory it is assumed the executable has been
262   * installed under a standard PREFIX. If "bin" is not found return the
263   * executable's absolute path.
264   */
265  const std::string get_prefix ();
266
267  /**
268   * Map of the cache and the symbol table.
269   */
270  void map (rld::files::cache& cache, rld::symbols::table& symbols);
271
272  /**
273   * Warn if externals in referenced object files are not used.
274   */
275  void warn_unused_externals (rld::files::object_list& objects);
276}
277
278#endif
Note: See TracBrowser for help on using the repository browser.