1 // options.h -- handle command line options for gold -*- C++ -*-
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.
12 #ifndef GOLD_OPTIONS_H
13 #define GOLD_OPTIONS_H
24 class Input_file_group
;
28 class Command_line_options
;
31 } // End namespace gold::options.
33 // The position independent options which apply to the whole link.
34 // There are a lot of them.
41 // -I: dynamic linker name.
43 dynamic_linker() const
44 { return this->dynamic_linker_
; }
46 // -L: Library search path.
47 typedef std::list
<const char*> Dir_list
;
51 { return this->search_path_
; }
53 // -o: Output file name.
55 output_file_name() const
56 { return this->output_file_name_
; }
58 // -r: Whether we are doing a relocatable link.
60 is_relocatable() const
61 { return this->is_relocatable_
; }
63 // --shared: Whether generating a shared object.
66 { return this->is_shared_
; }
68 // --static: Whether doing a static link.
71 { return this->is_static_
; }
74 // Don't copy this structure.
75 General_options(const General_options
&);
76 General_options
& operator=(const General_options
&);
78 friend class Command_line
;
79 friend class options::Command_line_options
;
82 set_dynamic_linker(const char* arg
)
83 { this->dynamic_linker_
= arg
; }
86 add_to_search_path(const char* arg
)
87 { this->search_path_
.push_back(arg
); }
90 set_output_file_name(const char* arg
)
91 { this->output_file_name_
= arg
; }
95 { this->is_relocatable_
= true; }
99 { this->is_shared_
= true; }
103 { this->is_static_
= true; }
109 const char* dynamic_linker_
;
110 Dir_list search_path_
;
111 const char* output_file_name_
;
112 bool is_relocatable_
;
117 // The current state of the position dependent options.
119 class Position_dependent_options
122 Position_dependent_options();
124 // -Bstatic: Whether we are searching for a static archive rather
125 // than a shared object.
127 do_static_search() const
128 { return this->do_static_search_
; }
130 // --as-needed: Whether to add a DT_NEEDED argument only if the
131 // dynamic object is used.
134 { return this->as_needed_
; }
138 { this->do_static_search_
= true; }
142 { this->do_static_search_
= false; }
146 { this->as_needed_
= true; }
150 { this->as_needed_
= false; }
153 bool do_static_search_
;
157 // A single file or library argument from the command line.
159 class Input_file_argument
162 Input_file_argument()
163 : name_(), is_lib_(false), options_()
166 Input_file_argument(const char* name
, bool is_lib
,
167 const Position_dependent_options
& options
)
168 : name_(name
), is_lib_(is_lib
), options_(options
)
173 { return this->name_
.c_str(); }
175 const Position_dependent_options
&
177 { return this->options_
; }
181 { return this->is_lib_
; }
184 // We use std::string, not const char*, here for convenience when
185 // using script files, so that we do not have to preserve the string
189 Position_dependent_options options_
;
192 // A file or library, or a group, from the command line.
197 // Create a file or library argument.
198 explicit Input_argument(Input_file_argument file
)
199 : is_file_(true), file_(file
), group_(NULL
)
202 // Create a group argument.
203 explicit Input_argument(Input_file_group
* group
)
204 : is_file_(false), group_(group
)
207 // Return whether this is a file.
210 { return this->is_file_
; }
212 // Return whether this is a group.
215 { return !this->is_file_
; }
217 // Return the information about the file.
218 const Input_file_argument
&
221 assert(this->is_file_
);
225 // Return the information about the group.
226 const Input_file_group
*
229 assert(!this->is_file_
);
236 assert(!this->is_file_
);
242 Input_file_argument file_
;
243 Input_file_group
* group_
;
246 // A group from the command line. This is a set of arguments within
247 // --start-group ... --end-group.
249 class Input_file_group
252 typedef std::vector
<Input_argument
> Files
;
253 typedef Files::const_iterator const_iterator
;
259 // Add a file to the end of the group.
261 add_file(const Input_file_argument
& arg
)
262 { this->files_
.push_back(Input_argument(arg
)); }
264 // Iterators to iterate over the group contents.
268 { return this->files_
.begin(); }
272 { return this->files_
.end(); }
278 // A list of files from the command line or a script.
280 class Input_arguments
283 typedef std::vector
<Input_argument
> Input_argument_list
;
284 typedef Input_argument_list::const_iterator const_iterator
;
287 : input_argument_list_(), in_group_(false)
292 add_file(const Input_file_argument
& arg
);
294 // Start a group (the --start-group option).
298 // End a group (the --end-group option).
302 // Return whether we are currently in a group.
305 { return this->in_group_
; }
307 // Iterators to iterate over the list of input files.
311 { return this->input_argument_list_
.begin(); }
315 { return this->input_argument_list_
.end(); }
317 // Return whether the list is empty.
320 { return this->input_argument_list_
.empty(); }
323 Input_argument_list input_argument_list_
;
327 // All the information read from the command line.
332 typedef Input_arguments::const_iterator const_iterator
;
336 // Process the command line options. This will exit with an
337 // appropriate error message if an unrecognized option is seen.
339 process(int argc
, char** argv
);
341 // Handle a -l option.
343 process_l_option(int, char**, char*);
345 // Handle a --start-group option.
347 start_group(const char* arg
);
349 // Handle a --end-group option.
351 end_group(const char* arg
);
353 // Get the general options.
354 const General_options
&
356 { return this->options_
; }
358 // Iterators to iterate over the list of input files.
362 { return this->inputs_
.begin(); }
366 { return this->inputs_
.end(); }
369 Command_line(const Command_line
&);
370 Command_line
& operator=(const Command_line
&);
372 // Report usage error.
374 usage() ATTRIBUTE_NORETURN
;
376 usage(const char* msg
, const char* opt
) ATTRIBUTE_NORETURN
;
378 usage(const char* msg
, char opt
) ATTRIBUTE_NORETURN
;
380 // Apply a command line option.
382 apply_option(const gold::options::One_option
&, const char*);
386 add_file(const char* name
, bool is_lib
);
388 General_options options_
;
389 Position_dependent_options position_options_
;
390 Input_arguments inputs_
;
393 } // End namespace gold.
395 #endif // !defined(GOLD_OPTIONS_H)