Commit | Line | Data |
---|---|---|
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> | |
16 | ||
17 | #include "gold.h" | |
18 | ||
19 | namespace gold | |
20 | { | |
21 | ||
22 | class Command_line; | |
23 | ||
24 | namespace options { | |
25 | ||
26 | class Command_line_options; | |
27 | struct 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 | ||
34 | class 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 | ||
46 | // -r: Whether we are doing a relocatable link. | |
47 | bool | |
48 | is_relocatable() const | |
49 | { return this->is_relocatable_; } | |
50 | ||
51 | // --static: Whether doing a static link. | |
52 | bool | |
53 | is_static() const | |
54 | { return this->is_static_; } | |
55 | ||
56 | private: | |
57 | friend class Command_line; | |
58 | friend class options::Command_line_options; | |
59 | ||
60 | void | |
61 | add_to_search_path(const char* arg) | |
62 | { this->search_path_.push_back(arg); } | |
63 | ||
64 | void | |
65 | set_relocatable() | |
66 | { this->is_relocatable_ = true; } | |
67 | ||
68 | void | |
69 | set_static() | |
70 | { this->is_static_ = true; } | |
71 | ||
72 | Dir_list search_path_; | |
73 | bool is_relocatable_; | |
74 | bool is_static_; | |
75 | ||
76 | // Don't copy this structure. | |
77 | General_options(const General_options&); | |
78 | General_options& operator=(const General_options&); | |
79 | }; | |
80 | ||
81 | // The current state of the position dependent options. | |
82 | ||
83 | class Position_dependent_options | |
84 | { | |
85 | public: | |
86 | Position_dependent_options(); | |
87 | ||
88 | // -Bstatic: Whether we are searching for a static archive rather | |
89 | // -than a shared object. | |
90 | bool | |
91 | do_static_search() | |
92 | { return this->do_static_search_; } | |
93 | ||
94 | private: | |
95 | friend class Command_line; | |
96 | friend class options::Command_line_options; | |
97 | ||
98 | void | |
99 | set_static_search() | |
100 | { this->do_static_search_ = true; } | |
101 | ||
102 | void | |
103 | set_dynamic_search() | |
104 | { this->do_static_search_ = false; } | |
105 | ||
106 | bool do_static_search_; | |
107 | }; | |
108 | ||
109 | // A single file or library argument from the command line. | |
110 | ||
111 | class Input_argument | |
112 | { | |
113 | public: | |
114 | Input_argument(const char* name, const Position_dependent_options& options) | |
115 | : name_(name), options_(options) | |
116 | { } | |
117 | ||
118 | const char* | |
119 | name() const | |
120 | { return this->name_; } | |
121 | ||
122 | const Position_dependent_options& | |
123 | options() const | |
124 | { return this->options_; } | |
125 | ||
126 | bool | |
127 | is_lib() const | |
128 | { return this->name_[0] == '-' && this->name_[1] == 'l'; } | |
129 | ||
130 | const char* | |
131 | lib_basename() const | |
132 | { return this->name_ + 2; } | |
133 | ||
134 | private: | |
135 | const char* name_; | |
136 | Position_dependent_options options_; | |
137 | }; | |
138 | ||
139 | // All the information read from the command line. | |
140 | ||
141 | class Command_line | |
142 | { | |
143 | public: | |
144 | Command_line(); | |
145 | ||
146 | // Process the command line options. This will exit with an | |
147 | // appropriate error message if an unrecognized option is seen. | |
148 | void | |
149 | process(int argc, char** argv); | |
150 | ||
151 | const General_options& | |
152 | options() const | |
153 | { return this->options_; } | |
154 | ||
155 | typedef std::list<Input_argument> Input_argument_list; | |
156 | ||
157 | const Input_argument_list& | |
158 | inputs() const | |
159 | { return this->inputs_; } | |
160 | ||
161 | private: | |
162 | void usage() ATTRIBUTE_NORETURN; | |
163 | void usage(const char* msg, const char* opt) ATTRIBUTE_NORETURN; | |
164 | void usage(const char* msg, char opt) ATTRIBUTE_NORETURN; | |
165 | void apply_option(const gold::options::One_option&, const char*); | |
166 | ||
167 | General_options options_; | |
168 | Position_dependent_options position_options_; | |
169 | Input_argument_list inputs_; | |
170 | }; | |
171 | ||
172 | } // End namespace gold. | |
173 | ||
174 | #endif // !defined(GOLD_OPTIONS_H) |