New drop, with first cut of section layout code.
[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
17 namespace gold
18 {
19
20 class Command_line;
21
22 namespace options {
23
24 class Command_line_options;
25 struct One_option;
26
27 } // End namespace gold::options.
28
29 // The position independent options which apply to the whole link.
30 // There are a lot of them.
31
32 class General_options
33 {
34  public:
35   General_options();
36
37   // -L: Library search path.
38   typedef std::list<const char*> Dir_list;
39
40   const Dir_list&
41   search_path() const
42   { return this->search_path_; }
43
44   // -r: Whether we are doing a relocatable link.
45   bool
46   is_relocatable() const
47   { return this->is_relocatable_; }
48
49   // --static: Whether doing a static link.
50   bool
51   is_static() const
52   { return this->is_static_; }
53
54  private:
55   friend class Command_line;
56   friend class options::Command_line_options;
57
58   void
59   add_to_search_path(const char* arg)
60   { this->search_path_.push_back(arg); }
61
62   void
63   set_relocatable()
64   { this->is_relocatable_ = true; }
65
66   void
67   set_static()
68   { this->is_static_ = true; }
69
70   Dir_list search_path_;
71   bool is_relocatable_;
72   bool is_static_;
73
74   // Don't copy this structure.
75   General_options(const General_options&);
76   General_options& operator=(const General_options&);
77 };
78
79 // The current state of the position dependent options.
80
81 class Position_dependent_options
82 {
83  public:
84   Position_dependent_options();
85
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_; }
91
92  private:
93   friend class Command_line;
94   friend class options::Command_line_options;
95
96   void
97   set_static_search()
98   { this->do_static_search_ = true; }
99
100   void
101   set_dynamic_search()
102   { this->do_static_search_ = false; }
103
104   bool do_static_search_;
105 };
106
107 // A single file or library argument from the command line.
108
109 class Input_argument
110 {
111  public:
112   Input_argument(const char* name, const Position_dependent_options& options)
113     : name_(name), options_(options)
114   { }
115
116   const char*
117   name() const
118   { return this->name_; }
119
120   const Position_dependent_options&
121   options() const
122   { return this->options_; }
123
124   bool
125   is_lib() const
126   { return this->name_[0] == '-' && this->name_[1] == 'l'; }
127
128   const char*
129   lib_basename() const
130   { return this->name_ + 2; }
131
132  private:
133   const char* name_;
134   Position_dependent_options options_;
135 };
136
137 // All the information read from the command line.
138
139 class Command_line
140 {
141  public:
142   Command_line();
143
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);
148
149   const General_options&
150   options() const
151   { return this->options_; }
152
153   typedef std::list<Input_argument> Input_argument_list;
154
155   const Input_argument_list&
156   inputs() const
157   { return this->inputs_; }
158
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*);
164
165   General_options options_;
166   Position_dependent_options position_options_;
167   Input_argument_list inputs_;
168 };
169
170 } // End namespace gold.
171
172 #endif // !defined(GOLD_OPTIONS_H)