* g++.dg/cpp0x/constexpr-53094-2.C: Ignore non-standard ABI
[official-gcc.git] / gcc / ada / clean.adb
blob560ceb7d33ee8b859acc39a2572e7b3ca8199884
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- C L E A N --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2003-2012, Free Software Foundation, Inc. --
10 -- --
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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with ALI; use ALI;
27 with Csets;
28 with Makeutl; use Makeutl;
29 with MLib.Tgt; use MLib.Tgt;
30 with Namet; use Namet;
31 with Opt; use Opt;
32 with Osint; use Osint;
33 with Osint.M; use Osint.M;
34 with Prj; use Prj;
35 with Prj.Env;
36 with Prj.Ext;
37 with Prj.Pars;
38 with Prj.Tree; use Prj.Tree;
39 with Prj.Util; use Prj.Util;
40 with Sdefault;
41 with Snames;
42 with Switch; use Switch;
43 with Table;
44 with Targparm; use Targparm;
45 with Types; use Types;
47 with Ada.Command_Line; use Ada.Command_Line;
49 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
50 with GNAT.IO; use GNAT.IO;
51 with GNAT.OS_Lib; use GNAT.OS_Lib;
53 package body Clean is
55 Initialized : Boolean := False;
56 -- Set to True by the first call to Initialize.
57 -- To avoid reinitialization of some packages.
59 -- Suffixes of various files
61 Assembly_Suffix : constant String := ".s";
62 ALI_Suffix : constant String := ".ali";
63 Tree_Suffix : constant String := ".adt";
64 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
65 Debug_Suffix : String := ".dg";
66 -- Changed to "_dg" for VMS in the body of the package
68 Repinfo_Suffix : String := ".rep";
69 -- Changed to "_rep" for VMS in the body of the package
71 B_Start : String_Ptr := new String'("b~");
72 -- Prefix of binder generated file, and number of actual characters used.
73 -- Changed to "b__" for VMS in the body of the package.
75 Project_Tree : constant Project_Tree_Ref :=
76 new Project_Tree_Data (Is_Root_Tree => True);
77 -- The project tree
79 Object_Directory_Path : String_Access := null;
80 -- The path name of the object directory, set with switch -D
82 Force_Deletions : Boolean := False;
83 -- Set to True by switch -f. When True, attempts to delete non writable
84 -- files will be done.
86 Do_Nothing : Boolean := False;
87 -- Set to True when switch -n is specified. When True, no file is deleted.
88 -- gnatclean only lists the files that would have been deleted if the
89 -- switch -n had not been specified.
91 File_Deleted : Boolean := False;
92 -- Set to True if at least one file has been deleted
94 Copyright_Displayed : Boolean := False;
95 Usage_Displayed : Boolean := False;
97 Project_File_Name : String_Access := null;
99 Project_Node_Tree : Project_Node_Tree_Ref;
101 Root_Environment : Prj.Tree.Environment;
103 Main_Project : Prj.Project_Id := Prj.No_Project;
105 All_Projects : Boolean := False;
107 -- Packages of project files where unknown attributes are errors
109 Naming_String : aliased String := "naming";
110 Builder_String : aliased String := "builder";
111 Compiler_String : aliased String := "compiler";
112 Binder_String : aliased String := "binder";
113 Linker_String : aliased String := "linker";
115 Gnatmake_Packages : aliased String_List :=
116 (Naming_String 'Access,
117 Builder_String 'Access,
118 Compiler_String 'Access,
119 Binder_String 'Access,
120 Linker_String 'Access);
122 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
123 Gnatmake_Packages'Access;
125 package Processed_Projects is new Table.Table
126 (Table_Component_Type => Project_Id,
127 Table_Index_Type => Natural,
128 Table_Low_Bound => 0,
129 Table_Initial => 10,
130 Table_Increment => 100,
131 Table_Name => "Clean.Processed_Projects");
132 -- Table to keep track of what project files have been processed, when
133 -- switch -r is specified.
135 package Sources is new Table.Table
136 (Table_Component_Type => File_Name_Type,
137 Table_Index_Type => Natural,
138 Table_Low_Bound => 0,
139 Table_Initial => 10,
140 Table_Increment => 100,
141 Table_Name => "Clean.Processed_Projects");
142 -- Table to store all the source files of a library unit: spec, body and
143 -- subunits, to detect .dg files and delete them.
145 -----------------------------
146 -- Other local subprograms --
147 -----------------------------
149 procedure Add_Source_Dir (N : String);
150 -- Call Add_Src_Search_Dir and output one line when in verbose mode
152 procedure Add_Source_Directories is
153 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
155 procedure Add_Object_Dir (N : String);
156 -- Call Add_Lib_Search_Dir and output one line when in verbose mode
158 procedure Add_Object_Directories is
159 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
161 function ALI_File_Name (Source : File_Name_Type) return String;
162 -- Returns the name of the ALI file corresponding to Source
164 function Assembly_File_Name (Source : File_Name_Type) return String;
165 -- Returns the assembly file name corresponding to Source
167 procedure Clean_Archive (Project : Project_Id; Global : Boolean);
168 -- Delete a global archive or library project archive and the dependency
169 -- file, if they exist.
171 procedure Clean_Executables;
172 -- Do the cleaning work when no project file is specified
174 procedure Clean_Interface_Copy_Directory (Project : Project_Id);
175 -- Delete files in an interface copy directory: any file that is a copy of
176 -- a source of the project.
178 procedure Clean_Library_Directory (Project : Project_Id);
179 -- Delete the library file in a library directory and any ALI file of a
180 -- source of the project in a library ALI directory.
182 procedure Clean_Project (Project : Project_Id);
183 -- Do the cleaning work when a project file is specified. This procedure
184 -- calls itself recursively when there are several project files in the
185 -- tree rooted at the main project file and switch -r has been specified.
187 function Debug_File_Name (Source : File_Name_Type) return String;
188 -- Name of the expanded source file corresponding to Source
190 procedure Delete (In_Directory : String; File : String);
191 -- Delete one file, or list the file name if switch -n is specified
193 procedure Delete_Binder_Generated_Files
194 (Dir : String;
195 Source : File_Name_Type);
196 -- Delete the binder generated file in directory Dir for Source, if they
197 -- exist: for Unix these are b~<source>.ads, b~<source>.adb,
198 -- b~<source>.ali and b~<source>.o.
200 procedure Display_Copyright;
201 -- Display the Copyright notice. If called several times, display the
202 -- Copyright notice only the first time.
204 procedure Initialize;
205 -- Call the necessary package initializations
207 function Object_File_Name (Source : File_Name_Type) return String;
208 -- Returns the object file name corresponding to Source
210 procedure Parse_Cmd_Line;
211 -- Parse the command line
213 function Repinfo_File_Name (Source : File_Name_Type) return String;
214 -- Returns the repinfo file name corresponding to Source
216 function Tree_File_Name (Source : File_Name_Type) return String;
217 -- Returns the tree file name corresponding to Source
219 function In_Extension_Chain
220 (Of_Project : Project_Id;
221 Prj : Project_Id) return Boolean;
222 -- Returns True iff Prj is an extension of Of_Project or if Of_Project is
223 -- an extension of Prj.
225 procedure Usage;
226 -- Display the usage. If called several times, the usage is displayed only
227 -- the first time.
229 --------------------
230 -- Add_Object_Dir --
231 --------------------
233 procedure Add_Object_Dir (N : String) is
234 begin
235 Add_Lib_Search_Dir (N);
237 if Opt.Verbose_Mode then
238 Put ("Adding object directory """);
239 Put (N);
240 Put (""".");
241 New_Line;
242 end if;
243 end Add_Object_Dir;
245 --------------------
246 -- Add_Source_Dir --
247 --------------------
249 procedure Add_Source_Dir (N : String) is
250 begin
251 Add_Src_Search_Dir (N);
253 if Opt.Verbose_Mode then
254 Put ("Adding source directory """);
255 Put (N);
256 Put (""".");
257 New_Line;
258 end if;
259 end Add_Source_Dir;
261 -------------------
262 -- ALI_File_Name --
263 -------------------
265 function ALI_File_Name (Source : File_Name_Type) return String is
266 Src : constant String := Get_Name_String (Source);
268 begin
269 -- If the source name has an extension, then replace it with
270 -- the ALI suffix.
272 for Index in reverse Src'First + 1 .. Src'Last loop
273 if Src (Index) = '.' then
274 return Src (Src'First .. Index - 1) & ALI_Suffix;
275 end if;
276 end loop;
278 -- If there is no dot, or if it is the first character, just add the
279 -- ALI suffix.
281 return Src & ALI_Suffix;
282 end ALI_File_Name;
284 ------------------------
285 -- Assembly_File_Name --
286 ------------------------
288 function Assembly_File_Name (Source : File_Name_Type) return String is
289 Src : constant String := Get_Name_String (Source);
291 begin
292 -- If the source name has an extension, then replace it with
293 -- the assembly suffix.
295 for Index in reverse Src'First + 1 .. Src'Last loop
296 if Src (Index) = '.' then
297 return Src (Src'First .. Index - 1) & Assembly_Suffix;
298 end if;
299 end loop;
301 -- If there is no dot, or if it is the first character, just add the
302 -- assembly suffix.
304 return Src & Assembly_Suffix;
305 end Assembly_File_Name;
307 -------------------
308 -- Clean_Archive --
309 -------------------
311 procedure Clean_Archive (Project : Project_Id; Global : Boolean) is
312 Current_Dir : constant Dir_Name_Str := Get_Current_Dir;
314 Lib_Prefix : String_Access;
315 Archive_Name : String_Access;
316 -- The name of the archive file for this project
318 Archive_Dep_Name : String_Access;
319 -- The name of the archive dependency file for this project
321 Obj_Dir : constant String :=
322 Get_Name_String (Project.Object_Directory.Display_Name);
324 begin
325 Change_Dir (Obj_Dir);
327 -- First, get the lib prefix, the archive file name and the archive
328 -- dependency file name.
330 if Global then
331 Lib_Prefix :=
332 new String'("lib" & Get_Name_String (Project.Display_Name));
333 else
334 Lib_Prefix :=
335 new String'("lib" & Get_Name_String (Project.Library_Name));
336 end if;
338 Archive_Name := new String'(Lib_Prefix.all & '.' & Archive_Ext);
339 Archive_Dep_Name := new String'(Lib_Prefix.all & ".deps");
341 -- Delete the archive file and the archive dependency file, if they
342 -- exist.
344 if Is_Regular_File (Archive_Name.all) then
345 Delete (Obj_Dir, Archive_Name.all);
346 end if;
348 if Is_Regular_File (Archive_Dep_Name.all) then
349 Delete (Obj_Dir, Archive_Dep_Name.all);
350 end if;
352 Change_Dir (Current_Dir);
353 end Clean_Archive;
355 -----------------------
356 -- Clean_Executables --
357 -----------------------
359 procedure Clean_Executables is
360 Main_Source_File : File_Name_Type;
361 -- Current main source
363 Main_Lib_File : File_Name_Type;
364 -- ALI file of the current main
366 Lib_File : File_Name_Type;
367 -- Current ALI file
369 Full_Lib_File : File_Name_Type;
370 -- Full name of the current ALI file
372 Text : Text_Buffer_Ptr;
373 The_ALI : ALI_Id;
374 Found : Boolean;
375 Source : Queue.Source_Info;
377 begin
378 Queue.Initialize (Queue_Per_Obj_Dir => False);
380 -- It does not really matter if there is or not an object file
381 -- corresponding to an ALI file: if there is one, it will be deleted.
383 Opt.Check_Object_Consistency := False;
385 -- Proceed each executable one by one. Each source is marked as it is
386 -- processed, so common sources between executables will not be
387 -- processed several times.
389 for N_File in 1 .. Osint.Number_Of_Files loop
390 Main_Source_File := Next_Main_Source;
391 Main_Lib_File :=
392 Osint.Lib_File_Name (Main_Source_File, Current_File_Index);
394 if Main_Lib_File /= No_File then
395 Queue.Insert
396 ((Format => Format_Gnatmake,
397 File => Main_Lib_File,
398 Unit => No_Unit_Name,
399 Index => 0,
400 Project => No_Project,
401 Sid => No_Source));
402 end if;
404 while not Queue.Is_Empty loop
405 Sources.Set_Last (0);
406 Queue.Extract (Found, Source);
407 pragma Assert (Found);
408 pragma Assert (Source.File /= No_File);
409 Lib_File := Source.File;
410 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
412 -- If we have existing ALI file that is not read-only, process it
414 if Full_Lib_File /= No_File
415 and then not Is_Readonly_Library (Full_Lib_File)
416 then
417 Text := Read_Library_Info (Lib_File);
419 if Text /= null then
420 The_ALI :=
421 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
422 Free (Text);
424 -- If no error was produced while loading this ALI file,
425 -- insert into the queue all the unmarked withed sources.
427 if The_ALI /= No_ALI_Id then
428 for J in ALIs.Table (The_ALI).First_Unit ..
429 ALIs.Table (The_ALI).Last_Unit
430 loop
431 Sources.Increment_Last;
432 Sources.Table (Sources.Last) :=
433 ALI.Units.Table (J).Sfile;
435 for K in ALI.Units.Table (J).First_With ..
436 ALI.Units.Table (J).Last_With
437 loop
438 if Withs.Table (K).Afile /= No_File then
439 Queue.Insert
440 ((Format => Format_Gnatmake,
441 File => Withs.Table (K).Afile,
442 Unit => No_Unit_Name,
443 Index => 0,
444 Project => No_Project,
445 Sid => No_Source));
446 end if;
447 end loop;
448 end loop;
450 -- Look for subunits and put them in the Sources table
452 for J in ALIs.Table (The_ALI).First_Sdep ..
453 ALIs.Table (The_ALI).Last_Sdep
454 loop
455 if Sdep.Table (J).Subunit_Name /= No_Name then
456 Sources.Increment_Last;
457 Sources.Table (Sources.Last) :=
458 Sdep.Table (J).Sfile;
459 end if;
460 end loop;
461 end if;
462 end if;
464 -- Now delete all existing files corresponding to this ALI file
466 declare
467 Obj_Dir : constant String :=
468 Dir_Name (Get_Name_String (Full_Lib_File));
469 Obj : constant String := Object_File_Name (Lib_File);
470 Adt : constant String := Tree_File_Name (Lib_File);
471 Asm : constant String := Assembly_File_Name (Lib_File);
473 begin
474 Delete (Obj_Dir, Get_Name_String (Lib_File));
476 if Is_Regular_File (Obj_Dir & Dir_Separator & Obj) then
477 Delete (Obj_Dir, Obj);
478 end if;
480 if Is_Regular_File (Obj_Dir & Dir_Separator & Adt) then
481 Delete (Obj_Dir, Adt);
482 end if;
484 if Is_Regular_File (Obj_Dir & Dir_Separator & Asm) then
485 Delete (Obj_Dir, Asm);
486 end if;
488 -- Delete expanded source files (.dg) and/or repinfo files
489 -- (.rep) if any
491 for J in 1 .. Sources.Last loop
492 declare
493 Deb : constant String :=
494 Debug_File_Name (Sources.Table (J));
495 Rep : constant String :=
496 Repinfo_File_Name (Sources.Table (J));
498 begin
499 if Is_Regular_File (Obj_Dir & Dir_Separator & Deb) then
500 Delete (Obj_Dir, Deb);
501 end if;
503 if Is_Regular_File (Obj_Dir & Dir_Separator & Rep) then
504 Delete (Obj_Dir, Rep);
505 end if;
506 end;
507 end loop;
508 end;
509 end if;
510 end loop;
512 -- Delete the executable, if it exists, and the binder generated
513 -- files, if any.
515 if not Compile_Only then
516 declare
517 Source : constant File_Name_Type :=
518 Strip_Suffix (Main_Lib_File);
519 Executable : constant String :=
520 Get_Name_String (Executable_Name (Source));
521 begin
522 if Is_Regular_File (Executable) then
523 Delete ("", Executable);
524 end if;
526 Delete_Binder_Generated_Files (Get_Current_Dir, Source);
527 end;
528 end if;
529 end loop;
530 end Clean_Executables;
532 ------------------------------------
533 -- Clean_Interface_Copy_Directory --
534 ------------------------------------
536 procedure Clean_Interface_Copy_Directory (Project : Project_Id) is
537 Current : constant String := Get_Current_Dir;
539 Direc : Dir_Type;
541 Name : String (1 .. 200);
542 Last : Natural;
544 Delete_File : Boolean;
545 Unit : Unit_Index;
547 begin
548 if Project.Library
549 and then Project.Library_Src_Dir /= No_Path_Information
550 then
551 declare
552 Directory : constant String :=
553 Get_Name_String (Project.Library_Src_Dir.Display_Name);
555 begin
556 Change_Dir (Directory);
557 Open (Direc, ".");
559 -- For each regular file in the directory, if switch -n has not
560 -- been specified, make it writable and delete the file if it is
561 -- a copy of a source of the project.
563 loop
564 Read (Direc, Name, Last);
565 exit when Last = 0;
567 declare
568 Filename : constant String := Name (1 .. Last);
570 begin
571 if Is_Regular_File (Filename) then
572 Canonical_Case_File_Name (Name (1 .. Last));
573 Delete_File := False;
575 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
577 -- Compare with source file names of the project
579 while Unit /= No_Unit_Index loop
580 if Unit.File_Names (Impl) /= null
581 and then Ultimate_Extending_Project_Of
582 (Unit.File_Names (Impl).Project) = Project
583 and then
584 Get_Name_String (Unit.File_Names (Impl).File) =
585 Name (1 .. Last)
586 then
587 Delete_File := True;
588 exit;
589 end if;
591 if Unit.File_Names (Spec) /= null
592 and then Ultimate_Extending_Project_Of
593 (Unit.File_Names (Spec).Project) = Project
594 and then
595 Get_Name_String
596 (Unit.File_Names (Spec).File) = Name (1 .. Last)
597 then
598 Delete_File := True;
599 exit;
600 end if;
602 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
603 end loop;
605 if Delete_File then
606 if not Do_Nothing then
607 Set_Writable (Filename);
608 end if;
610 Delete (Directory, Filename);
611 end if;
612 end if;
613 end;
614 end loop;
616 Close (Direc);
618 -- Restore the initial working directory
620 Change_Dir (Current);
621 end;
622 end if;
623 end Clean_Interface_Copy_Directory;
625 -----------------------------
626 -- Clean_Library_Directory --
627 -----------------------------
629 Empty_String : aliased String := "";
631 procedure Clean_Library_Directory (Project : Project_Id) is
632 Current : constant String := Get_Current_Dir;
634 Lib_Filename : constant String := Get_Name_String (Project.Library_Name);
635 DLL_Name : String :=
636 DLL_Prefix & Lib_Filename & "." & DLL_Ext;
637 Archive_Name : String :=
638 "lib" & Lib_Filename & "." & Archive_Ext;
639 Direc : Dir_Type;
641 Name : String (1 .. 200);
642 Last : Natural;
644 Delete_File : Boolean;
646 Minor : String_Access := Empty_String'Access;
647 Major : String_Access := Empty_String'Access;
649 begin
650 if Project.Library then
651 if Project.Library_Kind /= Static
652 and then MLib.Tgt.Library_Major_Minor_Id_Supported
653 and then Project.Lib_Internal_Name /= No_Name
654 then
655 Minor := new String'(Get_Name_String (Project.Lib_Internal_Name));
656 Major := new String'(MLib.Major_Id_Name (DLL_Name, Minor.all));
657 end if;
659 declare
660 Lib_Directory : constant String :=
661 Get_Name_String (Project.Library_Dir.Display_Name);
662 Lib_ALI_Directory : constant String :=
663 Get_Name_String (Project.Library_ALI_Dir.Display_Name);
665 begin
666 Canonical_Case_File_Name (Archive_Name);
667 Canonical_Case_File_Name (DLL_Name);
669 Change_Dir (Lib_Directory);
670 Open (Direc, ".");
672 -- For each regular file in the directory, if switch -n has not
673 -- been specified, make it writable and delete the file if it is
674 -- the library file.
676 loop
677 Read (Direc, Name, Last);
678 exit when Last = 0;
680 declare
681 Filename : constant String := Name (1 .. Last);
683 begin
684 if Is_Regular_File (Filename)
685 or else Is_Symbolic_Link (Filename)
686 then
687 Canonical_Case_File_Name (Name (1 .. Last));
688 Delete_File := False;
690 if (Project.Library_Kind = Static
691 and then Name (1 .. Last) = Archive_Name)
692 or else
693 ((Project.Library_Kind = Dynamic
694 or else
695 Project.Library_Kind = Relocatable)
696 and then
697 (Name (1 .. Last) = DLL_Name
698 or else
699 Name (1 .. Last) = Minor.all
700 or else
701 Name (1 .. Last) = Major.all))
702 then
703 if not Do_Nothing then
704 Set_Writable (Filename);
705 end if;
707 Delete (Lib_Directory, Filename);
708 end if;
709 end if;
710 end;
711 end loop;
713 Close (Direc);
715 Change_Dir (Lib_ALI_Directory);
716 Open (Direc, ".");
718 -- For each regular file in the directory, if switch -n has not
719 -- been specified, make it writable and delete the file if it is
720 -- any ALI file of a source of the project.
722 loop
723 Read (Direc, Name, Last);
724 exit when Last = 0;
726 declare
727 Filename : constant String := Name (1 .. Last);
728 begin
729 if Is_Regular_File (Filename) then
730 Canonical_Case_File_Name (Name (1 .. Last));
731 Delete_File := False;
733 if Last > 4 and then Name (Last - 3 .. Last) = ".ali" then
734 declare
735 Unit : Unit_Index;
736 begin
737 -- Compare with ALI file names of the project
739 Unit := Units_Htable.Get_First
740 (Project_Tree.Units_HT);
741 while Unit /= No_Unit_Index loop
742 if Unit.File_Names (Impl) /= null
743 and then Unit.File_Names (Impl).Project /=
744 No_Project
745 then
746 if Ultimate_Extending_Project_Of
747 (Unit.File_Names (Impl).Project) =
748 Project
749 then
750 Get_Name_String
751 (Unit.File_Names (Impl).File);
752 Name_Len := Name_Len -
753 File_Extension
754 (Name (1 .. Name_Len))'Length;
755 if Name_Buffer (1 .. Name_Len) =
756 Name (1 .. Last - 4)
757 then
758 Delete_File := True;
759 exit;
760 end if;
761 end if;
763 elsif Unit.File_Names (Spec) /= null
764 and then Ultimate_Extending_Project_Of
765 (Unit.File_Names (Spec).Project) =
766 Project
767 then
768 Get_Name_String
769 (Unit.File_Names (Spec).File);
770 Name_Len :=
771 Name_Len -
772 File_Extension
773 (Name (1 .. Name_Len))'Length;
775 if Name_Buffer (1 .. Name_Len) =
776 Name (1 .. Last - 4)
777 then
778 Delete_File := True;
779 exit;
780 end if;
781 end if;
783 Unit :=
784 Units_Htable.Get_Next (Project_Tree.Units_HT);
785 end loop;
786 end;
787 end if;
789 if Delete_File then
790 if not Do_Nothing then
791 Set_Writable (Filename);
792 end if;
794 Delete (Lib_ALI_Directory, Filename);
795 end if;
796 end if;
797 end;
798 end loop;
800 Close (Direc);
802 -- Restore the initial working directory
804 Change_Dir (Current);
805 end;
806 end if;
807 end Clean_Library_Directory;
809 -------------------
810 -- Clean_Project --
811 -------------------
813 procedure Clean_Project (Project : Project_Id) is
814 Main_Source_File : File_Name_Type;
815 -- Name of executable on the command line without directory info
817 Executable : File_Name_Type;
818 -- Name of the executable file
820 Current_Dir : constant Dir_Name_Str := Get_Current_Dir;
821 Unit : Unit_Index;
822 File_Name1 : File_Name_Type;
823 Index1 : Int;
824 File_Name2 : File_Name_Type;
825 Index2 : Int;
826 Lib_File : File_Name_Type;
828 Global_Archive : Boolean := False;
830 begin
831 -- Check that we don't specify executable on the command line for
832 -- a main library project.
834 if Project = Main_Project
835 and then Osint.Number_Of_Files /= 0
836 and then Project.Library
837 then
838 Osint.Fail
839 ("Cannot specify executable(s) for a Library Project File");
840 end if;
842 -- Nothing to clean in an externally built project
844 if Project.Externally_Built then
845 if Verbose_Mode then
846 Put ("Nothing to do to clean externally built project """);
847 Put (Get_Name_String (Project.Name));
848 Put_Line ("""");
849 end if;
851 else
852 if Verbose_Mode then
853 Put ("Cleaning project """);
854 Put (Get_Name_String (Project.Name));
855 Put_Line ("""");
856 end if;
858 -- Add project to the list of processed projects
860 Processed_Projects.Increment_Last;
861 Processed_Projects.Table (Processed_Projects.Last) := Project;
863 if Project.Object_Directory /= No_Path_Information then
864 declare
865 Obj_Dir : constant String :=
866 Get_Name_String (Project.Object_Directory.Display_Name);
868 begin
869 Change_Dir (Obj_Dir);
871 -- First, deal with Ada
873 -- Look through the units to find those that are either
874 -- immediate sources or inherited sources of the project.
875 -- Extending projects may have no language specified, if
876 -- Source_Dirs or Source_Files is specified as an empty list,
877 -- so always look for Ada units in extending projects.
879 if Has_Ada_Sources (Project)
880 or else Project.Extends /= No_Project
881 then
882 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
883 while Unit /= No_Unit_Index loop
884 File_Name1 := No_File;
885 File_Name2 := No_File;
887 -- If either the spec or the body is a source of the
888 -- project, check for the corresponding ALI file in the
889 -- object directory.
891 if (Unit.File_Names (Impl) /= null
892 and then
893 In_Extension_Chain
894 (Unit.File_Names (Impl).Project, Project))
895 or else
896 (Unit.File_Names (Spec) /= null
897 and then In_Extension_Chain
898 (Unit.File_Names (Spec).Project, Project))
899 then
900 if Unit.File_Names (Impl) /= null then
901 File_Name1 := Unit.File_Names (Impl).File;
902 Index1 := Unit.File_Names (Impl).Index;
903 else
904 File_Name1 := No_File;
905 Index1 := 0;
906 end if;
908 if Unit.File_Names (Spec) /= null then
909 File_Name2 := Unit.File_Names (Spec).File;
910 Index2 := Unit.File_Names (Spec).Index;
911 else
912 File_Name2 := No_File;
913 Index2 := 0;
914 end if;
916 -- If there is no body file name, then there may be
917 -- only a spec.
919 if File_Name1 = No_File then
920 File_Name1 := File_Name2;
921 Index1 := Index2;
922 File_Name2 := No_File;
923 Index2 := 0;
924 end if;
925 end if;
927 -- If there is either a spec or a body, look for files
928 -- in the object directory.
930 if File_Name1 /= No_File then
931 Lib_File := Osint.Lib_File_Name (File_Name1, Index1);
933 declare
934 Asm : constant String :=
935 Assembly_File_Name (Lib_File);
936 ALI : constant String :=
937 ALI_File_Name (Lib_File);
938 Obj : constant String :=
939 Object_File_Name (Lib_File);
940 Adt : constant String :=
941 Tree_File_Name (Lib_File);
942 Deb : constant String :=
943 Debug_File_Name (File_Name1);
944 Rep : constant String :=
945 Repinfo_File_Name (File_Name1);
946 Del : Boolean := True;
948 begin
949 -- If the ALI file exists and is read-only, no file
950 -- is deleted.
952 if Is_Regular_File (ALI) then
953 if Is_Writable_File (ALI) then
954 Delete (Obj_Dir, ALI);
956 else
957 Del := False;
959 if Verbose_Mode then
960 Put ('"');
961 Put (Obj_Dir);
963 if Obj_Dir (Obj_Dir'Last) /=
964 Dir_Separator
965 then
966 Put (Dir_Separator);
967 end if;
969 Put (ALI);
970 Put_Line (""" is read-only");
971 end if;
972 end if;
973 end if;
975 if Del then
977 -- Object file
979 if Is_Regular_File (Obj) then
980 Delete (Obj_Dir, Obj);
981 end if;
983 -- Assembly file
985 if Is_Regular_File (Asm) then
986 Delete (Obj_Dir, Asm);
987 end if;
989 -- Tree file
991 if Is_Regular_File (Adt) then
992 Delete (Obj_Dir, Adt);
993 end if;
995 -- First expanded source file
997 if Is_Regular_File (Deb) then
998 Delete (Obj_Dir, Deb);
999 end if;
1001 -- Repinfo file
1003 if Is_Regular_File (Rep) then
1004 Delete (Obj_Dir, Rep);
1005 end if;
1007 -- Second expanded source file
1009 if File_Name2 /= No_File then
1010 declare
1011 Deb : constant String :=
1012 Debug_File_Name (File_Name2);
1013 Rep : constant String :=
1014 Repinfo_File_Name (File_Name2);
1016 begin
1017 if Is_Regular_File (Deb) then
1018 Delete (Obj_Dir, Deb);
1019 end if;
1021 if Is_Regular_File (Rep) then
1022 Delete (Obj_Dir, Rep);
1023 end if;
1024 end;
1025 end if;
1026 end if;
1027 end;
1028 end if;
1030 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
1031 end loop;
1032 end if;
1034 -- Check if a global archive and it dependency file could have
1035 -- been created and, if they exist, delete them.
1037 if Project = Main_Project and then not Project.Library then
1038 Global_Archive := False;
1040 declare
1041 Proj : Project_List;
1043 begin
1044 Proj := Project_Tree.Projects;
1045 while Proj /= null loop
1047 -- For gnatmake, when the project specifies more than
1048 -- just Ada as a language (even if course we could not
1049 -- find any source file for the other languages), we
1050 -- will take all the object files found in the object
1051 -- directories. Since we know the project supports at
1052 -- least Ada, we just have to test whether it has at
1053 -- least two languages, and we do not care about the
1054 -- sources.
1056 if Proj.Project.Languages /= null
1057 and then Proj.Project.Languages.Next /= null
1058 then
1059 Global_Archive := True;
1060 exit;
1061 end if;
1063 Proj := Proj.Next;
1064 end loop;
1065 end;
1067 if Global_Archive then
1068 Clean_Archive (Project, Global => True);
1069 end if;
1070 end if;
1072 end;
1073 end if;
1075 -- If this is a library project, clean the library directory, the
1076 -- interface copy dir and, for a Stand-Alone Library, the binder
1077 -- generated files of the library.
1079 -- The directories are cleaned only if switch -c is not specified
1081 if Project.Library then
1082 if not Compile_Only then
1083 Clean_Library_Directory (Project);
1085 if Project.Library_Src_Dir /= No_Path_Information then
1086 Clean_Interface_Copy_Directory (Project);
1087 end if;
1088 end if;
1090 if Project.Standalone_Library /= No
1091 and then Project.Object_Directory /= No_Path_Information
1092 then
1093 Delete_Binder_Generated_Files
1094 (Get_Name_String (Project.Object_Directory.Display_Name),
1095 File_Name_Type (Project.Library_Name));
1096 end if;
1097 end if;
1099 if Verbose_Mode then
1100 New_Line;
1101 end if;
1102 end if;
1104 -- If switch -r is specified, call Clean_Project recursively for the
1105 -- imported projects and the project being extended.
1107 if All_Projects then
1108 declare
1109 Imported : Project_List;
1110 Process : Boolean;
1112 begin
1113 -- For each imported project, call Clean_Project if the project
1114 -- has not been processed already.
1116 Imported := Project.Imported_Projects;
1117 while Imported /= null loop
1118 Process := True;
1121 J in Processed_Projects.First .. Processed_Projects.Last
1122 loop
1123 if Imported.Project = Processed_Projects.Table (J) then
1124 Process := False;
1125 exit;
1126 end if;
1127 end loop;
1129 if Process then
1130 Clean_Project (Imported.Project);
1131 end if;
1133 Imported := Imported.Next;
1134 end loop;
1136 -- If this project extends another project, call Clean_Project for
1137 -- the project being extended. It is guaranteed that it has not
1138 -- called before, because no other project may import or extend
1139 -- this project.
1141 if Project.Extends /= No_Project then
1142 Clean_Project (Project.Extends);
1143 end if;
1144 end;
1145 end if;
1147 -- For the main project, delete the executables and the binder
1148 -- generated files.
1150 -- The executables are deleted only if switch -c is not specified
1152 if Project = Main_Project
1153 and then Project.Exec_Directory /= No_Path_Information
1154 then
1155 declare
1156 Exec_Dir : constant String :=
1157 Get_Name_String (Project.Exec_Directory.Display_Name);
1159 begin
1160 Change_Dir (Exec_Dir);
1162 for N_File in 1 .. Osint.Number_Of_Files loop
1163 Main_Source_File := Next_Main_Source;
1165 if not Compile_Only then
1166 Executable :=
1167 Executable_Of
1168 (Main_Project,
1169 Project_Tree.Shared,
1170 Main_Source_File,
1171 Current_File_Index);
1173 declare
1174 Exec_File_Name : constant String :=
1175 Get_Name_String (Executable);
1177 begin
1178 if Is_Absolute_Path (Name => Exec_File_Name) then
1179 if Is_Regular_File (Exec_File_Name) then
1180 Delete ("", Exec_File_Name);
1181 end if;
1183 else
1184 if Is_Regular_File (Exec_File_Name) then
1185 Delete (Exec_Dir, Exec_File_Name);
1186 end if;
1187 end if;
1188 end;
1189 end if;
1191 if Project.Object_Directory /= No_Path_Information then
1192 Delete_Binder_Generated_Files
1193 (Get_Name_String (Project.Object_Directory.Display_Name),
1194 Strip_Suffix (Main_Source_File));
1195 end if;
1196 end loop;
1197 end;
1198 end if;
1200 -- Change back to previous directory
1202 Change_Dir (Current_Dir);
1203 end Clean_Project;
1205 ---------------------
1206 -- Debug_File_Name --
1207 ---------------------
1209 function Debug_File_Name (Source : File_Name_Type) return String is
1210 begin
1211 return Get_Name_String (Source) & Debug_Suffix;
1212 end Debug_File_Name;
1214 ------------
1215 -- Delete --
1216 ------------
1218 procedure Delete (In_Directory : String; File : String) is
1219 Full_Name : String (1 .. In_Directory'Length + File'Length + 1);
1220 Last : Natural := 0;
1221 Success : Boolean;
1223 begin
1224 -- Indicate that at least one file is deleted or is to be deleted
1226 File_Deleted := True;
1228 -- Build the path name of the file to delete
1230 Last := In_Directory'Length;
1231 Full_Name (1 .. Last) := In_Directory;
1233 if Last > 0 and then Full_Name (Last) /= Directory_Separator then
1234 Last := Last + 1;
1235 Full_Name (Last) := Directory_Separator;
1236 end if;
1238 Full_Name (Last + 1 .. Last + File'Length) := File;
1239 Last := Last + File'Length;
1241 -- If switch -n was used, simply output the path name
1243 if Do_Nothing then
1244 Put_Line (Full_Name (1 .. Last));
1246 -- Otherwise, delete the file if it is writable
1248 else
1249 if Force_Deletions
1250 or else Is_Writable_File (Full_Name (1 .. Last))
1251 or else Is_Symbolic_Link (Full_Name (1 .. Last))
1252 then
1253 -- On VMS, we have to delete all versions of the file
1255 if OpenVMS_On_Target then
1256 Delete_File (Full_Name (1 .. Last) & ";*", Success);
1258 -- Otherwise just delete the specified file
1260 else
1261 Delete_File (Full_Name (1 .. Last), Success);
1262 end if;
1264 -- Here if no deletion required
1266 else
1267 Success := False;
1268 end if;
1270 if Verbose_Mode or else not Quiet_Output then
1271 if not Success then
1272 Put ("Warning: """);
1273 Put (Full_Name (1 .. Last));
1274 Put_Line (""" could not be deleted");
1276 else
1277 Put ("""");
1278 Put (Full_Name (1 .. Last));
1279 Put_Line (""" has been deleted");
1280 end if;
1281 end if;
1282 end if;
1283 end Delete;
1285 -----------------------------------
1286 -- Delete_Binder_Generated_Files --
1287 -----------------------------------
1289 procedure Delete_Binder_Generated_Files
1290 (Dir : String;
1291 Source : File_Name_Type)
1293 Source_Name : constant String := Get_Name_String (Source);
1294 Current : constant String := Get_Current_Dir;
1295 Last : constant Positive := B_Start'Length + Source_Name'Length;
1296 File_Name : String (1 .. Last + 4);
1298 begin
1299 Change_Dir (Dir);
1301 -- Build the file name (before the extension)
1303 File_Name (1 .. B_Start'Length) := B_Start.all;
1304 File_Name (B_Start'Length + 1 .. Last) := Source_Name;
1306 -- Spec
1308 File_Name (Last + 1 .. Last + 4) := ".ads";
1310 if Is_Regular_File (File_Name (1 .. Last + 4)) then
1311 Delete (Dir, File_Name (1 .. Last + 4));
1312 end if;
1314 -- Body
1316 File_Name (Last + 1 .. Last + 4) := ".adb";
1318 if Is_Regular_File (File_Name (1 .. Last + 4)) then
1319 Delete (Dir, File_Name (1 .. Last + 4));
1320 end if;
1322 -- ALI file
1324 File_Name (Last + 1 .. Last + 4) := ".ali";
1326 if Is_Regular_File (File_Name (1 .. Last + 4)) then
1327 Delete (Dir, File_Name (1 .. Last + 4));
1328 end if;
1330 -- Object file
1332 File_Name (Last + 1 .. Last + Object_Suffix'Length) := Object_Suffix;
1334 if Is_Regular_File (File_Name (1 .. Last + Object_Suffix'Length)) then
1335 Delete (Dir, File_Name (1 .. Last + Object_Suffix'Length));
1336 end if;
1338 -- Change back to previous directory
1340 Change_Dir (Current);
1341 end Delete_Binder_Generated_Files;
1343 -----------------------
1344 -- Display_Copyright --
1345 -----------------------
1347 procedure Display_Copyright is
1348 begin
1349 if not Copyright_Displayed then
1350 Copyright_Displayed := True;
1351 Display_Version ("GNATCLEAN", "2003");
1352 end if;
1353 end Display_Copyright;
1355 ---------------
1356 -- Gnatclean --
1357 ---------------
1359 procedure Gnatclean is
1360 begin
1361 -- Do the necessary initializations
1363 Clean.Initialize;
1365 -- Parse the command line, getting the switches and the executable names
1367 Parse_Cmd_Line;
1369 if Verbose_Mode then
1370 Display_Copyright;
1371 end if;
1373 if Project_File_Name /= null then
1375 -- A project file was specified by a -P switch
1377 if Opt.Verbose_Mode then
1378 New_Line;
1379 Put ("Parsing Project File """);
1380 Put (Project_File_Name.all);
1381 Put_Line (""".");
1382 New_Line;
1383 end if;
1385 -- Set the project parsing verbosity to whatever was specified
1386 -- by a possible -vP switch.
1388 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
1390 -- Parse the project file. If there is an error, Main_Project
1391 -- will still be No_Project.
1393 Prj.Pars.Parse
1394 (Project => Main_Project,
1395 In_Tree => Project_Tree,
1396 In_Node_Tree => Project_Node_Tree,
1397 Project_File_Name => Project_File_Name.all,
1398 Env => Root_Environment,
1399 Packages_To_Check => Packages_To_Check_By_Gnatmake);
1401 if Main_Project = No_Project then
1402 Fail ("""" & Project_File_Name.all & """ processing failed");
1403 end if;
1405 if Opt.Verbose_Mode then
1406 New_Line;
1407 Put ("Parsing of Project File """);
1408 Put (Project_File_Name.all);
1409 Put (""" is finished.");
1410 New_Line;
1411 end if;
1413 -- Add source directories and object directories to the search paths
1415 Add_Source_Directories (Main_Project, Project_Tree);
1416 Add_Object_Directories (Main_Project, Project_Tree);
1417 end if;
1419 Osint.Add_Default_Search_Dirs;
1421 -- If a project file was specified, but no executable name, put all
1422 -- the mains of the project file (if any) as if there were on the
1423 -- command line.
1425 if Main_Project /= No_Project and then Osint.Number_Of_Files = 0 then
1426 declare
1427 Main : String_Element;
1428 Value : String_List_Id := Main_Project.Mains;
1429 begin
1430 while Value /= Prj.Nil_String loop
1431 Main := Project_Tree.Shared.String_Elements.Table (Value);
1432 Osint.Add_File
1433 (File_Name => Get_Name_String (Main.Value),
1434 Index => Main.Index);
1435 Value := Main.Next;
1436 end loop;
1437 end;
1438 end if;
1440 -- If neither a project file nor an executable were specified, output
1441 -- the usage and exit.
1443 if Main_Project = No_Project and then Osint.Number_Of_Files = 0 then
1444 Usage;
1445 return;
1446 end if;
1448 if Verbose_Mode then
1449 New_Line;
1450 end if;
1452 if Main_Project /= No_Project then
1454 -- If a project file has been specified, call Clean_Project with the
1455 -- project id of this project file, after resetting the list of
1456 -- processed projects.
1458 Processed_Projects.Init;
1459 Clean_Project (Main_Project);
1461 else
1462 -- If no project file has been specified, the work is done in
1463 -- Clean_Executables.
1465 Clean_Executables;
1466 end if;
1468 -- In verbose mode, if Delete has not been called, indicate that no file
1469 -- needs to be deleted.
1471 if Verbose_Mode and (not File_Deleted) then
1472 New_Line;
1474 if Do_Nothing then
1475 Put_Line ("No file needs to be deleted");
1476 else
1477 Put_Line ("No file has been deleted");
1478 end if;
1479 end if;
1480 end Gnatclean;
1482 ------------------------
1483 -- In_Extension_Chain --
1484 ------------------------
1486 function In_Extension_Chain
1487 (Of_Project : Project_Id;
1488 Prj : Project_Id) return Boolean
1490 Proj : Project_Id;
1492 begin
1493 if Prj = No_Project or else Of_Project = No_Project then
1494 return False;
1495 end if;
1497 if Of_Project = Prj then
1498 return True;
1499 end if;
1501 Proj := Of_Project;
1502 while Proj.Extends /= No_Project loop
1503 if Proj.Extends = Prj then
1504 return True;
1505 end if;
1507 Proj := Proj.Extends;
1508 end loop;
1510 Proj := Prj;
1511 while Proj.Extends /= No_Project loop
1512 if Proj.Extends = Of_Project then
1513 return True;
1514 end if;
1516 Proj := Proj.Extends;
1517 end loop;
1519 return False;
1520 end In_Extension_Chain;
1522 ----------------
1523 -- Initialize --
1524 ----------------
1526 procedure Initialize is
1527 begin
1528 if not Initialized then
1529 Initialized := True;
1531 -- Get default search directories to locate system.ads when calling
1532 -- Targparm.Get_Target_Parameters.
1534 Osint.Add_Default_Search_Dirs;
1536 -- Initialize some packages
1538 Csets.Initialize;
1539 Snames.Initialize;
1541 Prj.Tree.Initialize (Root_Environment, Gnatmake_Flags);
1542 Prj.Env.Initialize_Default_Project_Path
1543 (Root_Environment.Project_Path,
1544 Target_Name => Sdefault.Target_Name.all);
1546 Project_Node_Tree := new Project_Node_Tree_Data;
1547 Prj.Tree.Initialize (Project_Node_Tree);
1549 Prj.Initialize (Project_Tree);
1551 -- Check if the platform is VMS and, if it is, change some variables
1553 Targparm.Get_Target_Parameters;
1555 if OpenVMS_On_Target then
1556 Debug_Suffix (Debug_Suffix'First) := '_';
1557 Repinfo_Suffix (Repinfo_Suffix'First) := '_';
1558 B_Start := new String'("b__");
1559 end if;
1560 end if;
1562 -- Reset global variables
1564 Free (Object_Directory_Path);
1565 Do_Nothing := False;
1566 File_Deleted := False;
1567 Copyright_Displayed := False;
1568 Usage_Displayed := False;
1569 Free (Project_File_Name);
1570 Main_Project := Prj.No_Project;
1571 All_Projects := False;
1572 end Initialize;
1574 ----------------------
1575 -- Object_File_Name --
1576 ----------------------
1578 function Object_File_Name (Source : File_Name_Type) return String is
1579 Src : constant String := Get_Name_String (Source);
1581 begin
1582 -- If the source name has an extension, then replace it with
1583 -- the Object suffix.
1585 for Index in reverse Src'First + 1 .. Src'Last loop
1586 if Src (Index) = '.' then
1587 return Src (Src'First .. Index - 1) & Object_Suffix;
1588 end if;
1589 end loop;
1591 -- If there is no dot, or if it is the first character, just add the
1592 -- ALI suffix.
1594 return Src & Object_Suffix;
1595 end Object_File_Name;
1597 --------------------
1598 -- Parse_Cmd_Line --
1599 --------------------
1601 procedure Parse_Cmd_Line is
1602 Last : constant Natural := Argument_Count;
1603 Source_Index : Int := 0;
1604 Index : Positive;
1606 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
1608 begin
1609 -- First, check for --version and --help
1611 Check_Version_And_Help ("GNATCLEAN", "2003");
1613 Index := 1;
1614 while Index <= Last loop
1615 declare
1616 Arg : constant String := Argument (Index);
1618 procedure Bad_Argument;
1619 -- Signal bad argument
1621 ------------------
1622 -- Bad_Argument --
1623 ------------------
1625 procedure Bad_Argument is
1626 begin
1627 Fail ("invalid argument """ & Arg & """");
1628 end Bad_Argument;
1630 begin
1631 if Arg'Length /= 0 then
1632 if Arg (1) = '-' then
1633 if Arg'Length = 1 then
1634 Bad_Argument;
1635 end if;
1637 case Arg (2) is
1638 when '-' =>
1639 if Arg'Length > Subdirs_Option'Length and then
1640 Arg (1 .. Subdirs_Option'Length) = Subdirs_Option
1641 then
1642 Subdirs :=
1643 new String'
1644 (Arg (Subdirs_Option'Length + 1 .. Arg'Last));
1646 elsif Arg = Makeutl.Unchecked_Shared_Lib_Imports then
1647 Opt.Unchecked_Shared_Lib_Imports := True;
1649 else
1650 Bad_Argument;
1651 end if;
1653 when 'a' =>
1654 if Arg'Length < 4 then
1655 Bad_Argument;
1656 end if;
1658 if Arg (3) = 'O' then
1659 Add_Lib_Search_Dir (Arg (4 .. Arg'Last));
1661 elsif Arg (3) = 'P' then
1662 Prj.Env.Add_Directories
1663 (Root_Environment.Project_Path,
1664 Arg (4 .. Arg'Last));
1666 else
1667 Bad_Argument;
1668 end if;
1670 when 'c' =>
1671 Compile_Only := True;
1673 when 'D' =>
1674 if Object_Directory_Path /= null then
1675 Fail ("duplicate -D switch");
1677 elsif Project_File_Name /= null then
1678 Fail ("-P and -D cannot be used simultaneously");
1679 end if;
1681 if Arg'Length > 2 then
1682 declare
1683 Dir : constant String := Arg (3 .. Arg'Last);
1684 begin
1685 if not Is_Directory (Dir) then
1686 Fail (Dir & " is not a directory");
1687 else
1688 Add_Lib_Search_Dir (Dir);
1689 end if;
1690 end;
1692 else
1693 if Index = Last then
1694 Fail ("no directory specified after -D");
1695 end if;
1697 Index := Index + 1;
1699 declare
1700 Dir : constant String := Argument (Index);
1701 begin
1702 if not Is_Directory (Dir) then
1703 Fail (Dir & " is not a directory");
1704 else
1705 Add_Lib_Search_Dir (Dir);
1706 end if;
1707 end;
1708 end if;
1710 when 'e' =>
1711 if Arg = "-eL" then
1712 Follow_Links_For_Files := True;
1713 Follow_Links_For_Dirs := True;
1715 else
1716 Bad_Argument;
1717 end if;
1719 when 'f' =>
1720 Force_Deletions := True;
1722 when 'F' =>
1723 Full_Path_Name_For_Brief_Errors := True;
1725 when 'h' =>
1726 Usage;
1728 when 'i' =>
1729 if Arg'Length = 2 then
1730 Bad_Argument;
1731 end if;
1733 Source_Index := 0;
1735 for J in 3 .. Arg'Last loop
1736 if Arg (J) not in '0' .. '9' then
1737 Bad_Argument;
1738 end if;
1740 Source_Index :=
1741 (20 * Source_Index) +
1742 (Character'Pos (Arg (J)) - Character'Pos ('0'));
1743 end loop;
1745 when 'I' =>
1746 if Arg = "-I-" then
1747 Opt.Look_In_Primary_Dir := False;
1749 else
1750 if Arg'Length = 2 then
1751 Bad_Argument;
1752 end if;
1754 Add_Lib_Search_Dir (Arg (3 .. Arg'Last));
1755 end if;
1757 when 'n' =>
1758 Do_Nothing := True;
1760 when 'P' =>
1761 if Project_File_Name /= null then
1762 Fail ("multiple -P switches");
1764 elsif Object_Directory_Path /= null then
1765 Fail ("-D and -P cannot be used simultaneously");
1767 end if;
1769 if Arg'Length > 2 then
1770 declare
1771 Prj : constant String := Arg (3 .. Arg'Last);
1772 begin
1773 if Prj'Length > 1 and then
1774 Prj (Prj'First) = '='
1775 then
1776 Project_File_Name :=
1777 new String'
1778 (Prj (Prj'First + 1 .. Prj'Last));
1779 else
1780 Project_File_Name := new String'(Prj);
1781 end if;
1782 end;
1784 else
1785 if Index = Last then
1786 Fail ("no project specified after -P");
1787 end if;
1789 Index := Index + 1;
1790 Project_File_Name := new String'(Argument (Index));
1791 end if;
1793 when 'q' =>
1794 Quiet_Output := True;
1796 when 'r' =>
1797 All_Projects := True;
1799 when 'v' =>
1800 if Arg = "-v" then
1801 Verbose_Mode := True;
1803 elsif Arg = "-vP0" then
1804 Current_Verbosity := Prj.Default;
1806 elsif Arg = "-vP1" then
1807 Current_Verbosity := Prj.Medium;
1809 elsif Arg = "-vP2" then
1810 Current_Verbosity := Prj.High;
1812 else
1813 Bad_Argument;
1814 end if;
1816 when 'X' =>
1817 if Arg'Length = 2 then
1818 Bad_Argument;
1819 end if;
1821 declare
1822 Ext_Asgn : constant String := Arg (3 .. Arg'Last);
1823 Start : Positive := Ext_Asgn'First;
1824 Stop : Natural := Ext_Asgn'Last;
1825 OK : Boolean := True;
1827 begin
1828 if Ext_Asgn (Start) = '"' then
1829 if Ext_Asgn (Stop) = '"' then
1830 Start := Start + 1;
1831 Stop := Stop - 1;
1833 else
1834 OK := False;
1835 end if;
1836 end if;
1838 if not OK
1839 or else not
1840 Prj.Ext.Check (Root_Environment.External,
1841 Ext_Asgn (Start .. Stop))
1842 then
1843 Fail
1844 ("illegal external assignment '"
1845 & Ext_Asgn
1846 & "'");
1847 end if;
1848 end;
1850 when others =>
1851 Bad_Argument;
1852 end case;
1854 else
1855 Add_File (Arg, Source_Index);
1856 end if;
1857 end if;
1858 end;
1860 Index := Index + 1;
1861 end loop;
1862 end Parse_Cmd_Line;
1864 -----------------------
1865 -- Repinfo_File_Name --
1866 -----------------------
1868 function Repinfo_File_Name (Source : File_Name_Type) return String is
1869 begin
1870 return Get_Name_String (Source) & Repinfo_Suffix;
1871 end Repinfo_File_Name;
1873 --------------------
1874 -- Tree_File_Name --
1875 --------------------
1877 function Tree_File_Name (Source : File_Name_Type) return String is
1878 Src : constant String := Get_Name_String (Source);
1880 begin
1881 -- If source name has an extension, then replace it with the tree suffix
1883 for Index in reverse Src'First + 1 .. Src'Last loop
1884 if Src (Index) = '.' then
1885 return Src (Src'First .. Index - 1) & Tree_Suffix;
1886 end if;
1887 end loop;
1889 -- If there is no dot, or if it is the first character, just add the
1890 -- tree suffix.
1892 return Src & Tree_Suffix;
1893 end Tree_File_Name;
1895 -----------
1896 -- Usage --
1897 -----------
1899 procedure Usage is
1900 begin
1901 if not Usage_Displayed then
1902 Usage_Displayed := True;
1903 Display_Copyright;
1904 Put_Line ("Usage: gnatclean [switches] {[-innn] name}");
1905 New_Line;
1907 Display_Usage_Version_And_Help;
1909 Put_Line (" names is one or more file names from which " &
1910 "the .adb or .ads suffix may be omitted");
1911 Put_Line (" names may be omitted if -P<project> is specified");
1912 New_Line;
1914 Put_Line (" --subdirs=dir real obj/lib/exec dirs are subdirs");
1915 Put_Line (" " & Makeutl.Unchecked_Shared_Lib_Imports);
1916 Put_Line (" Allow shared libraries to import static libraries");
1917 New_Line;
1919 Put_Line (" -c Only delete compiler generated files");
1920 Put_Line (" -D dir Specify dir as the object library");
1921 Put_Line (" -eL Follow symbolic links when processing " &
1922 "project files");
1923 Put_Line (" -f Force deletions of unwritable files");
1924 Put_Line (" -F Full project path name " &
1925 "in brief error messages");
1926 Put_Line (" -h Display this message");
1927 Put_Line (" -innn Index of unit in source for following names");
1928 Put_Line (" -n Nothing to do: only list files to delete");
1929 Put_Line (" -Pproj Use GNAT Project File proj");
1930 Put_Line (" -q Be quiet/terse");
1931 Put_Line (" -r Clean all projects recursively");
1932 Put_Line (" -v Verbose mode");
1933 Put_Line (" -vPx Specify verbosity when parsing " &
1934 "GNAT Project Files");
1935 Put_Line (" -Xnm=val Specify an external reference " &
1936 "for GNAT Project Files");
1937 New_Line;
1939 Put_Line (" -aPdir Add directory dir to project search path");
1940 New_Line;
1942 Put_Line (" -aOdir Specify ALI/object files search path");
1943 Put_Line (" -Idir Like -aOdir");
1944 Put_Line (" -I- Don't look for source/library files " &
1945 "in the default directory");
1946 New_Line;
1947 end if;
1948 end Usage;
1950 end Clean;