------------------------------------------------ -------------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A -- -- -- -- B o d y -- -- -- -- Copyright (C) 2005-2007, 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 Namet; with Errors; with Ocarina.Nutils; with Ocarina.AADL_Values; use Ocarina.AADL_Values; with Ada.Command_Line; with Output; use Output; with GNAT.OS_Lib; use GNAT.OS_Lib; with GNAT.Case_Util; use GNAT.Case_Util; package body Ocarina is ---------------- -- Initialize -- ---------------- procedure Initialize is use Namet; begin Namet.Initialize; Errors.Initialize; V_Zero := New_Integer_Value (0); V_One := New_Integer_Value (1); end Initialize; ----------- -- Reset -- ----------- procedure Reset is begin Namet.Initialize; Errors.Initialize; Ocarina.Nutils.Reset_Nodes; Ocarina.AADL_Values.Reset; end Reset; -------------------------------- -- Get_Installation_Directory -- -------------------------------- function Get_Installation_Directory (Suffix : String := "") return String is function Get_Install_Dir (Exec : String) return String; -- Exec is the executable name preceeded 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 Skept_Executable_Name : Boolean := False; Last : Integer; begin for J in reverse Exec'Range loop if Exec (J) = Directory_Separator then if J < Exec'Last - 5 then if To_Lower (Exec (J + 1)) = 'b' and then To_Lower (Exec (J + 2)) = 'i' and then To_Lower (Exec (J + 3)) = 'n' then -- Do not append the directory separator only if -- Suffix is not the empty string. if Suffix = "" then Last := J - 1; else Last := J; end if; return Exec (Exec'First .. Last) & Suffix; elsif not Skept_Executable_Name then Skept_Executable_Name := True; else exit; end if; end if; end if; end loop; return ""; end Get_Install_Dir; Exec_Name : constant String := Normalize_Pathname (Ada.Command_Line.Command_Name); begin -- First determine if a path prefix was placed in front of the -- executable name. for J in reverse Exec_Name'Range loop if Exec_Name (J) = Directory_Separator then declare Dir : constant String := Get_Install_Dir (Exec_Name); begin if Dir /= "" then return Dir; end if; end; end if; end loop; -- If we come here, the user has typed the executable name with no -- directory prefix. declare Dir : constant String := Get_Install_Dir (GNAT.OS_Lib.Locate_Exec_On_Path (Ada.Command_Line.Command_Name).all); begin if Dir /= "" then return Dir; end if; end; -- The user is not using a typical installation, last chance is -- to check for the OCARINA_PATH environment variable. declare Ocarina_Directory_Ptr : String_Access := Getenv ("OCARINA_PATH"); Install_Directory : constant String := Normalize_Pathname (Ocarina_Directory_Ptr.all & Directory_Separator & Suffix); begin Free (Ocarina_Directory_Ptr); if Install_Directory = Suffix then Write_Str ("Cannot find Ocarina resource files, "); Write_Str ("please check your installation."); Write_Eol; OS_Exit (1); end if; if Install_Directory (Install_Directory'Last) = Directory_Separator then return Install_Directory ( Install_Directory'First .. Install_Directory'Last - 1); else return Install_Directory; end if; end; end Get_Installation_Directory; ------------------ -- GNU_Make_Cmd -- ------------------ function GNU_Make_Cmd return String is begin return GNU_Make_Ptr.all; end GNU_Make_Cmd; ---------------------- -- Default_GNU_Make -- ---------------------- function Default_GNU_Make return String is begin return "make"; end Default_GNU_Make; end Ocarina;