* peXXigen.c: Updates for PE/COFF V8.0, and clarification
[deliverable/binutils-gdb.git] / gold / options.h
CommitLineData
bae7f79e
ILT
1// options.h -- handle command line options for gold -*- C++ -*-
2
3// Command_line
4// Holds everything we get from the command line.
5// General_options (from Command_line::options())
6// Options which are not position dependent.
7// Input_argument (from Command_line::inputs())
8// The list of input files, including -l options.
9// Position_dependent_options (from Input_argument::options())
10// Position dependent options which apply to this argument.
11
12#ifndef GOLD_OPTIONS_H
13#define GOLD_OPTIONS_H
14
15#include <list>
61ba1cf9 16#include <string>
92e059d8 17#include <vector>
ead1e424 18#include <cassert>
bae7f79e 19
bae7f79e
ILT
20namespace gold
21{
22
23class Command_line;
ead1e424 24class Input_file_group;
bae7f79e
ILT
25
26namespace options {
27
28class Command_line_options;
29struct One_option;
30
31} // End namespace gold::options.
32
33// The position independent options which apply to the whole link.
34// There are a lot of them.
35
36class General_options
37{
38 public:
39 General_options();
40
41 // -L: Library search path.
42 typedef std::list<const char*> Dir_list;
43
44 const Dir_list&
45 search_path() const
46 { return this->search_path_; }
47
61ba1cf9
ILT
48 // -o: Output file name.
49 const char*
50 output_file_name() const
51 { return this->output_file_name_; }
52
bae7f79e
ILT
53 // -r: Whether we are doing a relocatable link.
54 bool
55 is_relocatable() const
56 { return this->is_relocatable_; }
57
92e059d8
ILT
58 // --shared: Whether generating a shared object.
59 bool
60 is_shared() const
61 { return this->is_shared_; }
62
bae7f79e
ILT
63 // --static: Whether doing a static link.
64 bool
65 is_static() const
66 { return this->is_static_; }
67
68 private:
69 friend class Command_line;
70 friend class options::Command_line_options;
71
72 void
73 add_to_search_path(const char* arg)
74 { this->search_path_.push_back(arg); }
75
61ba1cf9
ILT
76 void
77 set_output_file_name(const char* arg)
78 { this->output_file_name_ = arg; }
79
bae7f79e
ILT
80 void
81 set_relocatable()
82 { this->is_relocatable_ = true; }
83
92e059d8
ILT
84 void
85 set_shared()
86 { this->is_shared_ = true; }
87
bae7f79e
ILT
88 void
89 set_static()
90 { this->is_static_ = true; }
91
652ec9bd
ILT
92 void
93 ignore(const char*)
94 { }
95
bae7f79e 96 Dir_list search_path_;
61ba1cf9 97 const char* output_file_name_;
bae7f79e 98 bool is_relocatable_;
92e059d8 99 bool is_shared_;
bae7f79e
ILT
100 bool is_static_;
101
102 // Don't copy this structure.
103 General_options(const General_options&);
104 General_options& operator=(const General_options&);
105};
106
107// The current state of the position dependent options.
108
109class Position_dependent_options
110{
111 public:
112 Position_dependent_options();
113
114 // -Bstatic: Whether we are searching for a static archive rather
115 // -than a shared object.
116 bool
117 do_static_search()
118 { return this->do_static_search_; }
119
120 private:
121 friend class Command_line;
122 friend class options::Command_line_options;
123
124 void
125 set_static_search()
126 { this->do_static_search_ = true; }
127
128 void
129 set_dynamic_search()
130 { this->do_static_search_ = false; }
131
132 bool do_static_search_;
133};
134
135// A single file or library argument from the command line.
136
ead1e424 137class Input_file_argument
bae7f79e
ILT
138{
139 public:
ead1e424
ILT
140 Input_file_argument()
141 : name_(NULL), is_lib_(false), options_()
142 { }
143
144 Input_file_argument(const char* name, bool is_lib,
145 const Position_dependent_options& options)
61ba1cf9 146 : name_(name), is_lib_(is_lib), options_(options)
bae7f79e
ILT
147 { }
148
149 const char*
150 name() const
151 { return this->name_; }
152
153 const Position_dependent_options&
154 options() const
155 { return this->options_; }
156
157 bool
158 is_lib() const
61ba1cf9 159 { return this->is_lib_; }
bae7f79e
ILT
160
161 private:
162 const char* name_;
61ba1cf9 163 bool is_lib_;
bae7f79e
ILT
164 Position_dependent_options options_;
165};
166
ead1e424
ILT
167// A file or library, or a group, from the command line.
168
169class Input_argument
170{
171 public:
172 // Create a file or library argument.
173 explicit Input_argument(Input_file_argument file)
174 : is_file_(true), file_(file), group_(NULL)
175 { }
176
177 // Create a group argument.
178 explicit Input_argument(Input_file_group* group)
179 : is_file_(false), group_(group)
180 { }
181
182 // Return whether this is a file.
183 bool
184 is_file() const
185 { return this->is_file_; }
186
187 // Return whether this is a group.
188 bool
189 is_group() const
190 { return !this->is_file_; }
191
192 // Return the information about the file.
193 const Input_file_argument&
194 file() const
195 {
196 assert(this->is_file_);
197 return this->file_;
198 }
199
200 // Return the information about the group.
201 const Input_file_group*
202 group() const
203 {
204 assert(!this->is_file_);
205 return this->group_;
206 }
207
208 Input_file_group*
209 group()
210 {
211 assert(!this->is_file_);
212 return this->group_;
213 }
214
215 private:
216 bool is_file_;
217 Input_file_argument file_;
218 Input_file_group* group_;
219};
220
221// A group from the command line. This is a set of arguments within
222// --start-group ... --end-group.
223
224class Input_file_group
92e059d8 225{
ead1e424
ILT
226 public:
227 typedef std::vector<Input_argument> Files;
228 typedef Files::const_iterator const_iterator;
229
230 Input_file_group()
231 : files_()
232 { }
233
234 // Add a file to the end of the group.
235 void
236 add_file(const Input_file_argument& arg)
237 { this->files_.push_back(Input_argument(arg)); }
238
239 // Iterators to iterate over the group contents.
240
241 const_iterator
242 begin() const
243 { return this->files_.begin(); }
244
245 const_iterator
246 end() const
247 { return this->files_.end(); }
248
249 private:
250 Files files_;
92e059d8
ILT
251};
252
bae7f79e
ILT
253// All the information read from the command line.
254
255class Command_line
256{
257 public:
ead1e424
ILT
258 typedef std::vector<Input_argument> Input_arguments;
259 typedef Input_arguments::const_iterator const_iterator;
260
bae7f79e
ILT
261 Command_line();
262
263 // Process the command line options. This will exit with an
264 // appropriate error message if an unrecognized option is seen.
265 void
266 process(int argc, char** argv);
267
61ba1cf9
ILT
268 // Handle a -l option.
269 int
270 process_l_option(int, char**, char*);
271
ead1e424
ILT
272 // Handle a --start-group option.
273 void
274 start_group(const char* arg);
275
276 // Handle a --end-group option.
277 void
278 end_group(const char* arg);
279
61ba1cf9 280 // Get the general options.
bae7f79e
ILT
281 const General_options&
282 options() const
283 { return this->options_; }
284
ead1e424
ILT
285 // Iterators to iterate over the list of input files.
286
287 const_iterator
288 begin() const
289 { return this->inputs_.begin(); }
290
291 const_iterator
292 end() const
293 { return this->inputs_.end(); }
bae7f79e
ILT
294
295 private:
ead1e424
ILT
296 Command_line(const Command_line&);
297 Command_line& operator=(const Command_line&);
298
299 // Report usage error.
300 void
301 usage() ATTRIBUTE_NORETURN;
302 void
303 usage(const char* msg, const char* opt) ATTRIBUTE_NORETURN;
304 void
305 usage(const char* msg, char opt) ATTRIBUTE_NORETURN;
306
307 // Apply a command line option.
308 void
309 apply_option(const gold::options::One_option&, const char*);
310
311 // Add a file.
312 void
313 add_file(const char* name, bool is_lib);
bae7f79e
ILT
314
315 General_options options_;
316 Position_dependent_options position_options_;
ead1e424
ILT
317 Input_arguments inputs_;
318 bool in_group_;
bae7f79e
ILT
319};
320
321} // End namespace gold.
322
323#endif // !defined(GOLD_OPTIONS_H)
This page took 0.045829 seconds and 4 git commands to generate.