* gdb.cp/annota2.exp ("watch triggered on a.x"): Allow arbitrary
[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>
bae7f79e 18
bae7f79e
ILT
19namespace gold
20{
21
22class Command_line;
ead1e424 23class Input_file_group;
bae7f79e
ILT
24
25namespace options {
26
27class Command_line_options;
28struct One_option;
29
30} // End namespace gold::options.
31
32// The position independent options which apply to the whole link.
33// There are a lot of them.
34
35class General_options
36{
37 public:
38 General_options();
39
dbe717ef
ILT
40 // -I: dynamic linker name.
41 const char*
42 dynamic_linker() const
43 { return this->dynamic_linker_; }
44
bae7f79e
ILT
45 // -L: Library search path.
46 typedef std::list<const char*> Dir_list;
47
48 const Dir_list&
49 search_path() const
50 { return this->search_path_; }
51
61ba1cf9
ILT
52 // -o: Output file name.
53 const char*
54 output_file_name() const
55 { return this->output_file_name_; }
56
bae7f79e
ILT
57 // -r: Whether we are doing a relocatable link.
58 bool
59 is_relocatable() const
60 { return this->is_relocatable_; }
61
92e059d8
ILT
62 // --shared: Whether generating a shared object.
63 bool
64 is_shared() const
65 { return this->is_shared_; }
66
bae7f79e
ILT
67 // --static: Whether doing a static link.
68 bool
69 is_static() const
70 { return this->is_static_; }
71
72 private:
dbe717ef
ILT
73 // Don't copy this structure.
74 General_options(const General_options&);
75 General_options& operator=(const General_options&);
76
bae7f79e
ILT
77 friend class Command_line;
78 friend class options::Command_line_options;
79
dbe717ef
ILT
80 void
81 set_dynamic_linker(const char* arg)
82 { this->dynamic_linker_ = arg; }
83
bae7f79e
ILT
84 void
85 add_to_search_path(const char* arg)
86 { this->search_path_.push_back(arg); }
87
61ba1cf9
ILT
88 void
89 set_output_file_name(const char* arg)
90 { this->output_file_name_ = arg; }
91
bae7f79e
ILT
92 void
93 set_relocatable()
94 { this->is_relocatable_ = true; }
95
92e059d8
ILT
96 void
97 set_shared()
98 { this->is_shared_ = true; }
99
bae7f79e
ILT
100 void
101 set_static()
102 { this->is_static_ = true; }
103
652ec9bd
ILT
104 void
105 ignore(const char*)
106 { }
107
dbe717ef 108 const char* dynamic_linker_;
bae7f79e 109 Dir_list search_path_;
61ba1cf9 110 const char* output_file_name_;
bae7f79e 111 bool is_relocatable_;
92e059d8 112 bool is_shared_;
bae7f79e 113 bool is_static_;
bae7f79e
ILT
114};
115
116// The current state of the position dependent options.
117
118class Position_dependent_options
119{
120 public:
121 Position_dependent_options();
122
123 // -Bstatic: Whether we are searching for a static archive rather
dbe717ef 124 // than a shared object.
bae7f79e 125 bool
dbe717ef 126 do_static_search() const
bae7f79e
ILT
127 { return this->do_static_search_; }
128
dbe717ef
ILT
129 // --as-needed: Whether to add a DT_NEEDED argument only if the
130 // dynamic object is used.
131 bool
132 as_needed() const
133 { return this->as_needed_; }
bae7f79e
ILT
134
135 void
136 set_static_search()
137 { this->do_static_search_ = true; }
138
139 void
140 set_dynamic_search()
141 { this->do_static_search_ = false; }
142
dbe717ef
ILT
143 void
144 set_as_needed()
145 { this->as_needed_ = true; }
146
147 void
148 clear_as_needed()
149 { this->as_needed_ = false; }
150
151 private:
bae7f79e 152 bool do_static_search_;
dbe717ef 153 bool as_needed_;
bae7f79e
ILT
154};
155
156// A single file or library argument from the command line.
157
ead1e424 158class Input_file_argument
bae7f79e
ILT
159{
160 public:
ead1e424 161 Input_file_argument()
dbe717ef 162 : name_(), is_lib_(false), options_()
ead1e424
ILT
163 { }
164
165 Input_file_argument(const char* name, bool is_lib,
166 const Position_dependent_options& options)
61ba1cf9 167 : name_(name), is_lib_(is_lib), options_(options)
bae7f79e
ILT
168 { }
169
170 const char*
171 name() const
dbe717ef 172 { return this->name_.c_str(); }
bae7f79e
ILT
173
174 const Position_dependent_options&
175 options() const
176 { return this->options_; }
177
178 bool
179 is_lib() const
61ba1cf9 180 { return this->is_lib_; }
bae7f79e
ILT
181
182 private:
dbe717ef
ILT
183 // We use std::string, not const char*, here for convenience when
184 // using script files, so that we do not have to preserve the string
185 // in that case.
186 std::string name_;
61ba1cf9 187 bool is_lib_;
bae7f79e
ILT
188 Position_dependent_options options_;
189};
190
ead1e424
ILT
191// A file or library, or a group, from the command line.
192
193class Input_argument
194{
195 public:
196 // Create a file or library argument.
197 explicit Input_argument(Input_file_argument file)
198 : is_file_(true), file_(file), group_(NULL)
199 { }
200
201 // Create a group argument.
202 explicit Input_argument(Input_file_group* group)
203 : is_file_(false), group_(group)
204 { }
205
206 // Return whether this is a file.
207 bool
208 is_file() const
209 { return this->is_file_; }
210
211 // Return whether this is a group.
212 bool
213 is_group() const
214 { return !this->is_file_; }
215
216 // Return the information about the file.
217 const Input_file_argument&
218 file() const
219 {
a3ad94ed 220 gold_assert(this->is_file_);
ead1e424
ILT
221 return this->file_;
222 }
223
224 // Return the information about the group.
225 const Input_file_group*
226 group() const
227 {
a3ad94ed 228 gold_assert(!this->is_file_);
ead1e424
ILT
229 return this->group_;
230 }
231
232 Input_file_group*
233 group()
234 {
a3ad94ed 235 gold_assert(!this->is_file_);
ead1e424
ILT
236 return this->group_;
237 }
238
239 private:
240 bool is_file_;
241 Input_file_argument file_;
242 Input_file_group* group_;
243};
244
245// A group from the command line. This is a set of arguments within
246// --start-group ... --end-group.
247
248class Input_file_group
92e059d8 249{
ead1e424
ILT
250 public:
251 typedef std::vector<Input_argument> Files;
252 typedef Files::const_iterator const_iterator;
253
254 Input_file_group()
255 : files_()
256 { }
257
258 // Add a file to the end of the group.
259 void
260 add_file(const Input_file_argument& arg)
261 { this->files_.push_back(Input_argument(arg)); }
262
263 // Iterators to iterate over the group contents.
264
265 const_iterator
266 begin() const
267 { return this->files_.begin(); }
268
269 const_iterator
270 end() const
271 { return this->files_.end(); }
272
273 private:
274 Files files_;
92e059d8
ILT
275};
276
dbe717ef
ILT
277// A list of files from the command line or a script.
278
279class Input_arguments
280{
281 public:
282 typedef std::vector<Input_argument> Input_argument_list;
283 typedef Input_argument_list::const_iterator const_iterator;
284
285 Input_arguments()
286 : input_argument_list_(), in_group_(false)
287 { }
288
289 // Add a file.
290 void
291 add_file(const Input_file_argument& arg);
292
293 // Start a group (the --start-group option).
294 void
295 start_group();
296
297 // End a group (the --end-group option).
298 void
299 end_group();
300
301 // Return whether we are currently in a group.
302 bool
303 in_group() const
304 { return this->in_group_; }
305
306 // Iterators to iterate over the list of input files.
307
308 const_iterator
309 begin() const
310 { return this->input_argument_list_.begin(); }
311
312 const_iterator
313 end() const
314 { return this->input_argument_list_.end(); }
315
316 // Return whether the list is empty.
317 bool
318 empty() const
319 { return this->input_argument_list_.empty(); }
320
321 private:
322 Input_argument_list input_argument_list_;
323 bool in_group_;
324};
325
bae7f79e
ILT
326// All the information read from the command line.
327
328class Command_line
329{
330 public:
ead1e424
ILT
331 typedef Input_arguments::const_iterator const_iterator;
332
bae7f79e
ILT
333 Command_line();
334
335 // Process the command line options. This will exit with an
336 // appropriate error message if an unrecognized option is seen.
337 void
338 process(int argc, char** argv);
339
61ba1cf9
ILT
340 // Handle a -l option.
341 int
342 process_l_option(int, char**, char*);
343
ead1e424
ILT
344 // Handle a --start-group option.
345 void
346 start_group(const char* arg);
347
348 // Handle a --end-group option.
349 void
350 end_group(const char* arg);
351
61ba1cf9 352 // Get the general options.
bae7f79e
ILT
353 const General_options&
354 options() const
355 { return this->options_; }
356
ead1e424
ILT
357 // Iterators to iterate over the list of input files.
358
359 const_iterator
360 begin() const
361 { return this->inputs_.begin(); }
362
363 const_iterator
364 end() const
365 { return this->inputs_.end(); }
bae7f79e
ILT
366
367 private:
ead1e424
ILT
368 Command_line(const Command_line&);
369 Command_line& operator=(const Command_line&);
370
371 // Report usage error.
372 void
373 usage() ATTRIBUTE_NORETURN;
374 void
375 usage(const char* msg, const char* opt) ATTRIBUTE_NORETURN;
376 void
377 usage(const char* msg, char opt) ATTRIBUTE_NORETURN;
378
379 // Apply a command line option.
380 void
381 apply_option(const gold::options::One_option&, const char*);
382
383 // Add a file.
384 void
385 add_file(const char* name, bool is_lib);
bae7f79e
ILT
386
387 General_options options_;
388 Position_dependent_options position_options_;
ead1e424 389 Input_arguments inputs_;
bae7f79e
ILT
390};
391
392} // End namespace gold.
393
394#endif // !defined(GOLD_OPTIONS_H)
This page took 0.051118 seconds and 4 git commands to generate.