1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2003 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 ------------------------------------------------------------------------------
27 -- This utility application creates symbol files in a format that is
28 -- platform-dependent.
30 -- A symbol file is a text file that lists the symbols to be exported from
31 -- a shared library. The format of a symbol file depends on the platform;
32 -- it may be a simple enumeration of the symbol (one per line) or a more
33 -- elaborate format (on VMS, for example). A symbol file may be used as an
34 -- input to the platform linker when building a shared library.
36 -- This utility is not available on all platforms. It is currently supported
39 -- gnatsym takes as parameters:
40 -- - the name of the symbol file to create or update
41 -- - the names of one or more object files where the symbols are found
43 with GNAT.Command_Line; use GNAT.Command_Line;
44 with GNAT.OS_Lib; use GNAT.OS_Lib;
46 with Gnatvsn; use Gnatvsn;
47 with Osint; use Osint;
48 with Output; use Output;
50 with Symbols; use Symbols;
55 Copyright_Displayed : Boolean := False;
56 -- A flag to prevent multiple display of the Copyright notice
58 Success : Boolean := True;
60 Force : Boolean := False;
61 -- True when -f switcxh is used
63 Verbose : Boolean := False;
64 -- True when -v switch is used
66 Quiet : Boolean := False;
67 -- True when -q switch is used
69 Symbol_File_Name : String_Access;
70 -- The name of the symbol file
72 package Object_Files is new Table.Table
73 (Table_Component_Type => String_Access,
74 Table_Index_Type => Natural,
77 Table_Increment => 10,
78 Table_Name => "Gnatsymb.Object_Files");
79 -- A table to store the object file names
81 Object_File : Natural := 0;
82 -- An index to traverse the Object_Files table
84 procedure Display_Copyright;
85 -- Display Copyright notice
87 procedure Parse_Cmd_Line;
88 -- Parse the command line switches and file names
93 -----------------------
94 -- Display_Copyright --
95 -----------------------
97 procedure Display_Copyright is
99 if not Copyright_Displayed then
101 Write_Str ("GNATSYMB ");
102 Write_Str (Gnat_Version_String);
103 Write_Str (" Copyright 2003 Free Software Foundation, Inc");
105 Copyright_Displayed := True;
107 end Display_Copyright;
113 procedure Parse_Cmd_Line is
116 case GNAT.Command_Line.Getopt ("f q v") is
130 Fail ("invalid switch: ", Full_Switch);
134 -- Get the file names
138 S : constant String_Access :=
139 new String'(GNAT.Command_Line.Get_Argument);
142 exit when S'Length = 0;
144 if Symbol_File_Name = null then
145 Symbol_File_Name := S;
148 Object_Files.Increment_Last;
149 Object_Files.Table (Object_Files.Last) := S;
154 when Invalid_Switch =>
156 Fail ("invalid switch : ", Full_Switch);
165 Write_Line ("gnatsym [options] sym_file object_file {object_file}");
167 Write_Line (" -f Force generation of symbol file");
168 Write_Line (" -q Quiet mode");
169 Write_Line (" -v Verbose mode");
173 -- Start of processing of Gnatsym
176 -- Initialize Object_Files table
178 Object_Files.Set_Last (0);
180 -- Parse the command line
188 -- If there is no symbol file or no object files on the command line,
189 -- display the usage and exit with an error status.
191 if Object_Files.Last = 0 then
197 Write_Str ("Initializing symbol file """);
198 Write_Str (Symbol_File_Name.all);
202 -- Initialize the symbol file
204 Symbols.Initialize (Symbol_File_Name.all, Force, Quiet, Success);
206 -- Process the object files in order. Stop as soon as there is
211 while Success and then Object_File < Object_Files.Last loop
212 Object_File := Object_File + 1;
215 Write_Str ("Processing object file """);
216 Write_Str (Object_Files.Table (Object_File).all);
220 Process (Object_Files.Table (Object_File).all, Success);
223 -- Finalize the object file
227 Write_Str ("Finalizing """);
228 Write_Str (Symbol_File_Name.all);
232 Finalize (Quiet, Success);
236 Fail ("unable to build symbol file");