aboutsummaryrefslogtreecommitdiff
path: root/gold/options.h
blob: ba32ef569997d3f419c0b2a7dfd82a7d2864e245 (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// 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>
#include <string>

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_; }

  // -o: Output file name.
  const char*
  output_file_name() const
  { return this->output_file_name_; }

  // -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_output_file_name(const char* arg)
  { this->output_file_name_ = arg; }

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

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

  Dir_list search_path_;
  const char* output_file_name_;
  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, bool is_lib,
		 const Position_dependent_options& options)
    : name_(name), is_lib_(is_lib), options_(options)
  { }

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

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

  bool
  is_lib() const
  { return this->is_lib_; }

 private:
  const char* name_;
  bool is_lib_;
  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);

  // Handle a -l option.
  int
  process_l_option(int, char**, char*);

  // Get the general options.
  const General_options&
  options() const
  { return this->options_; }

  typedef std::list<Input_argument> Input_argument_list;

  // Get the list of input files.
  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)