Commit 41c8951a by Vincent Celier Committed by Arnaud Charlet

re PR ada/4720 (GNAT programs do not support --help and --version)

2007-08-30  Vincent Celier  <celier@adacore.com>

	PR ada/4720

	* gnatchop.adb, gnatfind.adb, gnatlink.adb, gnatls.adb, 
	gnatname.adb, gnatxref.adb, gprep.adb, clean.adb gnatbind.adb
	(Check_Version_And_Help): New procedure in package Switch to process
	switches --version and --help.
	Use Check_Version_And_Help in GNAT tools

	* make.adb:  Ditto.
	(Compile_Sources): Make sure that sources that are "excluded" are not
	compiled.
	(Gnatmake): Do not issue -aO. to gnatbind and only issue -I- if a
	project file is used.
	(Version_Switch): Remove, moved to Switch
	(Help_Switch): Remove, moved to Switch
	(Display_Version): Remove, moved to Switch

	* switch.ads, switch.adb (Check_Version_And_Help): New procedure in
	package Switch to process switches --version and --help.
	(Display_Version): New procedure

	* gnatvsn.ads, gnatvsn.adb (Copyright_Holder): New function.

From-SVN: r127967
parent c66bc9cc
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
with ALI; use ALI; with ALI; use ALI;
with Csets; with Csets;
with Gnatvsn; use Gnatvsn;
with Makeutl; with Makeutl;
with MLib.Tgt; use MLib.Tgt; with MLib.Tgt; use MLib.Tgt;
with Namet; use Namet; with Namet; use Namet;
...@@ -39,6 +38,7 @@ with Prj.Ext; ...@@ -39,6 +38,7 @@ with Prj.Ext;
with Prj.Pars; with Prj.Pars;
with Prj.Util; use Prj.Util; with Prj.Util; use Prj.Util;
with Snames; with Snames;
with Switch; use Switch;
with Table; with Table;
with Targparm; use Targparm; with Targparm; use Targparm;
with Types; use Types; with Types; use Types;
...@@ -1342,11 +1342,7 @@ package body Clean is ...@@ -1342,11 +1342,7 @@ package body Clean is
begin begin
if not Copyright_Displayed then if not Copyright_Displayed then
Copyright_Displayed := True; Copyright_Displayed := True;
Put_Line Display_Version ("GNATCLEAN", "2003");
("GNATCLEAN " & Gnatvsn.Gnat_Version_String
& " Copyright 2003-"
& Current_Year
& " Free Software Foundation, Inc.");
end if; end if;
end Display_Copyright; end Display_Copyright;
...@@ -1640,9 +1636,14 @@ package body Clean is ...@@ -1640,9 +1636,14 @@ package body Clean is
procedure Parse_Cmd_Line is procedure Parse_Cmd_Line is
Last : constant Natural := Argument_Count; Last : constant Natural := Argument_Count;
Source_Index : Int := 0; Source_Index : Int := 0;
Index : Positive := 1; Index : Positive;
begin begin
-- First, check for --version and --help
Check_Version_And_Help ("GNATCLEAN", "2003", Usage'Access);
Index := 1;
while Index <= Last loop while Index <= Last loop
declare declare
Arg : constant String := Argument (Index); Arg : constant String := Argument (Index);
......
...@@ -37,7 +37,6 @@ with Csets; ...@@ -37,7 +37,6 @@ with Csets;
with Debug; use Debug; with Debug; use Debug;
with Fmap; with Fmap;
with Fname; use Fname; with Fname; use Fname;
with Gnatvsn; use Gnatvsn;
with Namet; use Namet; with Namet; use Namet;
with Opt; use Opt; with Opt; use Opt;
with Osint; use Osint; with Osint; use Osint;
...@@ -423,6 +422,12 @@ begin ...@@ -423,6 +422,12 @@ begin
Shared_Libgnat := (Shared_Libgnat_Default = SHARED); Shared_Libgnat := (Shared_Libgnat_Default = SHARED);
end; end;
-- Scan the switches and arguments
-- First, scan to detect --version and/or --help
Check_Version_And_Help ("GNATBIND", "1995", Bindusg.Display'Access);
-- Use low level argument routines to avoid dragging in the secondary stack -- Use low level argument routines to avoid dragging in the secondary stack
Next_Arg := 1; Next_Arg := 1;
...@@ -553,13 +558,7 @@ begin ...@@ -553,13 +558,7 @@ begin
if Verbose_Mode then if Verbose_Mode then
Write_Eol; Write_Eol;
Write_Str ("GNATBIND "); Display_Version ("GNATBIND", "1995");
Write_Str (Gnat_Version_String);
Write_Eol;
Write_Str ("Copyright 1995-" &
Current_Year &
", Free Software Foundation, Inc.");
Write_Eol;
end if; end if;
-- Output usage information if no files -- Output usage information if no files
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1998-2007, AdaCore -- -- Copyright (C) 1998-2007, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -36,8 +36,8 @@ with GNAT.OS_Lib; use GNAT.OS_Lib; ...@@ -36,8 +36,8 @@ with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Heap_Sort_G; with GNAT.Heap_Sort_G;
with GNAT.Table; with GNAT.Table;
with Gnatvsn;
with Hostparm; with Hostparm;
with Switch; use Switch;
with Types; with Types;
procedure Gnatchop is procedure Gnatchop is
...@@ -1158,14 +1158,7 @@ procedure Gnatchop is ...@@ -1158,14 +1158,7 @@ procedure Gnatchop is
when 'v' => when 'v' =>
Verbose_Mode := True; Verbose_Mode := True;
Display_Version ("GNATCHOP", "1998");
-- Why is following written to standard error. Most other
-- tools write to standard output ???
Put (Standard_Error, "GNATCHOP ");
Put_Line (Standard_Error, Gnatvsn.Gnat_Version_String);
Put_Line
(Standard_Error, "Copyright 1998-2005, AdaCore");
when 'w' => when 'w' =>
Overwrite_Files := True; Overwrite_Files := True;
...@@ -1767,6 +1760,10 @@ begin ...@@ -1767,6 +1760,10 @@ begin
-- Process command line options and initialize global variables -- Process command line options and initialize global variables
-- First, scan to detect --version and/or --help
Check_Version_And_Help ("GNATCHOP", "1998", Usage'Unrestricted_Access);
if not Scan_Arguments then if not Scan_Arguments then
Set_Exit_Status (Failure); Set_Exit_Status (Failure);
return; return;
......
...@@ -24,13 +24,12 @@ ...@@ -24,13 +24,12 @@
-- -- -- --
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
with Xr_Tabls; use Xr_Tabls; with Opt;
with Xref_Lib; use Xref_Lib;
with Osint; use Osint; with Osint; use Osint;
with Switch; use Switch;
with Types; use Types; with Types; use Types;
with Xr_Tabls; use Xr_Tabls;
with Gnatvsn; with Xref_Lib; use Xref_Lib;
with Opt;
with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Text_IO; use Ada.Text_IO;
...@@ -69,8 +68,11 @@ procedure Gnatfind is ...@@ -69,8 +68,11 @@ procedure Gnatfind is
procedure Parse_Cmd_Line; procedure Parse_Cmd_Line;
-- Parse every switch on the command line -- Parse every switch on the command line
procedure Usage;
-- Display the usage
procedure Write_Usage; procedure Write_Usage;
-- Print a small help page for program usage -- Print a small help page for program usage and exit program
-------------------- --------------------
-- Parse_Cmd_Line -- -- Parse_Cmd_Line --
...@@ -78,6 +80,14 @@ procedure Gnatfind is ...@@ -78,6 +80,14 @@ procedure Gnatfind is
procedure Parse_Cmd_Line is procedure Parse_Cmd_Line is
begin begin
-- First check for --version or --help
Check_Version_And_Help ("GNATFIND", "1998", Usage'Unrestricted_Access);
-- Now scan the other switches
GNAT.Command_Line.Initialize_Option_Scan;
loop loop
case case
GNAT.Command_Line.Getopt GNAT.Command_Line.Getopt
...@@ -232,14 +242,12 @@ procedure Gnatfind is ...@@ -232,14 +242,12 @@ procedure Gnatfind is
Write_Usage; Write_Usage;
end Parse_Cmd_Line; end Parse_Cmd_Line;
----------------- -----------
-- Write_Usage -- -- Usage --
----------------- -----------
procedure Write_Usage is procedure Usage is
begin begin
Put_Line ("GNATFIND " & Gnatvsn.Gnat_Version_String);
Put_Line ("Copyright 1998-2005, AdaCore");
Put_Line ("Usage: gnatfind pattern[:sourcefile[:line[:column]]] " Put_Line ("Usage: gnatfind pattern[:sourcefile[:line[:column]]] "
& "[file1 file2 ...]"); & "[file1 file2 ...]");
New_Line; New_Line;
...@@ -276,8 +284,19 @@ procedure Gnatfind is ...@@ -276,8 +284,19 @@ procedure Gnatfind is
& " only)"); & " only)");
Put_Line (" -s Print source line"); Put_Line (" -s Print source line");
Put_Line (" -t Print type hierarchy"); Put_Line (" -t Print type hierarchy");
end Usage;
-----------------
-- Write_Usage --
-----------------
procedure Write_Usage is
begin
Display_Version ("GNATFIND", "1998");
New_Line; New_Line;
Usage;
raise Usage_Error; raise Usage_Error;
end Write_Usage; end Write_Usage;
......
...@@ -205,6 +205,9 @@ procedure Gnatlink is ...@@ -205,6 +205,9 @@ procedure Gnatlink is
procedure Process_Binder_File (Name : String); procedure Process_Binder_File (Name : String);
-- Reads the binder file and extracts linker arguments -- Reads the binder file and extracts linker arguments
procedure Usage;
-- Display usage
procedure Write_Header; procedure Write_Header;
-- Show user the program name, version and copyright -- Show user the program name, version and copyright
...@@ -291,6 +294,10 @@ procedure Gnatlink is ...@@ -291,6 +294,10 @@ procedure Gnatlink is
-- linker's argument without parsing it. -- linker's argument without parsing it.
begin begin
-- First, check for --version and --help
Check_Version_And_Help ("GNATLINK", "1995", Usage'Unrestricted_Access);
-- Loop through arguments of gnatlink command -- Loop through arguments of gnatlink command
Next_Arg := 1; Next_Arg := 1;
...@@ -1329,32 +1336,12 @@ procedure Gnatlink is ...@@ -1329,32 +1336,12 @@ procedure Gnatlink is
Status := fclose (Fd); Status := fclose (Fd);
end Process_Binder_File; end Process_Binder_File;
------------------ -----------
-- Write_Header -- -- Usage --
------------------ -----------
procedure Write_Header is procedure Usage is
begin begin
if Verbose_Mode then
Write_Eol;
Write_Str ("GNATLINK ");
Write_Str (Gnat_Version_String);
Write_Eol;
Write_Str ("Copyright 1995-" &
Current_Year &
", Free Software Foundation, Inc");
Write_Eol;
end if;
end Write_Header;
-----------------
-- Write_Usage --
-----------------
procedure Write_Usage is
begin
Write_Header;
Write_Str ("Usage: "); Write_Str ("Usage: ");
Write_Str (Base_Name (Command_Name)); Write_Str (Base_Name (Command_Name));
Write_Str (" switches mainprog.ali [non-Ada-objects] [linker-options]"); Write_Str (" switches mainprog.ali [non-Ada-objects] [linker-options]");
...@@ -1385,6 +1372,28 @@ procedure Gnatlink is ...@@ -1385,6 +1372,28 @@ procedure Gnatlink is
Write_Eol; Write_Eol;
Write_Line (" [non-Ada-objects] list of non Ada object files"); Write_Line (" [non-Ada-objects] list of non Ada object files");
Write_Line (" [linker-options] other options for the linker"); Write_Line (" [linker-options] other options for the linker");
end Usage;
------------------
-- Write_Header --
------------------
procedure Write_Header is
begin
if Verbose_Mode then
Write_Eol;
Display_Version ("GNATLINK", "1995");
end if;
end Write_Header;
-----------------
-- Write_Usage --
-----------------
procedure Write_Usage is
begin
Write_Header;
Usage;
end Write_Usage; end Write_Usage;
-- Start of processing for Gnatlink -- Start of processing for Gnatlink
......
...@@ -40,6 +40,7 @@ with Output; use Output; ...@@ -40,6 +40,7 @@ with Output; use Output;
with Rident; use Rident; with Rident; use Rident;
with Sdefault; with Sdefault;
with Snames; with Snames;
with Switch; use Switch;
with Targparm; use Targparm; with Targparm; use Targparm;
with Types; use Types; with Types; use Types;
...@@ -1528,6 +1529,10 @@ begin ...@@ -1528,6 +1529,10 @@ begin
Csets.Initialize; Csets.Initialize;
Snames.Initialize; Snames.Initialize;
-- First check for --version or --help
Check_Version_And_Help ("GNATLS", "1997", Usage'Unrestricted_Access);
-- Loop to scan out arguments -- Loop to scan out arguments
Next_Arg := 1; Next_Arg := 1;
...@@ -1572,13 +1577,7 @@ begin ...@@ -1572,13 +1577,7 @@ begin
Targparm.Get_Target_Parameters; Targparm.Get_Target_Parameters;
Write_Eol; Write_Eol;
Write_Str ("GNATLS "); Display_Version ("GNATLS", "1997");
Write_Str (Gnat_Version_String);
Write_Eol;
Write_Str ("Copyright 1997-" &
Current_Year &
", Free Software Foundation, Inc.");
Write_Eol;
Write_Eol; Write_Eol;
Write_Str ("Source Search Path:"); Write_Str ("Source Search Path:");
Write_Eol; Write_Eol;
......
...@@ -24,12 +24,12 @@ ...@@ -24,12 +24,12 @@
-- -- -- --
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
with Gnatvsn; use Gnatvsn;
with Hostparm; with Hostparm;
with Opt; with Opt;
with Osint; use Osint; with Osint; use Osint;
with Output; use Output; with Output; use Output;
with Prj.Makr; with Prj.Makr;
with Switch; use Switch;
with Table; with Table;
with Ada.Command_Line; use Ada.Command_Line; with Ada.Command_Line; use Ada.Command_Line;
...@@ -169,12 +169,7 @@ procedure Gnatname is ...@@ -169,12 +169,7 @@ procedure Gnatname is
if not Version_Output then if not Version_Output then
Version_Output := True; Version_Output := True;
Output.Write_Eol; Output.Write_Eol;
Output.Write_Str ("GNATNAME "); Display_Version ("GNATNAME", "2001");
Output.Write_Line (Gnatvsn.Gnat_Version_String);
Output.Write_Line
("Copyright 2001-" &
Current_Year &
", Free Software Foundation, Inc.");
end if; end if;
end Output_Version; end Output_Version;
...@@ -184,6 +179,12 @@ procedure Gnatname is ...@@ -184,6 +179,12 @@ procedure Gnatname is
procedure Scan_Args is procedure Scan_Args is
begin begin
-- First check for --version or --help
Check_Version_And_Help ("GNATNAME", "2001", Usage'Unrestricted_Access);
-- Now scan the other switches
Initialize_Option_Scan; Initialize_Option_Scan;
-- Scan options first -- Scan options first
......
...@@ -33,6 +33,15 @@ ...@@ -33,6 +33,15 @@
package body Gnatvsn is package body Gnatvsn is
----------------------
-- Copyright_Holder --
----------------------
function Copyright_Holder return String is
begin
return "Free Software Foundation, Inc.";
end Copyright_Holder;
------------------------ ------------------------
-- Gnat_Free_Software -- -- Gnat_Free_Software --
------------------------ ------------------------
......
...@@ -68,6 +68,10 @@ package Gnatvsn is ...@@ -68,6 +68,10 @@ package Gnatvsn is
-- Text to be displayed by the different GNAT tools when switch --version -- Text to be displayed by the different GNAT tools when switch --version
-- is used. This text depends on the GNAT build type. -- is used. This text depends on the GNAT build type.
function Copyright_Holder return String;
-- Return the name of the Copyright holder to be displayed by the different
-- GNAT tools when switch --version is used.
Ver_Len_Max : constant := 64; Ver_Len_Max : constant := 64;
-- Longest possible length for Gnat_Version_String in this or any -- Longest possible length for Gnat_Version_String in this or any
-- other version of GNAT. This is used by the binder to establish -- other version of GNAT. This is used by the binder to establish
......
...@@ -24,13 +24,12 @@ ...@@ -24,13 +24,12 @@
-- -- -- --
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
with Xr_Tabls; use Xr_Tabls; with Opt;
with Xref_Lib; use Xref_Lib;
with Osint; use Osint; with Osint; use Osint;
with Types; use Types; with Types; use Types;
with Switch; use Switch;
with Gnatvsn; with Xr_Tabls; use Xr_Tabls;
with Opt; with Xref_Lib; use Xref_Lib;
with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Text_IO; use Ada.Text_IO;
...@@ -57,6 +56,9 @@ procedure Gnatxref is ...@@ -57,6 +56,9 @@ procedure Gnatxref is
procedure Parse_Cmd_Line; procedure Parse_Cmd_Line;
-- Parse every switch on the command line -- Parse every switch on the command line
procedure Usage;
-- Display the usage
procedure Write_Usage; procedure Write_Usage;
-- Print a small help page for program usage -- Print a small help page for program usage
...@@ -66,6 +68,10 @@ procedure Gnatxref is ...@@ -66,6 +68,10 @@ procedure Gnatxref is
procedure Parse_Cmd_Line is procedure Parse_Cmd_Line is
begin begin
-- First check for --version or --help
Check_Version_And_Help ("GNATXREF", "1998", Usage'Unrestricted_Access);
loop loop
case case
GNAT.Command_Line.Getopt GNAT.Command_Line.Getopt
...@@ -205,14 +211,12 @@ procedure Gnatxref is ...@@ -205,14 +211,12 @@ procedure Gnatxref is
Write_Usage; Write_Usage;
end Parse_Cmd_Line; end Parse_Cmd_Line;
----------------- -----------
-- Write_Usage -- -- Usage --
----------------- -----------
procedure Write_Usage is procedure Usage is
begin begin
Put_Line ("GNATXREF " & Gnatvsn.Gnat_Version_String);
Put_Line ("Copyright 1998-2005, AdaCore");
Put_Line ("Usage: gnatxref [switches] file1 file2 ..."); Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
New_Line; New_Line;
Put_Line (" file ... list of source files to xref, " & Put_Line (" file ... list of source files to xref, " &
...@@ -238,6 +242,17 @@ procedure Gnatxref is ...@@ -238,6 +242,17 @@ procedure Gnatxref is
Put_Line (" -v Print a 'tags' file for vi"); Put_Line (" -v Print a 'tags' file for vi");
New_Line; New_Line;
end Usage;
-----------------
-- Write_Usage --
-----------------
procedure Write_Usage is
begin
Display_Version ("GNATXREF", "1998");
New_Line;
Usage;
raise Usage_Error; raise Usage_Error;
end Write_Usage; end Write_Usage;
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
with Csets; with Csets;
with Err_Vars; use Err_Vars; with Err_Vars; use Err_Vars;
with Errutil; with Errutil;
with Gnatvsn; use Gnatvsn;
with Namet; use Namet; with Namet; use Namet;
with Opt; with Opt;
with Osint; use Osint; with Osint; use Osint;
...@@ -37,15 +36,16 @@ with Scng; ...@@ -37,15 +36,16 @@ with Scng;
with Sinput.C; with Sinput.C;
with Snames; with Snames;
with Stringt; use Stringt; with Stringt; use Stringt;
with Switch; use Switch;
with Types; use Types; with Types; use Types;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Case_Util; use GNAT.Case_Util; with GNAT.Case_Util; use GNAT.Case_Util;
with GNAT.Command_Line; with GNAT.Command_Line;
with GNAT.Directory_Operations; use GNAT.Directory_Operations; with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with System.OS_Lib; use System.OS_Lib; with System.OS_Lib; use System.OS_Lib;
package body GPrep is package body GPrep is
...@@ -138,10 +138,7 @@ package body GPrep is ...@@ -138,10 +138,7 @@ package body GPrep is
procedure Display_Copyright is procedure Display_Copyright is
begin begin
if not Copyright_Displayed then if not Copyright_Displayed then
Write_Line ("GNAT Preprocessor " & Gnatvsn.Gnat_Version_String); Display_Version ("GNAT Preprocessor", "1996");
Write_Line ("Copyright 1996-" &
Current_Year &
", Free Software Foundation, Inc.");
Copyright_Displayed := True; Copyright_Displayed := True;
end if; end if;
end Display_Copyright; end Display_Copyright;
...@@ -704,7 +701,13 @@ package body GPrep is ...@@ -704,7 +701,13 @@ package body GPrep is
Switch : Character; Switch : Character;
begin begin
-- Parse the switches -- First check for --version or --help
Check_Version_And_Help ("GNATPREP", "1996", Usage'Access);
-- Now scan the other switches
GNAT.Command_Line.Initialize_Option_Scan;
loop loop
begin begin
......
...@@ -392,8 +392,6 @@ package body Make is ...@@ -392,8 +392,6 @@ package body Make is
Shared_String : aliased String := "-shared"; Shared_String : aliased String := "-shared";
Force_Elab_Flags_String : aliased String := "-F"; Force_Elab_Flags_String : aliased String := "-F";
Version_Switch : constant String := "--version";
Help_Switch : constant String := "--help";
No_Shared_Switch : aliased Argument_List := (1 .. 0 => null); No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
Shared_Switch : aliased Argument_List := (1 => Shared_String'Access); Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
...@@ -509,9 +507,6 @@ package body Make is ...@@ -509,9 +507,6 @@ package body Make is
-- Misc Routines -- -- Misc Routines --
------------------- -------------------
procedure Display_Version;
-- Display version when switch --version is used
procedure List_Depend; procedure List_Depend;
-- Prints to standard output the list of object dependencies. This list -- Prints to standard output the list of object dependencies. This list
-- can be used directly in a Makefile. A call to Compile_Sources must -- can be used directly in a Makefile. A call to Compile_Sources must
...@@ -3562,15 +3557,22 @@ package body Make is ...@@ -3562,15 +3557,22 @@ package body Make is
if Uid /= Prj.No_Unit_Index then if Uid /= Prj.No_Unit_Index then
Udata := Project_Tree.Units.Table (Uid); Udata := Project_Tree.Units.Table (Uid);
if Udata.File_Names (Body_Part).Name /= if
No_File Udata.File_Names (Body_Part).Name /=
No_File
and then
Udata.File_Names (Body_Part).Path /= Slash
then then
Sfile := Udata.File_Names (Body_Part).Name; Sfile := Udata.File_Names (Body_Part).Name;
Source_Index := Source_Index :=
Udata.File_Names (Body_Part).Index; Udata.File_Names (Body_Part).Index;
elsif Udata.File_Names (Specification).Name /= elsif
No_File Udata.File_Names (Specification).Name /=
No_File
and then
Udata.File_Names (Specification).Path /=
Slash
then then
Sfile := Sfile :=
Udata.File_Names (Specification).Name; Udata.File_Names (Specification).Name;
...@@ -4063,26 +4065,6 @@ package body Make is ...@@ -4063,26 +4065,6 @@ package body Make is
Display_Executed_Programs := Display; Display_Executed_Programs := Display;
end Display_Commands; end Display_Commands;
---------------------
-- Display_Version --
---------------------
procedure Display_Version is
begin
Write_Str ("GNATMAKE ");
Write_Str (Gnatvsn.Gnat_Version_String);
Write_Eol;
Write_Str ("Copyright (C) 1995-");
Write_Str (Gnatvsn.Current_Year);
Write_Str (", Free Software Foundation, Inc.");
Write_Eol;
Write_Str (Gnatvsn.Gnat_Free_Software);
Write_Eol;
Write_Eol;
end Display_Version;
------------- -------------
-- Empty_Q -- -- Empty_Q --
------------- -------------
...@@ -4821,14 +4803,7 @@ package body Make is ...@@ -4821,14 +4803,7 @@ package body Make is
if Verbose_Mode then if Verbose_Mode then
Write_Eol; Write_Eol;
Write_Str ("GNATMAKE "); Display_Version ("GNATMAKE ", "1995");
Write_Str (Gnatvsn.Gnat_Version_String);
Write_Eol;
Write_Str
("Copyright 1995-" &
Current_Year &
", Free Software Foundation, Inc.");
Write_Eol;
end if; end if;
if Main_Project /= No_Project if Main_Project /= No_Project
...@@ -4901,7 +4876,6 @@ package body Make is ...@@ -4901,7 +4876,6 @@ package body Make is
Main_Index := Current_File_Index; Main_Index := Current_File_Index;
end if; end if;
Add_Switch ("-I-", Binder, And_Save => True);
Add_Switch ("-I-", Compiler, And_Save => True); Add_Switch ("-I-", Compiler, And_Save => True);
if Main_Project = No_Project then if Main_Project = No_Project then
...@@ -4914,10 +4888,6 @@ package body Make is ...@@ -4914,10 +4888,6 @@ package body Make is
Compiler, Append_Switch => False, Compiler, Append_Switch => False,
And_Save => False); And_Save => False);
Add_Switch ("-aO" & Normalized_CWD,
Binder,
Append_Switch => False,
And_Save => False);
end if; end if;
else else
...@@ -4930,6 +4900,7 @@ package body Make is ...@@ -4930,6 +4900,7 @@ package body Make is
-- projects. -- projects.
Look_In_Primary_Dir := False; Look_In_Primary_Dir := False;
Add_Switch ("-I-", Binder, And_Save => True);
end if; end if;
-- If the user wants a program without a main subprogram, add the -- If the user wants a program without a main subprogram, add the
...@@ -6670,49 +6641,16 @@ package body Make is ...@@ -6670,49 +6641,16 @@ package body Make is
-- Scan the switches and arguments -- Scan the switches and arguments
declare -- First, scan to detect --version and/or --help
Args : Argument_List (1 .. Argument_Count);
Version_Switch_Present : Boolean := False;
Help_Switch_Present : Boolean := False;
begin Check_Version_And_Help ("GNATMAKE", "1995", Makeusg'Access);
-- First, scan to detect --version and/or --help
for Next_Arg in 1 .. Argument_Count loop
Args (Next_Arg) := new String'(Argument (Next_Arg));
if Args (Next_Arg).all = Version_Switch then
Version_Switch_Present := True;
elsif Args (Next_Arg).all = Help_Switch then
Help_Switch_Present := True;
end if;
end loop;
-- If --version was used, display version and exit -- Scan again the switch and arguments, now that we are sure that
-- they do not include --version or --help.
if Version_Switch_Present then
Set_Standard_Output;
Display_Version;
Exit_Program (E_Success);
end if;
-- If --help was used, display help and exit Scan_Args : for Next_Arg in 1 .. Argument_Count loop
Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
if Help_Switch_Present then end loop Scan_Args;
Set_Standard_Output;
Makeusg;
Write_Eol;
Write_Line ("Report bugs to report@adacore.com");
Exit_Program (E_Success);
end if;
-- Scan again the switch and arguments, now that we are sure that
-- they do not include --version or --help.
Scan_Args : for Next_Arg in Args'Range loop
Scan_Make_Arg (Args (Next_Arg).all, And_Save => True);
end loop Scan_Args;
end;
if Commands_To_Stdout then if Commands_To_Stdout then
Set_Standard_Output; Set_Standard_Output;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1992-2005, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
-- -- -- --
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
with Osint; with Osint; use Osint;
with Output; use Output;
package body Switch is package body Switch is
...@@ -42,6 +43,87 @@ package body Switch is ...@@ -42,6 +43,87 @@ package body Switch is
Osint.Fail ("invalid switch: ", Switch); Osint.Fail ("invalid switch: ", Switch);
end Bad_Switch; end Bad_Switch;
----------------------------
-- Check_Version_And_Help --
----------------------------
procedure Check_Version_And_Help
(Tool_Name : String;
Initial_Year : String;
Usage : Procedure_Ptr;
Version_String : String := Gnatvsn.Gnat_Version_String)
is
Version_Switch_Present : Boolean := False;
Help_Switch_Present : Boolean := False;
Next_Arg : Natural;
begin
-- First check for --version or --help
Next_Arg := 1;
while Next_Arg < Arg_Count loop
declare
Next_Argv : String (1 .. Len_Arg (Next_Arg));
begin
Fill_Arg (Next_Argv'Address, Next_Arg);
if Next_Argv = Version_Switch then
Version_Switch_Present := True;
elsif Next_Argv = Help_Switch then
Help_Switch_Present := True;
end if;
Next_Arg := Next_Arg + 1;
end;
end loop;
-- If --version was used, display version and exit
if Version_Switch_Present then
Set_Standard_Output;
Display_Version (Tool_Name, Initial_Year, Version_String);
Write_Str (Gnatvsn.Gnat_Free_Software);
Write_Eol;
Write_Eol;
Exit_Program (E_Success);
end if;
-- If --help was used, display help and exit
if Help_Switch_Present then
Set_Standard_Output;
Usage.all;
Write_Eol;
Write_Line ("Report bugs to report@adacore.com");
Exit_Program (E_Success);
end if;
end Check_Version_And_Help;
---------------------
-- Display_Version --
---------------------
procedure Display_Version
(Tool_Name : String;
Initial_Year : String;
Version_String : String := Gnatvsn.Gnat_Version_String)
is
begin
Write_Str (Tool_Name);
Write_Char (' ');
Write_Str (Version_String);
Write_Eol;
Write_Str ("Copyright (C) ");
Write_Str (Initial_Year);
Write_Char ('-');
Write_Str (Gnatvsn.Current_Year);
Write_Str (", ");
Write_Str (Gnatvsn.Copyright_Holder);
Write_Eol;
end Display_Version;
------------------------- -------------------------
-- Is_Front_End_Switch -- -- Is_Front_End_Switch --
------------------------- -------------------------
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 1992-2005 Free Software Foundation, Inc. -- -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -31,30 +31,43 @@ ...@@ -31,30 +31,43 @@
-- switches that are recognized. In addition, package Debug documents -- switches that are recognized. In addition, package Debug documents
-- the otherwise undocumented debug switches that are also recognized. -- the otherwise undocumented debug switches that are also recognized.
with Gnatvsn;
with Types; use Types; with Types; use Types;
package Switch is package Switch is
-- Note: The default switch character is indicated by Switch_Character, -- Common switches for GNU tools
-- but regardless of what it is, a hyphen is always allowed as an
-- (alternative) switch character.
-- Note: In GNAT, the case of switches is not significant if Version_Switch : constant String := "--version";
-- Switches_Case_Sensitive is False. If this is the case, switch Help_Switch : constant String := "--help";
-- characters, or letters appearing in the parameter to a switch, may be
-- either upper case or lower case.
----------------- -----------------
-- Subprograms -- -- Subprograms --
----------------- -----------------
type Procedure_Ptr is access procedure;
procedure Check_Version_And_Help
(Tool_Name : String;
Initial_Year : String;
Usage : Procedure_Ptr;
Version_String : String := Gnatvsn.Gnat_Version_String);
-- Check if switches --version or --help is used. If one of this switch
-- is used, issue the proper messages and end the process.
procedure Display_Version
(Tool_Name : String;
Initial_Year : String;
Version_String : String := Gnatvsn.Gnat_Version_String);
-- Display version of a tool when switch --version is used
function Is_Switch (Switch_Chars : String) return Boolean; function Is_Switch (Switch_Chars : String) return Boolean;
-- Returns True iff Switch_Chars is at least two characters long, -- Returns True iff Switch_Chars is at least two characters long,
-- and the first character indicates it is a switch. -- and the first character is an hyphen ('-').
function Is_Front_End_Switch (Switch_Chars : String) return Boolean; function Is_Front_End_Switch (Switch_Chars : String) return Boolean;
-- Returns True iff Switch_Chars represents a front-end switch, -- Returns True iff Switch_Chars represents a front-end switch,
-- ie. it starts with -I or -gnat. -- ie. it starts with -I, -gnat or -?RTS.
private private
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment