aboutsummaryrefslogtreecommitdiff
path: root/gold/options.h
blob: 6ac1ab9c1e052e73ccd89f70872fab9e5195df75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// options.h -- handle command line options for gold  -*- C++ -*-

// Command_line
//   Holds everything we get from the command line.
// General_options (from Command_line::options())
//   Options which are not position dependent.
// Input_argument (from Command_line::inputs())
//   The list of input files, including -l options.
// Position_dependent_options (from Input_argument::options())
//   Position dependent options which apply to this argument.

#ifndef GOLD_OPTIONS_H
#define GOLD_OPTIONS_H

#include <list>

namespace gold
{

class Command_line;

namespace options {

class Command_line_options;
struct One_option;

} // End namespace gold::options.

// The position independent options which apply to the whole link.
// There are a lot of them.

class General_options
{
 public:
  General_options();

  // -L: Library search path.
  typedef std::list<const char*> Dir_list;

  const Dir_list&
  search_path() const
  { return this->search_path_; }

  // -r: Whether we are doing a relocatable link.
  bool
  is_relocatable() const
  { return this->is_relocatable_; }

  // --static: Whether doing a static link.
  bool
  is_static() const
  { return this->is_static_; }

 private:
  friend class Command_line;
  friend class options::Command_line_options;

  void
  add_to_search_path(const char* arg)
  { this->search_path_.push_back(arg); }

  void
  set_relocatable()
  { this->is_relocatable_ = true; }

  void
  set_static()
  { this->is_static_ = true; }

  Dir_list search_path_;
  bool is_relocatable_;
  bool is_static_;

  // Don't copy this structure.
  General_options(const General_options&);
  General_options& operator=(const General_options&);
};

// The current state of the position dependent options.

class Position_dependent_options
{
 public:
  Position_dependent_options();

  // -Bstatic: Whether we are searching for a static archive rather
  // -than a shared object.
  bool
  do_static_search()
  { return this->do_static_search_; }

 private:
  friend class Command_line;
  friend class options::Command_line_options;

  void
  set_static_search()
  { this->do_static_search_ = true; }

  void
  set_dynamic_search()
  { this->do_static_search_ = false; }

  bool do_static_search_;
};

// A single file or library argument from the command line.

class Input_argument
{
 public:
  Input_argument(const char* name, const Position_dependent_options& options)
    : name_(name), options_(options)
  { }

  const char*
  name() const
  { return this->name_; }

  const Position_dependent_options&
  options() const
  { return this->options_; }

  bool
  is_lib() const
  { return this->name_[0] == '-' && this->name_[1] == 'l'; }

  const char*
  lib_basename() const
  { return this->name_ + 2; }

 private:
  const char* name_;
  Position_dependent_options options_;
};

// All the information read from the command line.

class Command_line
{
 public:
  Command_line();

  // Process the command line options.  This will exit with an
  // appropriate error message if an unrecognized option is seen.
  void
  process(int argc, char** argv);

  const General_options&
  options() const
  { return this->options_; }

  typedef std::list<Input_argument> Input_argument_list;

  const Input_argument_list&
  inputs() const
  { return this->inputs_; }

 private:
  void usage() ATTRIBUTE_NORETURN;
  void usage(const char* msg, const char* opt) ATTRIBUTE_NORETURN;
  void usage(const char* msg, char opt) ATTRIBUTE_NORETURN;
  void apply_option(const gold::options::One_option&, const char*);

  General_options options_;
  Position_dependent_options position_options_;
  Input_argument_list inputs_;
};

} // End namespace gold.

#endif // !defined(GOLD_OPTIONS_H)