Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[oweals/cde.git] / util / elistgen.sun
1 XCOMM!/bin/sh -f
2 XCOMM $TOG: elistgen.sun /main/9 1999/09/07 17:54:17 mgreess $
3 XCOMM
4 XCOMM ########################################################################
5 XCOMM Construct shared-library scoping mapfile for Solaris based on standardized
6 XCOMM export list description file
7 XCOMM
8 XCOMM Usage: exportlistgen libfoo.so libfoo.elist > mapfile.scope
9 XCOMM
10 XCOMM   libfoo.so    => shared library of interest
11 XCOMM   libfoo.elist => Meta description of necessary export list.
12 XCOMM
13 XCOMM    The output file, "mapfile.scope" may then be passed to the Solaris 
14 XCOMM    linker to reconstruct the shared library, libfoo.so.
15 XCOMM
16 XCOMM ########################################################################
17
18 XCOMM Utility programs
19 FILTER=CXXFILT                  # C++ symbol demangler
20 AWK=nawk                        # Awk
21
22 XCOMM For nm, cat, pr, expand, awk, c++filt
23 PATH=/usr/bin:/bin:/usr/ccs/bin:/usr/ucb:/opt/SUNWspro/bin
24
25 XCOMM Try to detect broken versions of c++filt.
26 if [ `echo _okay | ${FILTER:-cat}` != "_okay" ]; then
27     if [ -x /opt/SUNWspro/bin/c++filt ]; then
28         echo "# Your $FILTER is broken -- using /opt/SUNWspro/bin/c++filt."
29         FILTER=/opt/SUNWspro/bin/c++filt
30     else
31         echo "# ERROR: no working $FILTER available."
32         exit 1
33     fi;
34 fi;
35
36 XCOMM Temporary files
37 EXPORTLIST=/tmp/elistgen1.$$    # export directives from "libfoo.list"
38 NMLIST=/tmp/elistgen2.$$        # name list from libfoo.sl
39 FILTLIST=/tmp/elistgen3.$$      # demangled (C++) version of above
40
41 XCOMM Print useful information at the top of the output
42 echo "#" `date`
43 echo "# This scoping mapfile was produced by" $0
44 echo "# Export list description taken from:" $2
45 echo "# Target library:" $1
46 echo "# Target Operating System:" `uname -msrv`
47 echo "# "
48
49 XCOMM Extract the globally visible symbols from target library
50 XCOMM The NMLIST generated here is later used to cross-check the symbols in the
51 XCOMM nm stopped working on Solaris 2.5, use dump instead.
52 XCOMM nm -p $1 | $AWK '/ [ TDBS] /{print $3}' > $NMLIST
53 /usr/ccs/bin/dump -t -v $1 | egrep "(FUNC|OBJT).(GLOB|WEAK)" | egrep -v "(FUNC|OBJT).(GLOB|WEAK). *[0-9]. *UNDEF" | $AWK '{print $8}' > $NMLIST
54
55 XCOMM Extract the globally visible symbols from target library
56 XCOMM The NMLIST generated here is later used to cross-check the symbols in the
57 ${FILTER:-cat} $NMLIST > $FILTLIST
58
59 XCOMM Clean up the export-list description file.  Sort the directives.
60 $AWK '
61     BEGIN {
62         csyms     = 0;  # C   public symbols in libfoo.list
63         cplusplus = 0;  # C++ public symbols in libfoo.list
64         isyms     = 0;  # C   internal symbols in libfoo.list
65         iplusplus = 0;  # C++ internal symbols in libfoo.list
66         implicit  = ""; # Handling of implicit symbols
67     }
68     $1 == "default" {
69         # A default clause suppresses warnings about implicit symbols.
70         if ($2 != "" && $2 != "force" && $2 != "public" && $2 != "private" && $2 != "internal") {
71             print "# Warning: illegal default clause:", $2 | "cat 1>&2";
72             next;
73         }
74         if (implicit != "")
75             print "# Warning: multiple default clauses." | "cat 1>&2";
76         implicit = $2;
77         next;
78     }
79     $1 == "force" {
80         csyms ++;
81         print $1 ";;" $2;
82         next;
83     }
84     $1 == "public" {
85         csyms ++;
86         print $1 ";;" $2;
87         next;
88     }
89     $1 == "publicC++" {
90         cplusplus ++;
91         string = $2;
92         for (n = 3; n <= NF; n++)
93             string = string " " $n;
94         print $1 ";;" string;
95         next;
96     }
97     $1 == "private" {
98         csyms ++;
99         print $1 ";;" $2;
100         next;
101     }
102     $1 == "privateC++" {
103         cplusplus ++;
104         string = $2;
105         for (n = 3; n <= NF; n++)
106             string = string " " $n;
107         print $1 ";;" string;
108         next;
109     }
110     $1 == "internal" {
111         isyms ++;
112         print $1 ";;" $2;
113         next;
114     }
115     $1 == "internalC++" {
116         iplusplus ++;
117         string = $2;
118         for (n = 3; n <= NF; n++)
119             string = string " " $n;
120         print $1 ";;" string;
121         next;
122     }
123     $1 == "#line" || $1 == "#" {
124         # cpp will have removed comments, but may have added other stuff.
125         next;
126     }
127     NF > 0 {
128         print "# Warning: unrecognized directive:", $0 | "cat 1>&2";
129         next;
130     }
131     END {
132         printf("# Exporting %d C and %d C++ symbols, hiding %d and %d.\n", csyms, cplusplus, isyms, iplusplus) | "cat 1>&2";
133         if (implicit != "") {
134             print "# Unspecified symbols are " implicit "." | "cat 1>&2";
135             print "default;;" implicit;
136         }
137     }
138 ' $2 1>$EXPORTLIST
139
140
141 XCOMM Read in the above files and write result to stdout.  The contents
142 XCOMM of NMLIST and FILTLIST are used to construct a symbol lookup table.
143 XCOMM The contents of EXPORTLIST are converted with the help of this table.
144 XCOMM Use ";" as a delimiter in the symbol lookup table.
145 (pr -m -s";" -t -w1024 $NMLIST $FILTLIST | expand -1; cat $EXPORTLIST) | $AWK '
146     BEGIN {
147         FS = ";";
148         implicit = 0;
149     }
150     NF == 2 {
151         # This is "pr" output, i.e., symbol translation table
152         r2=$2;
153         gsub(/static /,"",r2); # remove keyword "static" as above
154         gsub(/ /,"",r2);       # Remove spaces because c++filt is unpredictable
155         syms[r2] = $1;
156         r1=$1;
157         gsub(/ /,"",r1);
158         mangled[r1] = 1;       # Save the mangling because the export lists
159                                # sometimes use it instead of a prototype.
160         next;
161     }
162     NF == 3 && $1 == "default" {
163         # Treatment of unspecified symbols.
164         if ($3 == "internal" || $3 == "internalC++")
165             implicit = 1;
166         else if ($3 == "private" || $3 == "privateC++")
167             implicit = 2;
168         else if ($3 == "public" || $3 == "publicC++")
169             implicit = 3;
170         else # $3 == "force"
171             implicit = 4;
172         next;
173     }
174     NF == 3 {
175         # Generate canonical demangled form as an alternate symbol.
176         alt=$3;
177         gsub(/ \.\.\./,",...",alt);  # change " ..." to ",..." to match c++filt
178         gsub(/ /,"",alt);            # remove all spaces
179         
180         # An export directive.  Parse our instructions for this symbol.
181         if ($1 == "internal" || $1 == "internalC++")
182             export = 1;
183         else if ($3 == "private" || $3 == "privateC++")
184             export = 2;
185         else if ($3 == "public" || $3 == "publicC++")
186             export = 3;
187         else # $3 == "force"
188             export = 4;
189
190         # Process it.
191         if ((length(syms[alt]) > 0) || mangled[alt]) {
192             # This symbol is present in the library.
193             if (donelist[alt])
194                 print "# Warning: Duplicate entry for", $3, 
195                     "in export list" | "cat 1>&2";
196             if (donelist[alt] < export) {
197                 donelist[alt] = export;
198             }
199         } else { 
200             # Print forced-export symbols without complaining.
201             if (export == 4) {
202                 donelist[alt] = export;
203             } else {
204                 print "# Warning:", $3,
205                     "was not in the nm list for this library" | "cat 1>&2";
206             }
207         }
208         
209         next;
210     }
211     END { 
212         # Ignore magic linker symbols.
213         if (implicit == 0) {
214             if (!donelist["_DYNAMIC"])
215                 donelist["_DYNAMIC"] = 1;
216             if (!donelist["_GLOBAL_OFFSET_TABLE_"])
217                 donelist["_GLOBAL_OFFSET_TABLE_"] = 1;
218             if (!donelist["_PROCEDURE_LINKAGE_TABLE_"])
219                 donelist["_PROCEDURE_LINKAGE_TABLE_"] = 1;
220             if (!donelist["_edata"])
221                 donelist["_edata"] = 1;
222             if (!donelist["_end"])
223                 donelist["_end"] = 1;
224             if (!donelist["_etext"])
225                 donelist["_etext"] = 1;
226         }
227
228         # Process implicit symbols.
229         for (i in syms) {
230             if (donelist[i] == 0 && length(syms[i]) > 0) {
231                 if (implicit == 0) {
232                     # Ignore magic symbols introduced by the C++ compiler.
233                     if ((syms[i] !~ /[_a-zA-Z0-9]*__vtbl$/) &&
234                         (syms[i] !~ /libC_errors/) &&
235                         (syms[i] !~ /_ex_/) &&
236                         (syms[i] !~ /__rt/) &&
237                         (syms[i] !~ /__RT/) &&
238                         (syms[i] !~ /^__ptbl_vec__/))
239                         print "# Warning:", syms[i], "was not in the export list" | "cat 1>&2";
240                 } else {
241                     donelist[i] = implicit;
242                 }
243             }
244         }
245
246         # Generate the linker file.
247         print "";
248         print "SUNW.1.1 {";
249         print "    global:";
250         for (i in syms)
251             if (donelist[i] >= 2 && length(syms[i]) > 0)
252                 print "        " syms[i] ";";
253         print "    local:";
254         print "        *;";
255         print "};";
256
257         print "";
258         print "SUNW_private.1.1 {";
259         print "    global:";
260         for (i in syms)
261             if (donelist[i] == 1 && length(syms[i]) > 0)
262                 print "        " syms[i] ";";
263         print "} SUNW.1.1;"
264     }
265 '
266
267 XCOMM Clean up temporary files
268 rm $EXPORTLIST
269 rm $NMLIST
270 rm $FILTLIST