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; }
92 Dir_list search_path_
;
93 const char* output_file_name_
;
98 // Don't copy this structure.
99 General_options(const General_options
&);
100 General_options
& operator=(const General_options
&);
103 // The current state of the position dependent options.
105 class Position_dependent_options
108 Position_dependent_options();
110 // -Bstatic: Whether we are searching for a static archive rather
111 // -than a shared object.
114 { return this->do_static_search_
; }
117 friend class Command_line
;
118 friend class options::Command_line_options
;
122 { this->do_static_search_
= true; }
126 { this->do_static_search_
= false; }
128 bool do_static_search_
;
131 // A single file or library argument from the command line.
133 class Input_file_argument
136 Input_file_argument()
137 : name_(NULL
), is_lib_(false), options_()
140 Input_file_argument(const char* name
, bool is_lib
,
141 const Position_dependent_options
& options
)
142 : name_(name
), is_lib_(is_lib
), options_(options
)
147 { return this->name_
; }
149 const Position_dependent_options
&
151 { return this->options_
; }
155 { return this->is_lib_
; }
160 Position_dependent_options options_
;
163 // A file or library, or a group, from the command line.
168 // Create a file or library argument.
169 explicit Input_argument(Input_file_argument file
)
170 : is_file_(true), file_(file
), group_(NULL
)
173 // Create a group argument.
174 explicit Input_argument(Input_file_group
* group
)
175 : is_file_(false), group_(group
)
178 // Return whether this is a file.
181 { return this->is_file_
; }
183 // Return whether this is a group.
186 { return !this->is_file_
; }
188 // Return the information about the file.
189 const Input_file_argument
&
192 assert(this->is_file_
);
196 // Return the information about the group.
197 const Input_file_group
*
200 assert(!this->is_file_
);
207 assert(!this->is_file_
);
213 Input_file_argument file_
;
214 Input_file_group
* group_
;
217 // A group from the command line. This is a set of arguments within
218 // --start-group ... --end-group.
220 class Input_file_group
223 typedef std::vector
<Input_argument
> Files
;
224 typedef Files::const_iterator const_iterator
;
230 // Add a file to the end of the group.
232 add_file(const Input_file_argument
& arg
)
233 { this->files_
.push_back(Input_argument(arg
)); }
235 // Iterators to iterate over the group contents.
239 { return this->files_
.begin(); }
243 { return this->files_
.end(); }
249 // All the information read from the command line.
254 typedef std::vector
<Input_argument
> Input_arguments
;
255 typedef Input_arguments::const_iterator const_iterator
;
259 // Process the command line options. This will exit with an
260 // appropriate error message if an unrecognized option is seen.
262 process(int argc
, char** argv
);
264 // Handle a -l option.
266 process_l_option(int, char**, char*);
268 // Handle a --start-group option.
270 start_group(const char* arg
);
272 // Handle a --end-group option.
274 end_group(const char* arg
);
276 // Get the general options.
277 const General_options
&
279 { return this->options_
; }
281 // Iterators to iterate over the list of input files.
285 { return this->inputs_
.begin(); }
289 { return this->inputs_
.end(); }
292 Command_line(const Command_line
&);
293 Command_line
& operator=(const Command_line
&);
295 // Report usage error.
297 usage() ATTRIBUTE_NORETURN
;
299 usage(const char* msg
, const char* opt
) ATTRIBUTE_NORETURN
;
301 usage(const char* msg
, char opt
) ATTRIBUTE_NORETURN
;
303 // Apply a command line option.
305 apply_option(const gold::options::One_option
&, const char*);
309 add_file(const char* name
, bool is_lib
);
311 General_options options_
;
312 Position_dependent_options position_options_
;
313 Input_arguments inputs_
;
317 } // End namespace gold.
319 #endif // !defined(GOLD_OPTIONS_H)