Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[oweals/cde.git] / util / elistgen.hp
1 XCOMM!/bin/sh
2 XCOMM $TOG: elistgen.hp /main/5 1999/04/16 13:54:01 mgreess $
3 XCOMM
4 XCOMM #########################################################################
5 XCOMM Construct shared-library export lists for HP-UX based on standardized
6 XCOMM export list description file
7 XCOMM
8 XCOMM Usage: exportlistgen libfoo.sl libfoo.elist > libfoo.lopt
9 XCOMM
10 XCOMM   libfoo.sl    => shared library of interest
11 XCOMM   libfoo.elist => Meta description of necessary export list.
12 XCOMM
13 XCOMM The output may then be passed to the linker to reconstruct the
14 XCOMM shared library.  For unknown reasons naming only exported symbols
15 XCOMM with "+e" does not work for debuggable C++ code, even though "nm"
16 XCOMM reports no difference between the resulting libraries.  The linker
17 XCOMM complains that "first non-inline virtual function" is not defined for
18 XCOMM vtables.  We instead hide internal symbols with "-h" as a work-around.
19 XCOMM
20 XCOMM Author: Aloke Gupta 5/25/94.
21 XCOMM (c) Copyright 1996 Digital Equipment Corporation.
22 XCOMM (c) Copyright 1994,1996 Hewlett-Packard Company.
23 XCOMM (c) Copyright 1996 International Business Machines Corp.
24 XCOMM (c) Copyright 1996 Sun Microsystems, Inc.
25 XCOMM (c) Copyright 1996 Novell, Inc.
26 XCOMM (c) Copyright 1996 FUJITSU LIMITED.
27 XCOMM (c) Copyright 1996 Hitachi.
28 XCOMM
29 XCOMM #########################################################################
30
31 XCOMM Utility programs
32 FILTER=CXXFILT                  # C++ symbol demangler
33 AWK=awk                         # awk
34 PATH=/usr/bin:/bin:/usr/ucb     # For nm, cat, pr, expand, awk, c++filt
35
36 XCOMM Temporary files
37 EXPORTLIST=/tmp/elistgen1.$$    # list of export symbols from "libfoo.elist"
38 NMLIST=/tmp/elistgen2.$$        # name list from libfoo.sl
39 FILTLIST=/tmp/elistgen3.$$      # demangled (C++) version of NMLIST
40
41 XCOMM Print useful information at the top of the output
42 echo "#" `date`
43 echo "# This linker options list was produced by" $0
44 echo "# Input 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 supplied export-list.
52 XCOMM
53 nm -p $1 | $AWK '
54     / [cCTDB][S ] [^\$]/{print $3}   # Text, Data, BSS, or Secondary symbols
55 ' | uniq > $NMLIST.all
56
57 nm -p $1 | $AWK '
58     / [uU][S ] [^\$]/{print $3}   # Text, Data, BSS, or Secondary symbols
59 ' | uniq > $NMLIST.undef
60
61 cat $NMLIST.all $NMLIST.undef $NMLIST.undef | sort | uniq -c | $AWK '{if ($1=="1") print $2}' > $NMLIST
62
63
64 XCOMM nm -p $1 | $AWK '
65 XCOMM     / [cCTDB][S ] [^\$]/{print $3}   # Text, Data, BSS, or Secondary symbols
66 XCOMM ' > $NMLIST
67
68 XCOMM Demangle the global library symbols. This operation is necessary to
69 XCOMM convert mangled C++ symbols into their C++ notation.
70 ${FILTER:-cat} $NMLIST > $FILTLIST
71
72 XCOMM
73 XCOMM Cleanup the export-list description file.
74 XCOMM Note that C++ symbols may have embedded spaces in them.
75 XCOMM
76 cat $2 | $AWK '
77     BEGIN           {
78         csyms      = 0;         # C   language symbols in libfoo.list
79         cplusplus  = 0;         # C++ language symbols in libfoo.list
80         isyms      = 0;         # C   internal symbols in libfoo.elist
81         icplusplus = 0;         # C++ internal symbols in libfoo.elist
82         implicit = "";          # Handling of implicit symbols.
83     }
84     $1 == "default" {
85         # A default clause suppresses warnings about implicit symbols.
86         if ($2 != "" && $2 != "force" && $2 != "public" && 
87             $2 != "private" && $2 != "internal") {
88             print "# Warning: illegal default clause:", $2 | "cat 1>&2";
89             next;
90         }
91         if (implicit != "")
92             print "# Warning: multiple default clauses." | "cat 1>&2";
93         implicit = $2;
94         next;
95     }
96     $1 == "force" || $1 == "public" || $1 == "private" {
97         csyms ++;
98         print $1 ";;" $2;
99         next;
100     }
101     $1 == "publicC++" || $1 == "privateC++" {
102         cplusplus ++;
103         string = $2;
104         for (n = 3; n <= NF; n++)
105             string = string " " $n;
106         print $1 ";;" string;
107         next;
108     }
109     $1 == "internal" {
110         isyms ++;
111         print $1 ";;" $2;
112         next;
113     }
114     $1 == "internalC++" {
115         icplusplus ++;
116         string = $2;
117         for (n = 3; n <= NF; n++)
118             string = string " " $n;
119         print $1 ";;" string;
120         next;
121     }
122     END  {
123         printf("# Exporting %d C and %d C++ symbols, hiding %d and %d.\n",
124                 csyms, cplusplus, isyms, icplusplus) | "cat 1>&2";
125         if (implicit != "") {
126             print "# Unspecified symbols are " implicit "." | "cat 1>&2";
127             print "default;;" implicit;
128         }
129     }
130 ' > $EXPORTLIST
131
132 XCOMM Read in the above files and write result to stdout.  The contents
133 XCOMM of NMLIST and FILTLIST are used to construct a symbol lookup table.
134 XCOMM The contents of EXPORTLIST are converted with the help of this table.
135 XCOMM Use ";" as a delimiter in the symbol lookup table.
136 XCOMM
137 (pr -m -s";" -t -w1024 $NMLIST $FILTLIST| expand -t 1;cat $EXPORTLIST ) | $AWK '
138     BEGIN {
139         FS = ";";
140         implicit = 0;
141     }
142     NF == 2 {
143         # This is "pr" output, i.e., symbol translation table.
144         syms[$2] = $1;
145         next;
146     }
147     NF == 3 && $1 == "default" {
148         # Treatment of unspecified symbols.
149         if ($3 == "internal" || $3 == "internalC++")
150             implicit = 1;
151         else if ($3 == "private" || $3 == "privateC++")
152             implicit = 2;
153         else if ($3 == "public" || $3 == "publicC++")
154             implicit = 3;
155         else # $3 == "force"
156             implicit = 4;
157         next;
158     }
159     NF == 3 {
160         # Parse our instructions for this symbol.
161         if ($1 == "internal" || $1 == "internalC++")
162             export = 1;
163         else if ($1 == "private" || $1 == "privateC++")
164             export = 2;
165         else if ($1 == "public" || $1 == "publicC++")
166             export = 3;
167         else # $1 == "force"
168             export = 4;
169
170         # Process it.
171         if (length(syms[$3]) > 0) {
172             if (donelist[$3])
173                 print "# Warning: Duplicate entry for", $3,
174                         "in export list" | "cat 1>&2";
175             if (donelist[$3] < export)
176                 donelist[$3] = export;
177         } else {
178             if (export == 4)
179                 donelist[$3] = export;
180             else
181                 print "# Warning:", $3,
182                     "was not in the nm list for this library" | "cat 1>&2";
183         }
184         next;
185     }
186     END {
187         # Force implicit exporting of errno.
188         if (! donelist["errno"])
189             donelist["errno"] = 4;
190
191         # Complain about some implicit symbols.
192         for (i in syms) {
193             if (!donelist[i] && (length(syms[i]) > 0)) {
194                 # Ignore automatic symbols generated by the C++ compiler.
195                 if (implicit == 0 && 
196                     (syms[i] !~ /^__noperfopt__/) &&
197                     (syms[i] !~ /^__ptbl_vec__/) &&
198                     (syms[i] !~ /^__vtbl__[0-9]*_/) &&
199                     (syms[i] !~ /^__cfront_version_[0-9]*_xxxxxxxx$/))
200                     print "# Warning:", syms[i],
201                           "was not in the export list" | "cat 1>&2";
202                 donelist[i] = implicit;
203             }
204             if ((donelist[i] > 1) && (length(syms[i]) > 0))
205                 print "-e", syms[i];
206         }
207     }
208 '
209
210 XCOMM Clean up temporary files
211 rm $EXPORTLIST
212 rm $NMLIST.all
213 rm $NMLIST.undef
214 rm $NMLIST
215 rm $FILTLIST