]>
Commit | Line | Data |
---|---|---|
fbf5a39b AC |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- G N A T S Y M -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
9de61fcb | 9 | -- Copyright (C) 2003-2005, Free Software Foundation, Inc. -- |
fbf5a39b AC |
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 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 -- | |
cb5fee25 KC |
19 | -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, -- |
20 | -- Boston, MA 02110-1301, USA. -- | |
fbf5a39b AC |
21 | -- -- |
22 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
23 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- | |
24 | -- -- | |
25 | ------------------------------------------------------------------------------ | |
26 | ||
27 | -- This utility application creates symbol files in a format that is | |
28 | -- platform-dependent. | |
29 | ||
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. | |
35 | ||
36 | -- This utility is not available on all platforms. It is currently supported | |
37 | -- only on OpenVMS. | |
38 | ||
39 | -- gnatsym takes as parameters: | |
19f0526a AC |
40 | -- - the name of the symbol file to create |
41 | -- - (optional) the policy to create the symbol file | |
42 | -- - (optional) the name of the reference symbol file | |
fbf5a39b AC |
43 | -- - the names of one or more object files where the symbols are found |
44 | ||
45 | with GNAT.Command_Line; use GNAT.Command_Line; | |
46 | with GNAT.OS_Lib; use GNAT.OS_Lib; | |
47 | ||
48 | with Gnatvsn; use Gnatvsn; | |
49 | with Osint; use Osint; | |
50 | with Output; use Output; | |
51 | ||
52 | with Symbols; use Symbols; | |
53 | with Table; | |
54 | ||
55 | procedure Gnatsym is | |
56 | ||
19f0526a | 57 | Empty_String : aliased String := ""; |
91b1417d | 58 | Empty : constant String_Access := Empty_String'Unchecked_Access; |
19f0526a AC |
59 | -- To initialize variables Reference and Version_String |
60 | ||
fbf5a39b AC |
61 | Copyright_Displayed : Boolean := False; |
62 | -- A flag to prevent multiple display of the Copyright notice | |
63 | ||
64 | Success : Boolean := True; | |
65 | ||
19f0526a | 66 | Symbol_Policy : Policy := Autonomous; |
fbf5a39b AC |
67 | |
68 | Verbose : Boolean := False; | |
69 | -- True when -v switch is used | |
70 | ||
71 | Quiet : Boolean := False; | |
72 | -- True when -q switch is used | |
73 | ||
19f0526a | 74 | Symbol_File_Name : String_Access := null; |
fbf5a39b AC |
75 | -- The name of the symbol file |
76 | ||
19f0526a AC |
77 | Reference_Symbol_File_Name : String_Access := Empty; |
78 | -- The name of the reference symbol file | |
79 | ||
80 | Version_String : String_Access := Empty; | |
9de61fcb | 81 | -- The version of the library (used on VMS) |
19f0526a | 82 | |
fbf5a39b AC |
83 | package Object_Files is new Table.Table |
84 | (Table_Component_Type => String_Access, | |
85 | Table_Index_Type => Natural, | |
86 | Table_Low_Bound => 0, | |
87 | Table_Initial => 10, | |
88 | Table_Increment => 10, | |
89 | Table_Name => "Gnatsymb.Object_Files"); | |
90 | -- A table to store the object file names | |
91 | ||
92 | Object_File : Natural := 0; | |
93 | -- An index to traverse the Object_Files table | |
94 | ||
95 | procedure Display_Copyright; | |
96 | -- Display Copyright notice | |
97 | ||
98 | procedure Parse_Cmd_Line; | |
99 | -- Parse the command line switches and file names | |
100 | ||
101 | procedure Usage; | |
102 | -- Display the usage | |
103 | ||
104 | ----------------------- | |
105 | -- Display_Copyright -- | |
106 | ----------------------- | |
107 | ||
108 | procedure Display_Copyright is | |
109 | begin | |
110 | if not Copyright_Displayed then | |
111 | Write_Eol; | |
112 | Write_Str ("GNATSYMB "); | |
113 | Write_Str (Gnat_Version_String); | |
5f8abbd9 AC |
114 | Write_Eol; |
115 | Write_Str ("Copyright 2003-2004 Free Software Foundation, Inc"); | |
fbf5a39b AC |
116 | Write_Eol; |
117 | Copyright_Displayed := True; | |
118 | end if; | |
119 | end Display_Copyright; | |
120 | ||
121 | -------------------- | |
122 | -- Parse_Cmd_Line -- | |
123 | -------------------- | |
124 | ||
125 | procedure Parse_Cmd_Line is | |
126 | begin | |
127 | loop | |
5453d5bd | 128 | case GNAT.Command_Line.Getopt ("c C q r: R s: v V:") is |
fbf5a39b AC |
129 | when ASCII.NUL => |
130 | exit; | |
131 | ||
19f0526a AC |
132 | when 'c' => |
133 | Symbol_Policy := Compliant; | |
134 | ||
135 | when 'C' => | |
136 | Symbol_Policy := Controlled; | |
fbf5a39b AC |
137 | |
138 | when 'q' => | |
139 | Quiet := True; | |
140 | ||
19f0526a AC |
141 | when 'r' => |
142 | Reference_Symbol_File_Name := | |
143 | new String'(GNAT.Command_Line.Parameter); | |
144 | ||
5453d5bd AC |
145 | when 'R' => |
146 | Symbol_Policy := Restricted; | |
147 | ||
19f0526a AC |
148 | when 's' => |
149 | Symbol_File_Name := new String'(GNAT.Command_Line.Parameter); | |
150 | ||
fbf5a39b AC |
151 | when 'v' => |
152 | Verbose := True; | |
153 | ||
19f0526a AC |
154 | when 'V' => |
155 | Version_String := new String'(GNAT.Command_Line.Parameter); | |
156 | ||
fbf5a39b AC |
157 | when others => |
158 | Fail ("invalid switch: ", Full_Switch); | |
159 | end case; | |
160 | end loop; | |
161 | ||
162 | -- Get the file names | |
163 | ||
164 | loop | |
165 | declare | |
166 | S : constant String_Access := | |
167 | new String'(GNAT.Command_Line.Get_Argument); | |
168 | ||
169 | begin | |
170 | exit when S'Length = 0; | |
171 | ||
19f0526a AC |
172 | Object_Files.Increment_Last; |
173 | Object_Files.Table (Object_Files.Last) := S; | |
fbf5a39b AC |
174 | end; |
175 | end loop; | |
176 | exception | |
177 | when Invalid_Switch => | |
178 | Usage; | |
179 | Fail ("invalid switch : ", Full_Switch); | |
180 | end Parse_Cmd_Line; | |
181 | ||
182 | ----------- | |
183 | -- Usage -- | |
184 | ----------- | |
185 | ||
186 | procedure Usage is | |
187 | begin | |
19f0526a | 188 | Write_Line ("gnatsym [options] object_file {object_file}"); |
fbf5a39b | 189 | Write_Eol; |
5453d5bd AC |
190 | Write_Line (" -c Compliant symbol policy"); |
191 | Write_Line (" -C Controlled symbol policy"); | |
19f0526a AC |
192 | Write_Line (" -q Quiet mode"); |
193 | Write_Line (" -r<ref> Reference symbol file name"); | |
5453d5bd | 194 | Write_Line (" -R Restricted symbol policy"); |
19f0526a AC |
195 | Write_Line (" -s<sym> Symbol file name"); |
196 | Write_Line (" -v Verbose mode"); | |
197 | Write_Line (" -V<ver> Version"); | |
198 | Write_Eol; | |
199 | Write_Line ("Specifying a symbol file with -s<sym> is compulsory"); | |
fbf5a39b AC |
200 | Write_Eol; |
201 | end Usage; | |
202 | ||
203 | -- Start of processing of Gnatsym | |
204 | ||
205 | begin | |
206 | -- Initialize Object_Files table | |
207 | ||
208 | Object_Files.Set_Last (0); | |
209 | ||
210 | -- Parse the command line | |
211 | ||
212 | Parse_Cmd_Line; | |
213 | ||
214 | if Verbose then | |
215 | Display_Copyright; | |
216 | end if; | |
217 | ||
218 | -- If there is no symbol file or no object files on the command line, | |
219 | -- display the usage and exit with an error status. | |
220 | ||
19f0526a | 221 | if Symbol_File_Name = null or else Object_Files.Last = 0 then |
fbf5a39b AC |
222 | Usage; |
223 | OS_Exit (1); | |
224 | ||
225 | else | |
226 | if Verbose then | |
227 | Write_Str ("Initializing symbol file """); | |
228 | Write_Str (Symbol_File_Name.all); | |
229 | Write_Line (""""); | |
230 | end if; | |
231 | ||
91b1417d | 232 | -- Initialize symbol file and, if specified, read reference file |
fbf5a39b | 233 | |
19f0526a AC |
234 | Symbols.Initialize |
235 | (Symbol_File => Symbol_File_Name.all, | |
236 | Reference => Reference_Symbol_File_Name.all, | |
237 | Symbol_Policy => Symbol_Policy, | |
238 | Quiet => Quiet, | |
239 | Version => Version_String.all, | |
240 | Success => Success); | |
fbf5a39b AC |
241 | |
242 | -- Process the object files in order. Stop as soon as there is | |
243 | -- something wrong. | |
244 | ||
245 | Object_File := 0; | |
246 | ||
247 | while Success and then Object_File < Object_Files.Last loop | |
248 | Object_File := Object_File + 1; | |
249 | ||
250 | if Verbose then | |
251 | Write_Str ("Processing object file """); | |
252 | Write_Str (Object_Files.Table (Object_File).all); | |
253 | Write_Line (""""); | |
254 | end if; | |
255 | ||
65b10832 | 256 | Processing.Process (Object_Files.Table (Object_File).all, Success); |
fbf5a39b AC |
257 | end loop; |
258 | ||
259 | -- Finalize the object file | |
260 | ||
261 | if Success then | |
262 | if Verbose then | |
263 | Write_Str ("Finalizing """); | |
264 | Write_Str (Symbol_File_Name.all); | |
265 | Write_Line (""""); | |
266 | end if; | |
267 | ||
268 | Finalize (Quiet, Success); | |
269 | end if; | |
270 | ||
19f0526a AC |
271 | -- Fail if there was anything wrong |
272 | ||
fbf5a39b AC |
273 | if not Success then |
274 | Fail ("unable to build symbol file"); | |
275 | end if; | |
276 | end if; | |
277 | end Gnatsym; |