Finished layout code.
[binutils.git] / gold / options.h
blob6ac1ab9c1e052e73ccd89f70872fab9e5195df75
1 // options.h -- handle command line options for gold -*- C++ -*-
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.
12 #ifndef GOLD_OPTIONS_H
13 #define GOLD_OPTIONS_H
15 #include <list>
17 namespace gold
20 class Command_line;
22 namespace options {
24 class Command_line_options;
25 struct One_option;
27 } // End namespace gold::options.
29 // The position independent options which apply to the whole link.
30 // There are a lot of them.
32 class General_options
34 public:
35 General_options();
37 // -L: Library search path.
38 typedef std::list<const char*> Dir_list;
40 const Dir_list&
41 search_path() const
42 { return this->search_path_; }
44 // -r: Whether we are doing a relocatable link.
45 bool
46 is_relocatable() const
47 { return this->is_relocatable_; }
49 // --static: Whether doing a static link.
50 bool
51 is_static() const
52 { return this->is_static_; }
54 private:
55 friend class Command_line;
56 friend class options::Command_line_options;
58 void
59 add_to_search_path(const char* arg)
60 { this->search_path_.push_back(arg); }
62 void
63 set_relocatable()
64 { this->is_relocatable_ = true; }
66 void
67 set_static()
68 { this->is_static_ = true; }
70 Dir_list search_path_;
71 bool is_relocatable_;
72 bool is_static_;
74 // Don't copy this structure.
75 General_options(const General_options&);
76 General_options& operator=(const General_options&);
79 // The current state of the position dependent options.
81 class Position_dependent_options
83 public:
84 Position_dependent_options();
86 // -Bstatic: Whether we are searching for a static archive rather
87 // -than a shared object.
88 bool
89 do_static_search()
90 { return this->do_static_search_; }
92 private:
93 friend class Command_line;
94 friend class options::Command_line_options;
96 void
97 set_static_search()
98 { this->do_static_search_ = true; }
100 void
101 set_dynamic_search()
102 { this->do_static_search_ = false; }
104 bool do_static_search_;
107 // A single file or library argument from the command line.
109 class Input_argument
111 public:
112 Input_argument(const char* name, const Position_dependent_options& options)
113 : name_(name), options_(options)
116 const char*
117 name() const
118 { return this->name_; }
120 const Position_dependent_options&
121 options() const
122 { return this->options_; }
124 bool
125 is_lib() const
126 { return this->name_[0] == '-' && this->name_[1] == 'l'; }
128 const char*
129 lib_basename() const
130 { return this->name_ + 2; }
132 private:
133 const char* name_;
134 Position_dependent_options options_;
137 // All the information read from the command line.
139 class Command_line
141 public:
142 Command_line();
144 // Process the command line options. This will exit with an
145 // appropriate error message if an unrecognized option is seen.
146 void
147 process(int argc, char** argv);
149 const General_options&
150 options() const
151 { return this->options_; }
153 typedef std::list<Input_argument> Input_argument_list;
155 const Input_argument_list&
156 inputs() const
157 { return this->inputs_; }
159 private:
160 void usage() ATTRIBUTE_NORETURN;
161 void usage(const char* msg, const char* opt) ATTRIBUTE_NORETURN;
162 void usage(const char* msg, char opt) ATTRIBUTE_NORETURN;
163 void apply_option(const gold::options::One_option&, const char*);
165 General_options options_;
166 Position_dependent_options position_options_;
167 Input_argument_list inputs_;
170 } // End namespace gold.
172 #endif // !defined(GOLD_OPTIONS_H)