1------------------------------------------------------------------------------
2--                                                                          --
3--                            Matreshka Project                             --
4--                                                                          --
5--         Localization, Internationalization, Globalization for Ada        --
6--                                                                          --
7--                              Tools Component                             --
8--                                                                          --
9------------------------------------------------------------------------------
10--                                                                          --
11-- Copyright © 2010-2015, Vadim Godunko <vgodunko@gmail.com>                --
12-- All rights reserved.                                                     --
13--                                                                          --
14-- Redistribution and use in source and binary forms, with or without       --
15-- modification, are permitted provided that the following conditions       --
16-- are met:                                                                 --
17--                                                                          --
18--  * Redistributions of source code must retain the above copyright        --
19--    notice, this list of conditions and the following disclaimer.         --
20--                                                                          --
21--  * Redistributions in binary form must reproduce the above copyright     --
22--    notice, this list of conditions and the following disclaimer in the   --
23--    documentation and/or other materials provided with the distribution.  --
24--                                                                          --
25--  * Neither the name of the Vadim Godunko, IE nor the names of its        --
26--    contributors may be used to endorse or promote products derived from  --
27--    this software without specific prior written permission.              --
28--                                                                          --
29-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS      --
30-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT        --
31-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    --
32-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT     --
33-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   --
34-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
35-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR   --
36-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF   --
37-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     --
38-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS       --
39-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.             --
40--                                                                          --
41------------------------------------------------------------------------------
42--  $Revision: 5291 $ $Date: 2015-05-13 15:17:27 +0300 (Wed, 13 May 2015) $
43------------------------------------------------------------------------------
44with Ada.Command_Line;
45with Ada.Directories;
46with Ada.Strings.Unbounded.Text_IO;
47with Ada.Text_IO;
48
49with Configure.Architecture;
50with Configure.Instantiate;
51with Configure.Internals;
52with Configure.RTL_Version;
53with Configure.Tests.Asis;
54with Configure.Tests.Modules.AMF;
55with Configure.Tests.Gprbuild;
56with Configure.Tests.Install;
57with Configure.Tests.Installation_Directories;
58with Configure.Tests.MySQL;
59with Configure.Tests.OCI;
60with Configure.Tests.Operating_System;
61with Configure.Tests.PostgreSQL;
62with Configure.Tests.SQLite3;
63with Configure.Tests.Firebird;
64with Configure.Tests.Valgrind;
65with Configure.Version;
66
67procedure Configure.Driver is
68   use Ada.Command_Line;
69
70   function Is_Help_Requested return Boolean;
71   --  Returns True when help information is requested by the user.
72
73   procedure Help_Output (Position : Unbounded_String_Vectors.Cursor);
74   --  Outputs line of help information.
75
76   -----------------
77   -- Help_Output --
78   -----------------
79
80   procedure Help_Output (Position : Unbounded_String_Vectors.Cursor) is
81      Line : constant Unbounded_String
82        := Unbounded_String_Vectors.Element (Position);
83
84   begin
85      Ada.Strings.Unbounded.Text_IO.Put_Line (Line);
86   end Help_Output;
87
88   -----------------------
89   -- Is_Help_Requested --
90   -----------------------
91
92   function Is_Help_Requested return Boolean is
93   begin
94      for J in 1 .. Argument_Count loop
95         if Argument (J) = "--help" then
96            return True;
97         end if;
98      end loop;
99
100      return False;
101   end Is_Help_Requested;
102
103   Arguments       : Unbounded_String_Vector;
104   Operating_System_Test : aliased
105     Configure.Tests.Operating_System.Operating_System_Test;
106   Dirs_Test       :
107     Configure.Tests.Installation_Directories.Installation_Directories_Test;
108   Gprbuild_Test   : Configure.Tests.Gprbuild.Gprbuild_Test;
109   Install_Test    : Configure.Tests.Install.Install_Test;
110   Asis_Test       : Configure.Tests.Asis.Asis_Test;
111   AMF_Test        :
112     Configure.Tests.Modules.AMF.AMF_Test (Operating_System_Test'Access);
113   MySQL_Test      : Configure.Tests.MySQL.MySQL_Test;
114   OCI_Test        :
115     Configure.Tests.OCI.OCI_Test (Operating_System_Test'Access);
116   PostgreSQL_Test : Configure.Tests.PostgreSQL.PostgreSQL_Test;
117   SQLite3_Test    :
118     Configure.Tests.SQLite3.SQLite3_Test (Operating_System_Test'Access);
119   Firebird_Test   : Configure.Tests.Firebird.Firebird_Test;
120   Valgrind_Test   : Configure.Tests.Valgrind.Valgrind_Test;
121
122begin
123   if Is_Help_Requested then
124      Ada.Text_IO.Put_Line
125       ("`"
126          & Ada.Directories.Simple_Name (Command_Name)
127          & "' configures Matreshka to adapt to many kinds of systems.");
128      Ada.Text_IO.New_Line;
129      Ada.Text_IO.Put_Line ("Usage: " & Command_Name & " [OPTION]...");
130      Ada.Text_IO.New_Line;
131      Ada.Text_IO.Put_Line
132       ("Defaults for the options are specified in brackets.");
133      Ada.Text_IO.New_Line;
134      Ada.Text_IO.Put_Line ("Configuration:");
135      Ada.Text_IO.Put_Line
136       ("  --help                  display this help and exit");
137
138      Ada.Text_IO.New_Line;
139      Dirs_Test.Help.Iterate (Help_Output'Access);
140
141      Ada.Text_IO.New_Line;
142      Ada.Text_IO.Put_Line ("Modules:");
143
144      AMF_Test.Help.Iterate (Help_Output'Access);
145
146      Ada.Text_IO.New_Line;
147      Ada.Text_IO.Put_Line ("Optional Packages:");
148
149      OCI_Test.Help.Iterate (Help_Output'Access);
150      PostgreSQL_Test.Help.Iterate (Help_Output'Access);
151      SQLite3_Test.Help.Iterate (Help_Output'Access);
152      Firebird_Test.Help.Iterate (Help_Output'Access);
153
154      return;
155   end if;
156
157   --  Create log file.
158
159   Configure.Internals.Create_Log_File;
160
161   --  Convert command line arguments into the vector.
162
163   for J in 1 .. Ada.Command_Line.Argument_Count loop
164      Arguments.Append (+Ada.Command_Line.Argument (J));
165   end loop;
166
167   Configure.Version;
168   Configure.Architecture;
169   Operating_System_Test.Execute (Arguments);
170   Configure.RTL_Version;
171   Dirs_Test.Execute (Arguments);
172   Install_Test.Execute (Arguments);
173   Gprbuild_Test.Execute (Arguments);
174   Asis_Test.Execute (Arguments);
175   AMF_Test.Execute (Arguments);
176   MySQL_Test.Execute (Arguments);
177   OCI_Test.Execute (Arguments);
178   PostgreSQL_Test.Execute (Arguments);
179   SQLite3_Test.Execute (Arguments);
180   Firebird_Test.Execute (Arguments);
181   Valgrind_Test.Execute (Arguments);
182
183   declare
184      use Ada.Directories;
185      use Ada.Strings.Unbounded.Text_IO;
186      use Ada.Text_IO;
187      use Maps;
188
189      P : Cursor := Substitutions.First;
190
191   begin
192      while Has_Element (P) loop
193         Put (Simple_Name (Command_Name));
194         Put (": ");
195         Put (Key (P));
196         Put (" => ");
197         Put (Element (P));
198         New_Line;
199
200         Next (P);
201      end loop;
202   end;
203
204   --  Check whether all arguments in the command line are recognized and
205   --  removed.
206
207   if not Arguments.Is_Empty then
208      declare
209         procedure Output (Position : Unbounded_String_Vectors.Cursor);
210
211         ------------
212         -- Output --
213         ------------
214
215         procedure Output (Position : Unbounded_String_Vectors.Cursor) is
216            Arg : constant Unbounded_String
217              := Unbounded_String_Vectors.Element (Position);
218
219         begin
220            Warning
221             ("command line argument '" & (+Arg) & "' is not recognized");
222         end Output;
223
224      begin
225         Arguments.Iterate (Output'Access);
226      end;
227   end if;
228
229   Configure.Instantiate ("Makefile.config");
230   Configure.Instantiate ("gnat/install/matreshka_config.gpr");
231   Configure.Instantiate ("gnat/matreshka_config.gpr");
232   Configure.Instantiate ("source/league/matreshka-config.ads");
233
234   --  Close log file.
235
236   Configure.Internals.Close_Log_File;
237
238exception
239   when Internal_Error =>
240      Set_Exit_Status (Failure);
241end Configure.Driver;
242