ocarina-configuration.adb.in 9.53 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--                O C A R I N A . C O N F I G U R A T I O N                 --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--               Copyright (C) 2006-2009, GET-Telecom Paris.                --
--                                                                          --
-- Ocarina  is free software;  you  can  redistribute  it and/or  modify    --
-- it under terms of the GNU General Public License as published by the     --
-- Free Software Foundation; either version 2, or (at your option) any      --
-- later version. Ocarina is distributed  in  the  hope  that it will be    --
-- useful, but WITHOUT ANY WARRANTY;  without even the implied warranty of  --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received  a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING.   --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA.                                       --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable to be   --
-- covered  by the  GNU  General  Public  License. This exception does not  --
-- however invalidate  any other reasons why the executable file might be   --
-- covered by the GNU Public License.                                       --
--                                                                          --
--                 Ocarina is maintained by the Ocarina team                --
--                       (ocarina-users@listes.enst.fr)                     --
--                                                                          --
------------------------------------------------------------------------------

with Ocarina.Backends;
with Ocarina.BE_AADL;
with Ocarina.BE_AADL_BA;
with Ocarina.BE_REAL;
with Ocarina.Transfo;
with Ocarina.Transfo.Fusions;

with Ocarina.FE_REAL;
with Ocarina.FE_AADL;
with Ocarina.FE_AADL_BA;

with Ocarina.Analyzer;

with Ocarina.Options;  use Ocarina.Options;
with Ocarina.Parser;   use Ocarina.Parser;

with GNAT.OS_Lib;      use GNAT.OS_Lib;

with Ada.Command_Line; use Ada.Command_Line;

with Charset; use Charset;
with Namet;   use Namet;
with Types;   use Types;

package body Ocarina.Configuration is

   --  As some of the values of the constants below may make the lines
   --  too long for GNAT styles, we put the litterals in a new line.

   Version          : constant String :=
     "@VERSION@";
   --  This is the official version of Ocarina Stored in configure.ac

   Default_AADL_Version : constant AADL_Version_Type :=
     @AADL_VERSION@;

   pragma Style_Checks (Off);
   SVN_Revision : constant String := "Working Copy from @SVN_REVISION@";
   pragma Style_Checks (On);
   --  We keep the repository version as "(Working Copy) from ..." to
   --  distinguish modified versions. When packaging Ocarina, we
   --  delete the "Working Copy from" substring. The variable
   --  declaration must be done in one single line in order for the
   --  substitution pattern to work. We disable style checks because
   --  this line may be too long.

   Last_Config_Date : constant String :=
     "@LAST_CONFIG_DATE@";
   --  The date of the latest execution of the configure script

   Last_Config_Year : constant String :=
     "@LAST_CONFIG_YEAR@";
   --  The year of the latest execution of the configure script

   GNU_Make_Str : constant String :=
     "@GNU_MAKE@";
   --  The GNU make command

   ------------------------------
   -- Get_Default_AADL_Version --
   ------------------------------

   function Get_Default_AADL_Version return AADL_Version_Type is
   begin
      return Default_AADL_Version;
   end Get_Default_AADL_Version;

   ------------------
   -- Init_Modules --
   ------------------

   procedure Init_Modules is

      function Get_Install_Dir (Exec : String) return String;
      --  S is the executable name preceded by the absolute or relative
      --  path, e.g. "c:\usr\bin\gcc.exe" or "..\bin\gcc".

      ---------------------
      -- Get_Install_Dir --
      ---------------------

      function Get_Install_Dir (Exec : String) return String is
         Path : constant String := Normalize_Pathname (Exec);

      begin
         for J in reverse Path'Range loop
            if Path (J) = Directory_Separator then
               if J < Path'Last - 6 then
                  if To_Lower (Path (J + 1)) = 'b'
                    and then To_Lower (Path (J + 2)) = 'i'
                    and then To_Lower (Path (J + 3)) = 'n'
                    and then To_Lower (Path (J + 4)) = Directory_Separator
                  then
                     return Path (Path'First .. J);
                  end if;
               end if;
            end if;
         end loop;

         return "";
      end Get_Install_Dir;

      Exec : constant String := Normalize_Pathname (Command_Name);

   begin
      Set_Str_To_Name_Buffer ("");

      --  First check whether OCARINA_PATH is set.

      declare
         Path : constant String_Access := Getenv ("OCARINA_PATH");
      begin
         if Path /= null and then Path'Length > 0 then
            declare
               Dir : constant String
                 := Normalize_Pathname (Path.all) & Directory_Separator;
            begin
               if Dir'Length > 0 then
152
153
154
155
                  --  XXX disabled for now, to be investigated
                  --  if not Is_Regular_File (Dir & "bin/" & Command_Name) then
                  --  raise Program_Error with "Wrong value for OCARINA_PATH";
                  --  end if;
156

157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
                  Set_Str_To_Name_Buffer (Dir);
                  Installation_Directory := Name_Find;
               end if;
            end;
         end if;
      end;

      --  Determine if a path prefix was placed in front of the
      --  executable name.

      if Installation_Directory = No_Name then
         for J in reverse Exec'Range loop
            if Exec (J) = Directory_Separator then
               declare
                  Dir : constant String := Get_Install_Dir (Exec);
               begin
173
174
175
                  if Dir'Length > 0
                    and then Is_Regular_File (Dir & "bin/" & Command_Name)
                  then
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
                     Set_Str_To_Name_Buffer (Dir);
                     Installation_Directory := Name_Find;
                  end if;
                  exit;
               end;
            end if;
         end loop;
      end if;

      --  The executable name has no path prefix. Locate executable
      --  and use its path prefix.

      if Installation_Directory = No_Name then
         declare
            Dir : constant String
              := Get_Install_Dir (Locate_Exec_On_Path (Command_Name).all);
         begin
            if Dir'Length > 0 then
               Set_Str_To_Name_Buffer (Dir);
               Installation_Directory := Name_Find;
            end if;
         end;
      end if;

      if Installation_Directory = No_Name then
         raise Program_Error;
      end if;

      Ocarina.Backends.Init;
      Ocarina.Analyzer.Init_Analyzers;
      Ocarina.FE_AADL.Init;
      Ocarina.FE_AADL_BA.Init;
      Ocarina.FE_REAL.Init;
      Ocarina.BE_AADL.Init;
      Ocarina.BE_AADL_BA.Init;
      Ocarina.BE_REAL.Init;
      Ocarina.Transfo.Init;
      Ocarina.Transfo.Fusions.Init;

      Ocarina.Parser.Init_Parsers;

      --  Set the platform dependant GNU make executable name

      GNU_Make_Ptr := GNU_Make_Cmd'Access;
   end Init_Modules;

   -------------------
   -- Reset_Modules --
   -------------------

   procedure Reset_Modules is
   begin
      Installation_Directory := No_Name;
      Ocarina.FE_AADL.Reset;
      Ocarina.FE_AADL_BA.Reset;
      Ocarina.FE_REAL.Reset;
      Ocarina.Parser.Reset_Parsers;
      Ocarina.Analyzer.Reset_Analyzers;
      Ocarina.Backends.Reset;
      Ocarina.Transfo.Fusions.Reset;
   end Reset_Modules;

   ---------------------
   -- Ocarina_Version --
   ---------------------

   function Ocarina_Version return String is
   begin
      return Version;
   end Ocarina_Version;

   --------------------------
   -- Ocarina_SVN_Revision --
   --------------------------

   function Ocarina_SVN_Revision return String is
   begin
      return SVN_Revision;
   end Ocarina_SVN_Revision;

   ---------------------------------
   -- Ocarina_Last_Configure_Date --
   ---------------------------------

   function Ocarina_Last_Configure_Date return String is
   begin
      return Last_Config_Date;
   end Ocarina_Last_Configure_Date;

   ---------------------------------
   -- Ocarina_Last_Configure_Year --
   ---------------------------------

   function Ocarina_Last_Configure_Year return String is
   begin
      return Last_Config_Year;
   end Ocarina_Last_Configure_Year;

   ------------------
   -- GNU_Make_Cmd --
   ------------------

   function GNU_Make_Cmd return String is
   begin
      return GNU_Make_Str;
   end GNU_Make_Cmd;

end Ocarina.Configuration;