ocarina-configuration.adb.in 10.1 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           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                                  --
--                                                                          --
9
--    Copyright (C) 2006-2009 Telecom ParisTech, 2010-2020 ESA & ISAE.      --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. 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.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29
30
31
32
33
34
35
36
37
38
39
40
41
--                                                                          --
------------------------------------------------------------------------------

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;
42
43
with Ocarina.FE_AADL_EMA;
with Ocarina.FE_AO4AADL;
44
45
46
47
48
49

with Ocarina.Analyzer;

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

50
--  with GNAT.Compiler_Version;
51
with GNAT.OS_Lib;      use GNAT.OS_Lib;
52
with GNAT.Source_Info;
53
54
55
with Ada.Command_Line; use Ada.Command_Line;

with Charset; use Charset;
yoogx's avatar
yoogx committed
56
with Ocarina.Namet;   use Ocarina.Namet;
57
with Ocarina.Output;  use Ocarina.Output;
yoogx's avatar
yoogx committed
58
with Ocarina.Types;   use Ocarina.Types;
59
60
61
62
63
64

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.

65
   Ocarina_V : constant String := "@VERSION@";
66
67
68
69
70
71
   --  This is the official version of Ocarina Stored in configure.ac

   Default_AADL_Version : constant AADL_Version_Type :=
     @AADL_VERSION@;

   pragma Style_Checks (Off);
72
   SCM_Revision : constant String := "Working Copy from @SCM_REVISION@";
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
   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_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
149
150
151
152
                  --  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;
153

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
                  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
170
171
172
                  if Dir'Length > 0
                    and then Is_Regular_File (Dir & "bin/" & Command_Name)
                  then
173
174
175
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
                     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;
205
      Ocarina.FE_AADL_EMA.Init;
206
      Ocarina.FE_REAL.Init;
207
      Ocarina.FE_AO4AADL.Init;
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
      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;
230
      Ocarina.FE_AADL_EMA.Reset;
231
      Ocarina.FE_REAL.Reset;
232
      Ocarina.FE_AO4AADL.Reset;
233
234
235
236
237
238
239
240
241
242
243
244
      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
245
      return Ocarina_V;
246
247
   end Ocarina_Version;

248
   ----------------------
249
   -- Ocarina_Revision --
250
   -----------------------
251

252
   function Ocarina_Revision return String is
253
   begin
254
255
      return SCM_Revision;
   end Ocarina_Revision;
256
257
258
259
260
261
262

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

   function Ocarina_Last_Configure_Date return String is
   begin
263
264
      return GNAT.Source_Info.Compilation_Date & " "
        & GNAT.Source_Info.Compilation_Time;
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
   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;

285
286
287
288
289
   -------------
   -- Version --
   -------------

   procedure Version is
290
--      package Compiler_Version is new GNAT.Compiler_Version;
291
292
293
294
295
296
297
298
299

   begin
      Write_Line
        ("Ocarina " & Ocarina_Version & " (" & Ocarina_Revision & ")");
      Write_Line
        ("Copyright (c) 2003-2009 Telecom ParisTech, 2010-" &
         Ocarina_Last_Configure_Year &
         " ESA & ISAE");
      Write_Line ("Build date: " & Ocarina_Last_Configure_Date);
300
--      Write_Line ("Compiled with: " & Compiler_Version.Version);
301
302
   end Version;

303
end Ocarina.Configuration;