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 // -L: Library search path.
42 typedef std::list
<const char*> Dir_list
;
46 { return this->search_path_
; }
48 // -o: Output file name.
50 output_file_name() const
51 { return this->output_file_name_
; }
53 // -r: Whether we are doing a relocatable link.
55 is_relocatable() const
56 { return this->is_relocatable_
; }
58 // --shared: Whether generating a shared object.
61 { return this->is_shared_
; }
63 // --static: Whether doing a static link.
66 { return this->is_static_
; }
69 friend class Command_line
;
70 friend class options::Command_line_options
;
73 add_to_search_path(const char* arg
)
74 { this->search_path_
.push_back(arg
); }
77 set_output_file_name(const char* arg
)
78 { this->output_file_name_
= arg
; }
82 { this->is_relocatable_
= true; }
86 { this->is_shared_
= true; }
90 { this->is_static_
= true; }
96 Dir_list search_path_
;
97 const char* output_file_name_
;
102 // Don't copy this structure.
103 General_options(const General_options
&);
104 General_options
& operator=(const General_options
&);
107 // The current state of the position dependent options.
109 class Position_dependent_options
112 Position_dependent_options();
114 // -Bstatic: Whether we are searching for a static archive rather
115 // -than a shared object.
118 { return this->do_static_search_
; }
121 friend class Command_line
;
122 friend class options::Command_line_options
;
126 { this->do_static_search_
= true; }
130 { this->do_static_search_
= false; }
132 bool do_static_search_
;
135 // A single file or library argument from the command line.
137 class Input_file_argument
140 Input_file_argument()
141 : name_(NULL
), is_lib_(false), options_()
144 Input_file_argument(const char* name
, bool is_lib
,
145 const Position_dependent_options
& options
)
146 : name_(name
), is_lib_(is_lib
), options_(options
)
151 { return this->name_
; }
153 const Position_dependent_options
&
155 { return this->options_
; }
159 { return this->is_lib_
; }
164 Position_dependent_options options_
;
167 // A file or library, or a group, from the command line.
172 // Create a file or library argument.
173 explicit Input_argument(Input_file_argument file
)
174 : is_file_(true), file_(file
), group_(NULL
)
177 // Create a group argument.
178 explicit Input_argument(Input_file_group
* group
)
179 : is_file_(false), group_(group
)
182 // Return whether this is a file.
185 { return this->is_file_
; }
187 // Return whether this is a group.
190 { return !this->is_file_
; }
192 // Return the information about the file.
193 const Input_file_argument
&
196 assert(this->is_file_
);
200 // Return the information about the group.
201 const Input_file_group
*
204 assert(!this->is_file_
);
211 assert(!this->is_file_
);
217 Input_file_argument file_
;
218 Input_file_group
* group_
;
221 // A group from the command line. This is a set of arguments within
222 // --start-group ... --end-group.
224 class Input_file_group
227 typedef std::vector
<Input_argument
> Files
;
228 typedef Files::const_iterator const_iterator
;
234 // Add a file to the end of the group.
236 add_file(const Input_file_argument
& arg
)
237 { this->files_
.push_back(Input_argument(arg
)); }
239 // Iterators to iterate over the group contents.
243 { return this->files_
.begin(); }
247 { return this->files_
.end(); }
253 // All the information read from the command line.
258 typedef std::vector
<Input_argument
> Input_arguments
;
259 typedef Input_arguments::const_iterator const_iterator
;
263 // Process the command line options. This will exit with an
264 // appropriate error message if an unrecognized option is seen.
266 process(int argc
, char** argv
);
268 // Handle a -l option.
270 process_l_option(int, char**, char*);
272 // Handle a --start-group option.
274 start_group(const char* arg
);
276 // Handle a --end-group option.
278 end_group(const char* arg
);
280 // Get the general options.
281 const General_options
&
283 { return this->options_
; }
285 // Iterators to iterate over the list of input files.
289 { return this->inputs_
.begin(); }
293 { return this->inputs_
.end(); }
296 Command_line(const Command_line
&);
297 Command_line
& operator=(const Command_line
&);
299 // Report usage error.
301 usage() ATTRIBUTE_NORETURN
;
303 usage(const char* msg
, const char* opt
) ATTRIBUTE_NORETURN
;
305 usage(const char* msg
, char opt
) ATTRIBUTE_NORETURN
;
307 // Apply a command line option.
309 apply_option(const gold::options::One_option
&, const char*);
313 add_file(const char* name
, bool is_lib
);
315 General_options options_
;
316 Position_dependent_options position_options_
;
317 Input_arguments inputs_
;
321 } // End namespace gold.
323 #endif // !defined(GOLD_OPTIONS_H)