Fix typo in comment.
[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;
23
24namespace options {
25
26class Command_line_options;
27struct One_option;
28
29} // End namespace gold::options.
30
31// The position independent options which apply to the whole link.
32// There are a lot of them.
33
34class General_options
35{
36 public:
37 General_options();
38
39 // -L: Library search path.
40 typedef std::list<const char*> Dir_list;
41
42 const Dir_list&
43 search_path() const
44 { return this->search_path_; }
45
61ba1cf9
ILT
46 // -o: Output file name.
47 const char*
48 output_file_name() const
49 { return this->output_file_name_; }
50
bae7f79e
ILT
51 // -r: Whether we are doing a relocatable link.
52 bool
53 is_relocatable() const
54 { return this->is_relocatable_; }
55
92e059d8
ILT
56 // --shared: Whether generating a shared object.
57 bool
58 is_shared() const
59 { return this->is_shared_; }
60
bae7f79e
ILT
61 // --static: Whether doing a static link.
62 bool
63 is_static() const
64 { return this->is_static_; }
65
66 private:
67 friend class Command_line;
68 friend class options::Command_line_options;
69
70 void
71 add_to_search_path(const char* arg)
72 { this->search_path_.push_back(arg); }
73
61ba1cf9
ILT
74 void
75 set_output_file_name(const char* arg)
76 { this->output_file_name_ = arg; }
77
bae7f79e
ILT
78 void
79 set_relocatable()
80 { this->is_relocatable_ = true; }
81
92e059d8
ILT
82 void
83 set_shared()
84 { this->is_shared_ = true; }
85
bae7f79e
ILT
86 void
87 set_static()
88 { this->is_static_ = true; }
89
90 Dir_list search_path_;
61ba1cf9 91 const char* output_file_name_;
bae7f79e 92 bool is_relocatable_;
92e059d8 93 bool is_shared_;
bae7f79e
ILT
94 bool is_static_;
95
96 // Don't copy this structure.
97 General_options(const General_options&);
98 General_options& operator=(const General_options&);
99};
100
101// The current state of the position dependent options.
102
103class Position_dependent_options
104{
105 public:
106 Position_dependent_options();
107
108 // -Bstatic: Whether we are searching for a static archive rather
109 // -than a shared object.
110 bool
111 do_static_search()
112 { return this->do_static_search_; }
113
114 private:
115 friend class Command_line;
116 friend class options::Command_line_options;
117
118 void
119 set_static_search()
120 { this->do_static_search_ = true; }
121
122 void
123 set_dynamic_search()
124 { this->do_static_search_ = false; }
125
126 bool do_static_search_;
127};
128
129// A single file or library argument from the command line.
130
131class Input_argument
132{
133 public:
61ba1cf9
ILT
134 Input_argument(const char* name, bool is_lib,
135 const Position_dependent_options& options)
136 : name_(name), is_lib_(is_lib), options_(options)
bae7f79e
ILT
137 { }
138
139 const char*
140 name() const
141 { return this->name_; }
142
143 const Position_dependent_options&
144 options() const
145 { return this->options_; }
146
147 bool
148 is_lib() const
61ba1cf9 149 { return this->is_lib_; }
bae7f79e
ILT
150
151 private:
152 const char* name_;
61ba1cf9 153 bool is_lib_;
bae7f79e
ILT
154 Position_dependent_options options_;
155};
156
92e059d8
ILT
157// A list of input files.
158class Input_argument_list : public std::vector<Input_argument>
159{
160};
161
bae7f79e
ILT
162// All the information read from the command line.
163
164class Command_line
165{
166 public:
167 Command_line();
168
169 // Process the command line options. This will exit with an
170 // appropriate error message if an unrecognized option is seen.
171 void
172 process(int argc, char** argv);
173
61ba1cf9
ILT
174 // Handle a -l option.
175 int
176 process_l_option(int, char**, char*);
177
178 // Get the general options.
bae7f79e
ILT
179 const General_options&
180 options() const
181 { return this->options_; }
182
61ba1cf9 183 // Get the list of input files.
bae7f79e
ILT
184 const Input_argument_list&
185 inputs() const
186 { return this->inputs_; }
187
188 private:
189 void usage() ATTRIBUTE_NORETURN;
190 void usage(const char* msg, const char* opt) ATTRIBUTE_NORETURN;
191 void usage(const char* msg, char opt) ATTRIBUTE_NORETURN;
192 void apply_option(const gold::options::One_option&, const char*);
193
194 General_options options_;
195 Position_dependent_options position_options_;
196 Input_argument_list inputs_;
197};
198
199} // End namespace gold.
200
201#endif // !defined(GOLD_OPTIONS_H)
This page took 0.036207 seconds and 4 git commands to generate.