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