source: rtems-tools/rtemstoolkit/rld.h @ 0c0b2d4

4.10
Last change on this file since 0c0b2d4 was 0c0b2d4, checked in by Chris Johns <chrisj@…>, on Apr 3, 2016 at 5:37:01 AM

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
RevLine 
[ec24a37]1/*
[1d60a4a]2 * Copyright (c) 2011, Chris Johns <chrisj@rtems.org>
[ec24a37]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.
[1d60a4a]7 *
[ec24a37]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
[b6d7f5f]28#include <algorithm>
29#include <cctype>
30#include <functional>
[ec24a37]31#include <iostream>
[0c0b2d4]32#include <list>
[b6d7f5f]33#include <locale>
[ec24a37]34#include <sstream>
35#include <string>
36
37/**
38 * Path handling for Windows.
39 */
40#if __WIN32__
41#define RLD_PATH_SEPARATOR        '\\'
[a72a9e35]42#define RLD_PATH_SEPARATOR_STR    "\\"
[ec24a37]43#define RLD_PATHSTR_SEPARATOR     ';'
44#define RLD_PATHSTR_SEPARATOR_STR ";"
45#define RLD_DRIVE_SEPARATOR       (1)
[4fd758e]46#define RLD_LINE_SEPARATOR        "\r\n"
[ec24a37]47#else
48#define RLD_PATH_SEPARATOR        '/'
[a72a9e35]49#define RLD_PATH_SEPARATOR_STR    "/"
[ec24a37]50#define RLD_PATHSTR_SEPARATOR     ':'
51#define RLD_PATHSTR_SEPARATOR_STR ":"
52#define RLD_DRIVE_SEPARATOR       (0)
[4fd758e]53#define RLD_LINE_SEPARATOR        "\n"
[ec24a37]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;
[0c0b2d4]67    class cache;
68    typedef std::list < object* > object_list;
[ec24a37]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)
[1d60a4a]84#define RLD_VERBOSE_TRACE_SYMS (4)
[13b9f2b]85#define RLD_VERBOSE_TRACE_FILE (5)
86#define RLD_VERBOSE_FULL_DEBUG (6)
[ec24a37]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
[b6d7f5f]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
[7ccb670]129  /**
130   * Does a string start with another string ?
131   */
[6506aa1]132  bool starts_with(const std::string& s1, const std::string& s2);
[7ccb670]133
[b6d7f5f]134  /**
135   * Trim from start.
136   */
[6506aa1]137  const std::string ltrim (const std::string& s);
[b6d7f5f]138
139  /**
140   * Trim from end.
141   */
[6506aa1]142  const std::string rtrim (const std::string& s);
[b6d7f5f]143
144  /**
145   * Trim from both ends.
146   */
[6506aa1]147  const std::string trim (const std::string& s);
[b6d7f5f]148
[058d502]149  /**
150   * Dequote a string.
151   */
[6506aa1]152  const std::string dequote (const std::string& s);
[058d502]153
154  /**
155   * Find and replace.
156   */
[6506aa1]157  const std::string find_replace(const std::string& sin,
158                                 const std::string& out,
159                                 const std::string& in);
[058d502]160
[b6d7f5f]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   */
[6506aa1]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);
[b6d7f5f]173
174  /**
175   * Join the strings together with the separator.
176   */
[6506aa1]177  const std::string join (const strings& ss, const std::string& separator);
[b6d7f5f]178
[7ccb670]179  /**
180   * Convert a string to lower case.
181   */
[6506aa1]182  const std::string tolower (const std::string& sin);
[7ccb670]183
[0c0b2d4]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
[ec24a37]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   */
[30a7f06]202  int verbose (int level = 0);
[ec24a37]203
204  /**
205   * The version string.
206   */
207  const std::string version ();
208
[0c0b2d4]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
[ec24a37]224  /**
225   * Container of strings to hold the results of a split.
226   */
227  typedef std::vector < std::string > strings;
228
[b7ad4a2]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
[6506aa1]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
[ec24a37]267  /**
[df7fd26]268   * Map of the cache and the symbol table.
[ec24a37]269   */
270  void map (rld::files::cache& cache, rld::symbols::table& symbols);
271
272  /**
[6506aa1]273   * Warn if externals in referenced object files are not used.
[ec24a37]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.