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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
------------------------------------------------------------------------------
-- --
-- ASIS UTILITY LIBRARY COMPONENTS --
-- --
-- A S I S _ U L . C O M M O N --
-- --
-- B o d y --
-- --
-- Copyright (C) 2004-2015, AdaCore --
-- --
-- Asis Utility Library (ASIS UL) 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 3, or (at your --
-- option) any later version. ASIS UL 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 GNAT; see file --
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
-- of the license. --
-- --
-- GNATCHECK is maintained by AdaCore (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
pragma Ada_2012;
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with GNAT.Directory_Operations;
with ASIS_UL.Output; use ASIS_UL.Output;
with ASIS_UL.Compiler_Options; use ASIS_UL.Compiler_Options;
package body ASIS_UL.Common is
-----------------------
-- Local subprograms --
-----------------------
procedure Set_Tool_Name_And_Path;
-- Reads the tool name from the command line and sets Tool_Name. If the
-- tool name contains directory information, adds the directory to the
-- path.
Global_Report_Dir : String_Access := new String'("." & Directory_Separator);
-- The name of the directory to place the global results into
-------------------
-- Detect_Target --
-------------------
function Detect_Target return String is
use GNAT.Directory_Operations;
Tgt_Last : constant Natural :=
Index (Tool_Name.all, "-", Ada.Strings.Backward);
AAMP_Idx : constant Natural := Index (Tool_Name.all, "gnaamp");
begin
if AAMP_Idx = Tool_Name'First then
return "AAMP";
elsif Tgt_Last > 0 then
return Tool_Name (Tool_Name'First .. Tgt_Last);
else
return "";
end if;
exception
when others =>
return "";
end Detect_Target;
---------------------------
-- Get_Global_Report_Dir --
---------------------------
function Get_Global_Report_Dir return String is
begin
return Global_Report_Dir.all;
end Get_Global_Report_Dir;
--------------------------
-- Process_Project_File --
--------------------------
procedure Process_Project_File (Project_File_Name : String) is
begin
-- pragma Assert (False, "???Process_Project_File is not used");
if Is_Regular_File (Project_File_Name) then
Project_File := new String'(Normalize_Pathname (Project_File_Name));
if Project_Support_Type = No_Tmp_Project_File then
Store_Option ("-P" & Project_File.all);
end if;
else
Error ("the project file " & Project_File_Name & " not found");
raise Parameter_Error;
end if;
Gcc_To_Call := Gnatmake_To_Call;
if Gcc_To_Call /= null then
Use_Gnatmake_To_Compile := True;
else
Error ("can not locate gnatmake to compile with a project file");
raise Parameter_Error;
end if;
Use_Project_File := True;
end Process_Project_File;
---------------------------
-- Set_Global_Report_Dir --
---------------------------
procedure Set_Global_Report_Dir (Dir : String) is
begin
Free (Global_Report_Dir);
pragma Assert (Dir /= "");
Global_Report_Dir := new String'(Dir & Directory_Separator);
end Set_Global_Report_Dir;
-------------------
-- Set_Tool_Name --
-------------------
procedure Set_Tool_Name (To_This : String) is
begin
Free (Tool_Name);
Tool_Name := new String'(To_This);
end Set_Tool_Name;
----------------------------
-- Set_Tool_Name_And_Path --
----------------------------
procedure Set_Tool_Name_And_Path is
Full_Tool_Name : constant String := Ada.Command_Line.Command_Name;
Exe_Suffix : String_Access := Get_Executable_Suffix;
begin
Tool_Name :=
new String'(To_Lower
(GNAT.Directory_Operations.Base_Name
(Full_Tool_Name, Suffix => Exe_Suffix.all)));
for Index in reverse Full_Tool_Name'Range loop
if Full_Tool_Name (Index) = Directory_Separator then
declare
Absolute_Dir : constant String :=
Normalize_Pathname
(Full_Tool_Name
(Full_Tool_Name'First .. Index));
PATH : constant String :=
Absolute_Dir & Path_Separator & Getenv ("PATH").all;
begin
Setenv ("PATH", PATH);
end;
exit;
end if;
end loop;
Free (Exe_Suffix);
end Set_Tool_Name_And_Path;
begin
Set_Tool_Name_And_Path;
-- Detetermine the name of the executables for gcc, gnatmake, and gprbuild
declare
Target : constant String := Detect_Target;
Gcc_Name : constant String :=
(if Target = "AAMP" then "gnaamp" else Target & "gnatgcc");
Gnatmake_Name : constant String :=
(if Target = "AAMP" then "gnaampmake" else Target & "gnatmake");
pragma Unreferenced (Gnatmake_Name);
Gprbuild_Name : constant String := "gprbuild";
begin
Gcc_To_Call := Locate_Exec_On_Path (Gcc_Name);
Gprbuild_To_Call := Locate_Exec_On_Path (Gprbuild_Name);
Gnatmake_To_Call := Gprbuild_To_Call;
end;
end ASIS_UL.Common;
|