Full support for --sysroot.
[external/binutils.git] / gold / parameters.h
1 // parameters.h -- general parameters for a link using gold  -*- C++ -*-
2
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
5
6 // This file is part of gold.
7
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
22
23 #ifndef GOLD_PARAMETERS_H
24 #define GOLD_PARAMETERS_H
25
26 namespace gold
27 {
28
29 class General_options;
30
31 // Here we define the Parameters class which simply holds simple
32 // general parameters which apply to the entire link.  We use a global
33 // variable for this.  This is in contrast to the General_options
34 // class, which holds the complete state of position independent
35 // command line options.  The hope is that Parameters will stay fairly
36 // simple, so that if this turns into a library it will be clear how
37 // these parameters should be set.
38
39 class Parameters
40 {
41  public:
42   Parameters(const General_options*);
43
44   // Whether we are generating a regular executable.
45   bool
46   output_is_executable() const
47   { return this->output_file_type_ == OUTPUT_EXECUTABLE; }
48
49   // Whether we are generating a shared library.
50   bool
51   output_is_shared() const
52   { return this->output_file_type_ == OUTPUT_SHARED; }
53
54   // Whether we are generating an object file.
55   bool
56   output_is_object() const
57   { return this->output_file_type_ == OUTPUT_OBJECT; }
58
59   // The target system root directory.  This is NULL if there isn't
60   // one.
61   const std::string&
62   sysroot() const
63   { return this->sysroot_; }
64
65   // Whether we are doing a static link--a link in which none of the
66   // input files are shared libraries.  This is only known after we
67   // have seen all the input files.
68   bool
69   doing_static_link() const
70   {
71     gold_assert(this->is_doing_static_link_valid_);
72     return this->doing_static_link_;
73   }
74
75   // The size of the output file we are generating.  This should
76   // return 32 or 64.
77   int
78   get_size() const
79   {
80     gold_assert(this->is_size_and_endian_valid_);
81     return this->size_;
82   }
83
84   // Whether the output is big endian.
85   bool
86   is_big_endian() const
87   {
88     gold_assert(this->is_size_and_endian_valid_);
89     return this->is_big_endian_;
90   }
91
92   // The general linker optimization level.
93   int
94   optimization_level() const
95   { return this->optimization_level_; }
96
97   // Set whether we are doing a static link.
98   void
99   set_doing_static_link(bool doing_static_link);
100
101   // Set the size and endianness.
102   void
103   set_size_and_endianness(int size, bool is_big_endian);
104
105  private:
106   // The types of output files.
107   enum Output_file_type
108     {
109       // Generating executable.
110       OUTPUT_EXECUTABLE,
111       // Generating shared library.
112       OUTPUT_SHARED,
113       // Generating object file.
114       OUTPUT_OBJECT
115     };
116
117   // The type of the output file.
118   Output_file_type output_file_type_;
119   // The target system root directory.
120   std::string sysroot_;
121   
122   // Whether the doing_static_link_ field is valid.
123   bool is_doing_static_link_valid_;
124   // Whether we are doing a static link.
125   bool doing_static_link_;
126   // Whether the size_ and is_big_endian_ fields are valid.
127   bool is_size_and_endian_valid_;
128   // The size of the output file--32 or 64.
129   int size_;
130   // Whether the output file is big endian.
131   bool is_big_endian_;
132   // The optimization level.
133   int optimization_level_;
134 };
135
136 // This is a global variable.
137 extern const Parameters* parameters;
138
139 // Initialize the global variable.
140 extern void initialize_parameters(const General_options*);
141
142 // Set the size and endianness of the global parameters variable.
143 extern void set_parameters_size_and_endianness(int size, bool is_big_endian);
144
145 // Set whether we are doing a static link.
146 extern void set_parameters_doing_static_link(bool doing_static_link);
147
148 } // End namespace gold.
149
150 #endif // !defined(GOLD_PARAMATERS_H)