1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2003-2004, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
31 with Namet
; use Namet
;
33 with Osint
; use Osint
;
34 with Osint
.M
; use Osint
.M
;
40 with Prj
.Util
; use Prj
.Util
;
44 with Types
; use Types
;
46 with GNAT
.Command_Line
; use GNAT
.Command_Line
;
47 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
48 with GNAT
.IO
; use GNAT
.IO
;
49 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
54 Initialized
: Boolean := False;
55 -- Set to True by the first call to Initialize.
56 -- To avoid reinitialization of some packages.
58 -- Suffixes of various files
60 Assembly_Suffix
: constant String := ".s";
61 ALI_Suffix
: constant String := ".ali";
62 Tree_Suffix
: constant String := ".adt";
63 Object_Suffix
: constant String := Get_Object_Suffix
.all;
64 Debug_Suffix
: String := ".dg";
65 -- Changed to "_dg" for VMS in the body of the package
67 Repinfo_Suffix
: String := ".rep";
68 -- Changed to "_rep" for VMS in the body of the package
70 B_Start
: String := "b~";
71 -- Prefix of binder generated file.
72 -- Changed to "b$" for VMS in the body of the package.
74 Object_Directory_Path
: String_Access
:= null;
75 -- The path name of the object directory, set with switch -D
77 Do_Nothing
: Boolean := False;
78 -- Set to True when switch -n is specified.
79 -- When True, no file is deleted. gnatclean only lists the files that
80 -- would have been deleted if the switch -n had not been specified.
82 File_Deleted
: Boolean := False;
83 -- Set to True if at least one file has been deleted
85 Copyright_Displayed
: Boolean := False;
86 Usage_Displayed
: Boolean := False;
88 Project_File_Name
: String_Access
:= null;
90 Main_Project
: Prj
.Project_Id
:= Prj
.No_Project
;
92 All_Projects
: Boolean := False;
94 -- Packages of project files where unknown attributes are errors.
96 Naming_String
: aliased String := "naming";
97 Builder_String
: aliased String := "builder";
98 Compiler_String
: aliased String := "compiler";
99 Binder_String
: aliased String := "binder";
100 Linker_String
: aliased String := "linker";
102 Gnatmake_Packages
: aliased String_List
:=
103 (Naming_String
'Access,
104 Builder_String 'Access,
105 Compiler_String
'Access,
106 Binder_String 'Access,
107 Linker_String
'Access);
109 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
110 Gnatmake_Packages'Access;
112 package Processed_Projects is new Table.Table
113 (Table_Component_Type => Project_Id,
114 Table_Index_Type => Natural,
115 Table_Low_Bound => 0,
117 Table_Increment => 10,
118 Table_Name => "Clean.Processed_Projects");
119 -- Table to keep track of what project files have been processed, when
120 -- switch -r is specified.
122 package Sources is new Table.Table
123 (Table_Component_Type => File_Name_Type,
124 Table_Index_Type => Natural,
125 Table_Low_Bound => 0,
127 Table_Increment => 10,
128 Table_Name => "Clean.Processed_Projects");
129 -- Table to store all the source files of a library unit: spec, body and
130 -- subunits, to detect .dg files and delete them.
132 ----------------------------
133 -- Queue (Q) manipulation --
134 ----------------------------
137 -- Must be called to initialize the Q
140 (Source_File : File_Name_Type);
141 -- If Source_File is not marked, inserts it at the end of Q and mark it
143 function Empty_Q return Boolean;
144 -- Returns True if Q is empty.
146 procedure Extract_From_Q
147 (Source_File : out File_Name_Type);
148 -- Extracts the first element from the Q.
151 -- Points to the first valid element in the Q.
153 package Q is new Table.Table (
154 Table_Component_Type => File_Name_Type,
155 Table_Index_Type => Natural,
156 Table_Low_Bound => 0,
157 Table_Initial => 4000,
158 Table_Increment => 100,
159 Table_Name => "Clean.Q");
160 -- This is the actual queue
162 -----------------------------
163 -- Other local subprograms --
164 -----------------------------
166 procedure Add_Source_Dir (N : String);
167 -- Call Add_Src_Search_Dir.
168 -- Output one line when in verbose mode.
170 procedure Add_Source_Directories is
171 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
173 procedure Add_Object_Dir (N : String);
174 -- Call Add_Lib_Search_Dir.
175 -- Output one line when in verbose mode.
177 procedure Add_Object_Directories is
178 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
180 function ALI_File_Name (Source : Name_Id) return String;
181 -- Returns the name of the ALI file corresponding to Source
183 function Assembly_File_Name (Source : Name_Id) return String;
184 -- Returns the assembly file name corresponding to Source
186 procedure Clean_Directory (Dir : Name_Id);
187 -- Delete all regular files in a library directory or in a library
190 procedure Clean_Executables;
191 -- Do the cleaning work when no project file is specified
193 procedure Clean_Project (Project : Project_Id);
194 -- Do the cleaning work when a project file is specified.
195 -- This procedure calls itself recursively when there are several
196 -- project files in the tree rooted at the main project file and switch -r
197 -- has been specified.
199 function Debug_File_Name (Source : Name_Id) return String;
200 -- Name of the expanded source file corresponding to Source
202 procedure Delete (In_Directory : String; File : String);
203 -- Delete one file, or list the file name if switch -n is specified
205 procedure Delete_Binder_Generated_Files (Dir : String; Source : Name_Id);
206 -- Delete the binder generated file in directory Dir for Source, if they
207 -- exist: for Unix these are b~<source>.ads, b~<source>.adb,
208 -- b~<source>.ali and b~<source>.o.
210 procedure Display_Copyright;
211 -- Display the Copyright notice.
212 -- If called several times, display the Copyright notice only the first
215 procedure Initialize;
216 -- Call the necessary package initializations
218 function Object_File_Name (Source : Name_Id) return String;
219 -- Returns the object file name corresponding to Source
221 procedure Parse_Cmd_Line;
222 -- Parse the command line
224 function Repinfo_File_Name (Source : Name_Id) return String;
225 -- Returns the repinfo file name corresponding to Source
227 function Tree_File_Name (Source : Name_Id) return String;
228 -- Returns the tree file name corresponding to Source
230 function In_Extension_Chain
231 (Of_Project : Project_Id;
232 Prj : Project_Id) return Boolean;
233 -- Returns True iff Prj is an extension of Of_Project or if Of_Project is
234 -- an extension of Prj.
237 -- Display the usage.
238 -- If called several times, the usage is displayed only the first time.
244 procedure Add_Object_Dir (N : String) is
246 Add_Lib_Search_Dir (N);
248 if Opt.Verbose_Mode then
249 Put ("Adding object directory """);
260 procedure Add_Source_Dir (N : String) is
262 Add_Src_Search_Dir (N);
264 if Opt.Verbose_Mode then
265 Put ("Adding source directory """);
276 function ALI_File_Name (Source : Name_Id) return String is
277 Src : constant String := Get_Name_String (Source);
280 -- If the source name has an extension, then replace it with
283 for Index in reverse Src'First + 1 .. Src'Last loop
284 if Src (Index) = '.' then
285 return Src (Src'First .. Index - 1) & ALI_Suffix;
289 -- If there is no dot, or if it is the first character, just add the
292 return Src & ALI_Suffix;
295 ------------------------
296 -- Assembly_File_Name --
297 ------------------------
299 function Assembly_File_Name (Source : Name_Id) return String is
300 Src : constant String := Get_Name_String (Source);
303 -- If the source name has an extension, then replace it with
304 -- the assembly suffix.
306 for Index in reverse Src'First + 1 .. Src'Last loop
307 if Src (Index) = '.' then
308 return Src (Src'First .. Index - 1) & Assembly_Suffix;
312 -- If there is no dot, or if it is the first character, just add the
315 return Src & Assembly_Suffix;
316 end Assembly_File_Name;
318 ---------------------
319 -- Clean_Directory --
320 ---------------------
322 procedure Clean_Directory (Dir : Name_Id) is
323 Directory : constant String := Get_Name_String (Dir);
324 Current : constant Dir_Name_Str := Get_Current_Dir;
328 Name : String (1 .. 200);
331 procedure Set_Writable (Name : System.Address);
332 pragma Import (C, Set_Writable, "__gnat_set_writable");
335 Change_Dir (Directory);
338 -- For each regular file in the directory, if switch -n has not been
339 -- specified, make it writable and delete the file.
342 Read (Direc, Name, Last);
345 if Is_Regular_File (Name (1 .. Last)) then
346 if not Do_Nothing then
347 Name (Last + 1) := ASCII.NUL;
348 Set_Writable (Name (1)'Address);
351 Delete (Directory, Name (1 .. Last));
357 -- Restore the initial working directory
359 Change_Dir (Current);
362 -----------------------
363 -- Clean_Executables --
364 -----------------------
366 procedure Clean_Executables is
367 Main_Source_File : File_Name_Type;
368 -- Current main source
370 Source_File : File_Name_Type;
371 -- Current source file
373 Lib_File : File_Name_Type;
374 -- Current library file
376 Full_Lib_File : File_Name_Type;
377 -- Full name of the current library file
379 Text : Text_Buffer_Ptr;
385 -- It does not really matter if there is or not an object file
386 -- corresponding to an ALI file: if there is one, it will be deleted.
388 Opt.Check_Object_Consistency := False;
390 -- Proceed each executable one by one. Each source is marked as it is
391 -- processed, so common sources between executables will not be
392 -- processed several times.
394 for N_File in 1 .. Osint.Number_Of_Files loop
395 Main_Source_File := Next_Main_Source;
396 Insert_Q (Main_Source_File);
398 while not Empty_Q loop
399 Sources.Set_Last (0);
400 Extract_From_Q (Source_File);
401 Lib_File := Osint.Lib_File_Name (Source_File);
402 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
404 -- If we have an existing ALI file that is not read-only,
407 if Full_Lib_File /= No_File
408 and then not Is_Readonly_Library (Full_Lib_File)
410 Text := Read_Library_Info (Lib_File);
414 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
417 -- If no error was produced while loading this ALI file,
418 -- insert into the queue all the unmarked withed sources.
420 if The_ALI /= No_ALI_Id then
421 for J in ALIs.Table (The_ALI).First_Unit ..
422 ALIs.Table (The_ALI).Last_Unit
424 Sources.Increment_Last;
425 Sources.Table (Sources.Last) :=
426 ALI.Units.Table (J).Sfile;
428 for K in ALI.Units.Table (J).First_With ..
429 ALI.Units.Table (J).Last_With
431 Insert_Q (Withs.Table (K).Sfile);
435 -- Look for subunits and put them in the Sources table
437 for J in ALIs.Table (The_ALI).First_Sdep ..
438 ALIs.Table (The_ALI).Last_Sdep
440 if Sdep.Table (J).Subunit_Name /= No_Name then
441 Sources.Increment_Last;
442 Sources.Table (Sources.Last) :=
443 Sdep.Table (J).Sfile;
449 -- Now, delete all the existing files corresponding to this
453 Obj_Dir : constant String :=
454 Dir_Name (Get_Name_String (Full_Lib_File));
455 Obj : constant String := Object_File_Name (Lib_File);
456 Adt : constant String := Tree_File_Name (Lib_File);
457 Asm : constant String := Assembly_File_Name (Lib_File);
460 Delete (Obj_Dir, Get_Name_String (Lib_File));
462 if Is_Regular_File (Obj_Dir & Dir_Separator & Obj) then
463 Delete (Obj_Dir, Obj);
466 if Is_Regular_File (Obj_Dir & Dir_Separator & Adt) then
467 Delete (Obj_Dir, Adt);
470 if Is_Regular_File (Obj_Dir & Dir_Separator & Asm) then
471 Delete (Obj_Dir, Asm);
474 -- Delete expanded source files (.dg) and/or repinfo files
477 for J in 1 .. Sources.Last loop
479 Deb : constant String :=
480 Debug_File_Name (Sources.Table (J));
481 Rep : constant String :=
482 Repinfo_File_Name (Sources.Table (J));
484 if Is_Regular_File (Obj_Dir & Dir_Separator & Deb) then
485 Delete (Obj_Dir, Deb);
488 if Is_Regular_File (Obj_Dir & Dir_Separator & Rep) then
489 Delete (Obj_Dir, Rep);
497 -- Delete the executable, if it exists, and the binder generated
500 if not Compile_Only then
502 Source : constant Name_Id := Strip_Suffix (Main_Source_File);
503 Executable : constant String := Get_Name_String
504 (Executable_Name (Source));
506 if Is_Regular_File (Executable) then
507 Delete ("", Executable);
510 Delete_Binder_Generated_Files (Get_Current_Dir, Source);
514 end Clean_Executables;
520 procedure Clean_Project (Project : Project_Id) is
521 Main_Source_File : File_Name_Type;
522 -- Name of the executable on the command line, without directory
525 Executable : Name_Id;
526 -- Name of the executable file
528 Current_Dir : constant Dir_Name_Str := Get_Current_Dir;
529 Data : constant Project_Data := Projects.Table (Project);
530 U_Data : Prj.Com.Unit_Data;
531 File_Name1 : Name_Id;
532 File_Name2 : Name_Id;
537 -- Check that we don't specify executable on the command line for
538 -- a main library project.
540 if Project = Main_Project
541 and then Osint.Number_Of_Files /= 0
542 and then Data.Library
545 ("Cannot specify executable(s) for a Library Project File");
549 Put ("Cleaning project """);
550 Put (Get_Name_String (Data.Name));
554 -- Add project to the list of proceesed projects
556 Processed_Projects.Increment_Last;
557 Processed_Projects.Table (Processed_Projects.Last) := Project;
559 if Data.Object_Directory /= No_Name then
561 Obj_Dir : constant String :=
562 Get_Name_String (Data.Object_Directory);
565 Change_Dir (Obj_Dir);
567 -- Look through the units to find those that are either immediate
568 -- sources or inherited sources of the project.
570 for Unit in 1 .. Prj.Com.Units.Last loop
571 U_Data := Prj.Com.Units.Table (Unit);
572 File_Name1 := No_Name;
573 File_Name2 := No_Name;
575 -- If either the spec or the body is a source of the project,
576 -- check for the corresponding ALI file in the object
579 if In_Extension_Chain
580 (U_Data.File_Names (Body_Part).Project, Project)
583 (U_Data.File_Names (Specification).Project, Project)
585 File_Name1 := U_Data.File_Names (Body_Part).Name;
586 File_Name2 := U_Data.File_Names (Specification).Name;
588 -- If there is no body file name, then there may be only a
591 if File_Name1 = No_Name then
592 File_Name1 := File_Name2;
593 File_Name2 := No_Name;
597 -- If there is either a spec or a body, look for files in the
600 if File_Name1 /= No_Name then
602 Asm : constant String := Assembly_File_Name (File_Name1);
603 ALI : constant String := ALI_File_Name (File_Name1);
604 Obj : constant String := Object_File_Name (File_Name1);
605 Adt : constant String := Tree_File_Name (File_Name1);
606 Deb : constant String := Debug_File_Name (File_Name1);
607 Rep : constant String := Repinfo_File_Name (File_Name1);
608 Del : Boolean := True;
611 -- If the ALI file exists and is read-only, no file is
614 if Is_Regular_File (ALI) then
615 if Is_Writable_File (ALI) then
616 Delete (Obj_Dir, ALI);
625 if Obj_Dir (Obj_Dir'Last) /= Dir_Separator then
630 Put_Line (""" is read
-only
");
639 if Is_Regular_File (Obj) then
640 Delete (Obj_Dir, Obj);
645 if Is_Regular_File (Asm) then
646 Delete (Obj_Dir, Asm);
651 if Is_Regular_File (Adt) then
652 Delete (Obj_Dir, Adt);
655 -- First expanded source file
657 if Is_Regular_File (Deb) then
658 Delete (Obj_Dir, Deb);
663 if Is_Regular_File (Rep) then
664 Delete (Obj_Dir, Rep);
667 -- Second expanded source file
669 if File_Name2 /= No_Name then
671 Deb : constant String :=
672 Debug_File_Name (File_Name2);
673 Rep : constant String :=
674 Repinfo_File_Name (File_Name2);
676 if Is_Regular_File (Deb) then
677 Delete (Obj_Dir, Deb);
680 if Is_Regular_File (Rep) then
681 Delete (Obj_Dir, Rep);
696 -- If switch -r is specified, call Clean_Project recursively for the
697 -- imported projects and the project being extended.
701 Imported : Project_List := Data.Imported_Projects;
702 Element : Project_Element;
706 -- For each imported project, call Clean_Project if the project
707 -- has not been processed already.
709 while Imported /= Empty_Project_List loop
710 Element := Project_Lists.Table (Imported);
711 Imported := Element.Next;
715 J in Processed_Projects.First .. Processed_Projects.Last
717 if Element.Project = Processed_Projects.Table (J) then
724 Clean_Project (Element.Project);
728 -- If this project extends another project, call Clean_Project for
729 -- the project being extended. It is guaranteed that it has not
730 -- called before, because no other project may import or extend
733 if Data.Extends /= No_Project then
734 Clean_Project (Data.Extends);
739 -- If this is a library project, clean the library directory, the
740 -- interface copy dir and, for a Stand-Alone Library, the binder
741 -- generated files of the library.
743 -- The directories are cleaned only if switch -c is not specified.
746 if not Compile_Only then
747 Clean_Directory (Data.Library_Dir);
749 if Data.Library_Src_Dir /= No_Name
750 and then Data.Library_Src_Dir /= Data.Library_Dir
752 Clean_Directory (Data.Library_Src_Dir);
756 if Data.Standalone_Library and then
757 Data.Object_Directory /= No_Name
759 Delete_Binder_Generated_Files
760 (Get_Name_String (Data.Object_Directory), Data.Library_Name);
763 -- Otherwise, for the main project, delete the executables and the
764 -- binder generated files.
766 -- The executables are deleted only if switch -c is not specified.
768 elsif Project = Main_Project and then Data.Exec_Directory /= No_Name then
770 Exec_Dir : constant String :=
771 Get_Name_String (Data.Exec_Directory);
773 Change_Dir (Exec_Dir);
775 for N_File in 1 .. Osint.Number_Of_Files loop
776 Main_Source_File := Next_Main_Source;
778 if not Compile_Only then
779 Executable := Executable_Of (Main_Project, Main_Source_File);
781 if Is_Regular_File (Get_Name_String (Executable)) then
782 Delete (Exec_Dir, Get_Name_String (Executable));
786 if Data.Object_Directory /= No_Name then
787 Delete_Binder_Generated_Files
789 (Data.Object_Directory),
790 Strip_Suffix (Main_Source_File));
796 -- Change back to previous directory
798 Change_Dir (Current_Dir);
801 ---------------------
802 -- Debug_File_Name --
803 ---------------------
805 function Debug_File_Name (Source : Name_Id) return String is
807 return Get_Name_String (Source) & Debug_Suffix;
814 procedure Delete (In_Directory : String; File : String) is
815 Full_Name : String (1 .. In_Directory'Length + File'Length + 1);
820 -- Indicate that at least one file is deleted or is to be deleted
822 File_Deleted := True;
824 -- Build the path name of the file to delete
826 Last := In_Directory'Length;
827 Full_Name (1 .. Last) := In_Directory;
829 if Last > 0 and then Full_Name (Last) /= Directory_Separator then
831 Full_Name (Last) := Directory_Separator;
834 Full_Name (Last + 1 .. Last + File'Length) := File;
835 Last := Last + File'Length;
837 -- If switch -n was used, simply output the path name
840 Put_Line (Full_Name (1 .. Last));
842 -- Otherwise, delete the file
845 Delete_File (Full_Name (1 .. Last), Success);
849 Put (Full_Name (1 .. Last));
850 Put_Line (""" could
not be deleted
");
852 elsif Verbose_Mode or else not Quiet_Output then
854 Put (Full_Name (1 .. Last));
855 Put_Line (""" has been deleted
");
860 -----------------------------------
861 -- Delete_Binder_Generated_Files --
862 -----------------------------------
864 procedure Delete_Binder_Generated_Files (Dir : String; Source : Name_Id) is
865 Source_Name : constant String := Get_Name_String (Source);
866 Current : constant String := Get_Current_Dir;
867 Last : constant Positive := B_Start'Length + Source_Name'Length;
868 File_Name : String (1 .. Last + 4);
873 -- Build the file name (before the extension)
875 File_Name (1 .. B_Start'Length) := B_Start;
876 File_Name (B_Start'Length + 1 .. Last) := Source_Name;
880 File_Name (Last + 1 .. Last + 4) := ".ads
";
882 if Is_Regular_File (File_Name (1 .. Last + 4)) then
883 Delete (Dir, File_Name (1 .. Last + 4));
888 File_Name (Last + 1 .. Last + 4) := ".adb
";
890 if Is_Regular_File (File_Name (1 .. Last + 4)) then
891 Delete (Dir, File_Name (1 .. Last + 4));
896 File_Name (Last + 1 .. Last + 4) := ".ali
";
898 if Is_Regular_File (File_Name (1 .. Last + 4)) then
899 Delete (Dir, File_Name (1 .. Last + 4));
904 File_Name (Last + 1 .. Last + Object_Suffix'Length) := Object_Suffix;
906 if Is_Regular_File (File_Name (1 .. Last + Object_Suffix'Length)) then
907 Delete (Dir, File_Name (1 .. Last + Object_Suffix'Length));
910 -- Change back to previous directory
912 Change_Dir (Current);
913 end Delete_Binder_Generated_Files;
915 -----------------------
916 -- Display_Copyright --
917 -----------------------
919 procedure Display_Copyright is
921 if not Copyright_Displayed then
922 Copyright_Displayed := True;
923 Put_Line ("GNATCLEAN
" & Gnatvsn.Gnat_Version_String
924 & " Copyright
2003-2004 Free Software Foundation
, Inc
.");
926 end Display_Copyright;
932 function Empty_Q return Boolean is
934 return Q_Front >= Q.Last;
941 procedure Extract_From_Q (Source_File : out File_Name_Type) is
942 File : constant File_Name_Type := Q.Table (Q_Front);
945 Q_Front := Q_Front + 1;
953 procedure Gnatclean is
955 -- Do the necessary initializations
959 -- Parse the command line, getting the switches and the executable names
967 if Project_File_Name /= null then
969 -- A project file was specified by a -P switch
971 if Opt.Verbose_Mode then
973 Put ("Parsing Project File
""");
974 Put (Project_File_Name.all);
979 -- Set the project parsing verbosity to whatever was specified
980 -- by a possible -vP switch.
982 Prj.Pars.Set_Verbosity (To => Prj.Com.Current_Verbosity);
984 -- Parse the project file.
985 -- If there is an error, Main_Project will still be No_Project.
988 (Project => Main_Project,
989 Project_File_Name => Project_File_Name.all,
990 Packages_To_Check => Packages_To_Check_By_Gnatmake);
992 if Main_Project = No_Project then
993 Fail ("""" & Project_File_Name.all &
994 """ processing failed
");
997 if Opt.Verbose_Mode then
999 Put ("Parsing
of Project File
""");
1000 Put (Project_File_Name.all);
1001 Put (""" is finished
.");
1005 -- We add the source directories and the object directories
1006 -- to the search paths.
1008 Add_Source_Directories (Main_Project);
1009 Add_Object_Directories (Main_Project);
1013 Osint.Add_Default_Search_Dirs;
1015 -- If a project file was specified, but no executable name, put all
1016 -- the mains of the project file (if any) as if there were on the
1019 if Main_Project /= No_Project and then Osint.Number_Of_Files = 0 then
1021 Value : String_List_Id := Projects.Table (Main_Project).Mains;
1024 while Value /= Prj.Nil_String loop
1025 Get_Name_String (String_Elements.Table (Value).Value);
1026 Osint.Add_File (Name_Buffer (1 .. Name_Len));
1027 Value := String_Elements.Table (Value).Next;
1032 -- If neither a project file nor an executable were specified,
1033 -- output the usage and exit.
1035 if Main_Project = No_Project and then Osint.Number_Of_Files = 0 then
1040 if Verbose_Mode then
1044 if Main_Project /= No_Project then
1046 -- If a project file has been specified, call Clean_Project with the
1047 -- project id of this project file, after resetting the list of
1048 -- processed projects.
1050 Processed_Projects.Init;
1051 Clean_Project (Main_Project);
1054 -- If no project file has been specified, the work is done in
1055 -- Clean_Executables.
1060 -- In verbose mode, if Delete has not been called, indicate that
1061 -- no file needs to be deleted.
1063 if Verbose_Mode and (not File_Deleted) then
1067 Put_Line ("No file needs to be deleted
");
1069 Put_Line ("No file has been deleted
");
1074 ------------------------
1075 -- In_Extension_Chain --
1076 ------------------------
1078 function In_Extension_Chain
1079 (Of_Project : Project_Id;
1080 Prj : Project_Id) return Boolean
1082 Data : Project_Data;
1085 if Of_Project = Prj then
1089 Data := Projects.Table (Of_Project);
1091 while Data.Extends /= No_Project loop
1092 if Data.Extends = Prj then
1096 Data := Projects.Table (Data.Extends);
1099 Data := Projects.Table (Prj);
1101 while Data.Extends /= No_Project loop
1102 if Data.Extends = Of_Project then
1106 Data := Projects.Table (Data.Extends);
1110 end In_Extension_Chain;
1119 Q.Set_Last (Q.First);
1126 procedure Initialize is
1128 if not Initialized then
1129 Initialized := True;
1131 -- Initialize some packages
1139 -- Reset global variables
1141 Free (Object_Directory_Path);
1142 Do_Nothing := False;
1143 File_Deleted := False;
1144 Copyright_Displayed := False;
1145 Usage_Displayed := False;
1146 Free (Project_File_Name);
1147 Main_Project := Prj.No_Project;
1148 All_Projects := False;
1155 procedure Insert_Q (Source_File : File_Name_Type) is
1157 -- Do not insert an empty name or an already marked source
1159 if Source_File /= No_Name
1160 and then Get_Name_Table_Byte (Source_File) = 0
1162 Q.Table (Q.Last) := Source_File;
1165 -- Mark the source that has been just added to the Q
1167 Set_Name_Table_Byte (Source_File, 1);
1171 ----------------------
1172 -- Object_File_Name --
1173 ----------------------
1175 function Object_File_Name (Source : Name_Id) return String is
1176 Src : constant String := Get_Name_String (Source);
1179 -- If the source name has an extension, then replace it with
1180 -- the Object suffix.
1182 for Index in reverse Src'First + 1 .. Src'Last loop
1183 if Src (Index) = '.' then
1184 return Src (Src'First .. Index - 1) & Object_Suffix;
1188 -- If there is no dot, or if it is the first character, just add the
1191 return Src & Object_Suffix;
1192 end Object_File_Name;
1194 --------------------
1195 -- Parse_Cmd_Line --
1196 --------------------
1198 procedure Parse_Cmd_Line is
1202 GNAT.Command_Line.Getopt
1203 ("aO
: c D
: F h I
: I
- n P
: q r v vP0 vP1 vP2 X
:")
1209 Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
1212 Compile_Only := True;
1216 Dir : constant String := GNAT.Command_Line.Parameter;
1219 if Object_Directory_Path /= null then
1220 Fail ("duplicate
-D switch
");
1222 elsif Project_File_Name /= null then
1223 Fail ("-P
and -D cannot be used simultaneously
");
1225 elsif not Is_Directory (Dir) then
1226 Fail (Dir, " is not a directory
");
1229 Add_Lib_Search_Dir (Dir);
1234 Full_Path_Name_For_Brief_Errors := True;
1240 if Full_Switch = "I
-" then
1241 Opt.Look_In_Primary_Dir := False;
1244 Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
1251 if Project_File_Name /= null then
1252 Fail ("multiple
-P switches
");
1254 elsif Object_Directory_Path /= null then
1255 Fail ("-D
and -P cannot be used simultaneously
");
1259 Prj : constant String := GNAT.Command_Line.Parameter;
1261 if Prj'Length > 1 and then Prj (Prj'First) = '=' then
1262 Project_File_Name :=
1263 new String'(Prj (Prj'First + 1 .. Prj'Last));
1266 Project_File_Name := new String'(Prj);
1272 Quiet_Output := True;
1275 All_Projects := True;
1278 if Full_Switch = "v
" then
1279 Verbose_Mode := True;
1281 elsif Full_Switch = "vP0
" then
1282 Prj.Com.Current_Verbosity := Prj.Default;
1284 elsif Full_Switch = "vP1
" then
1285 Prj.Com.Current_Verbosity := Prj.Medium;
1288 Prj.Com.Current_Verbosity := Prj.High;
1293 Ext_Asgn : constant String := GNAT.Command_Line.Parameter;
1294 Start : Positive := Ext_Asgn'First;
1295 Stop : Natural := Ext_Asgn'Last;
1296 Equal_Pos : Natural;
1297 OK : Boolean := True;
1300 if Ext_Asgn (Start) = '"' then
1301 if Ext_Asgn (Stop) = '"' then
1312 while Equal_Pos <= Stop and then
1313 Ext_Asgn (Equal_Pos) /= '='
1315 Equal_Pos := Equal_Pos + 1;
1318 if Equal_Pos = Start or else Equal_Pos > Stop then
1324 (External_Name => Ext_Asgn (Start .. Equal_Pos - 1),
1325 Value => Ext_Asgn (Equal_Pos + 1 .. Stop));
1328 Fail ("illegal external assignment
'", Ext_Asgn, "'");
1333 Fail ("INTERNAL ERROR
, please report
");
1337 -- Get the file names
1341 S : constant String := GNAT.Command_Line.Get_Argument;
1344 exit when S'Length = 0;
1351 when GNAT.Command_Line.Invalid_Switch =>
1353 Fail ("invalid switch
: "& GNAT.Command_Line.Full_Switch);
1355 when GNAT.Command_Line.Invalid_Parameter =>
1357 Fail ("parameter missing
for : " & GNAT.Command_Line.Full_Switch);
1360 -----------------------
1361 -- Repinfo_File_Name --
1362 -----------------------
1364 function Repinfo_File_Name (Source : Name_Id) return String is
1366 return Get_Name_String (Source) & Repinfo_Suffix;
1367 end Repinfo_File_Name;
1369 --------------------
1370 -- Tree_File_Name --
1371 --------------------
1373 function Tree_File_Name (Source : Name_Id) return String is
1374 Src : constant String := Get_Name_String (Source);
1377 -- If the source name has an extension, then replace it with
1380 for Index in reverse Src'First + 1 .. Src'Last loop
1381 if Src (Index) = '.' then
1382 return Src (Src'First .. Index - 1) & Tree_Suffix;
1386 -- If there is no dot, or if it is the first character, just add the
1389 return Src & Tree_Suffix;
1398 if not Usage_Displayed then
1399 Usage_Displayed := True;
1401 Put_Line ("Usage
: gnatclean
[switches
] names
");
1404 Put_Line (" names
is one
or more file names from which
" &
1405 "the
.adb
or .ads suffix may be omitted
");
1406 Put_Line (" names may be omitted
if -P
<project
> is specified
");
1409 Put_Line (" -c Only delete compiler generated files
");
1410 Put_Line (" -D dir Specify dir as the object library
");
1411 Put_Line (" -F Full project path name
" &
1412 "in brief error messages
");
1413 Put_Line (" -h Display this message
");
1414 Put_Line (" -n Nothing to
do: only list files to delete
");
1415 Put_Line (" -Pproj
Use GNAT Project File proj
");
1416 Put_Line (" -q Be quiet
/terse
");
1417 Put_Line (" -r Clean
all projects recursively
");
1418 Put_Line (" -v Verbose mode
");
1419 Put_Line (" -vPx Specify verbosity
when parsing
" &
1420 "GNAT Project Files
");
1421 Put_Line (" -Xnm
=val Specify an external reference
" &
1422 "for GNAT Project Files
");
1425 Put_Line (" -aOdir Specify ALI
/object files search path
");
1426 Put_Line (" -Idir Like
-aOdir
");
1427 Put_Line (" -I
- Don
't look
for source
/library files
" &
1428 "in the default directory
");
1434 if Hostparm.OpenVMS then
1435 Debug_Suffix (Debug_Suffix'First) := '_';
1436 Repinfo_Suffix (Repinfo_Suffix'First) := '_';
1437 B_Start (B_Start'Last) := '$';