190075Sobrien# Generate a flat list of symbols to export.
290075Sobrien#	Contributed by Richard Henderson <rth@cygnus.com>
390075Sobrien#
490075Sobrien# This file is part of GCC.
590075Sobrien#
690075Sobrien# GCC is free software; you can redistribute it and/or modify it under
790075Sobrien# the terms of the GNU General Public License as published by the Free
890075Sobrien# Software Foundation; either version 2, or (at your option) any later
990075Sobrien# version.
1090075Sobrien#
1190075Sobrien# GCC is distributed in the hope that it will be useful, but WITHOUT
1290075Sobrien# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1390075Sobrien# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
1490075Sobrien# License for more details.
1590075Sobrien#
1690075Sobrien# You should have received a copy of the GNU General Public License
1790075Sobrien# along with GCC; see the file COPYING.  If not, write to the Free
18169689Skan# Software Foundation, 51 Franklin Street, Fifth Floor, Boston MA
19169689Skan# 02110-1301, USA.
2090075Sobrien
2190075SobrienBEGIN {
2290075Sobrien  state = "nm";
23169689Skan  excluding = 0;
24169689Skan  if (leading_underscore)
25169689Skan    prefix = "_";
26169689Skan  else
27169689Skan    prefix = "";
2890075Sobrien}
2990075Sobrien
3090075Sobrien# Remove comment and blank lines.
3190075Sobrien/^ *#/ || /^ *$/ {
3290075Sobrien  next;
3390075Sobrien}
3490075Sobrien
3590075Sobrien# We begin with nm input.  Collect the set of symbols that are present
3690075Sobrien# so that we can elide undefined symbols.
3790075Sobrien
3890075Sobrienstate == "nm" && /^%%/ {
3990075Sobrien  state = "ver";
4090075Sobrien  next;
4190075Sobrien}
4290075Sobrien
4390075Sobrienstate == "nm" && ($1 == "U" || $2 == "U") {
4490075Sobrien  next;
4590075Sobrien}
4690075Sobrien
4790075Sobrienstate == "nm" && NF == 3 {
4890075Sobrien  def[$3] = 1;
4990075Sobrien  next;
5090075Sobrien}
5190075Sobrien
5290075Sobrienstate == "nm" {
5390075Sobrien  next;
5490075Sobrien}
5590075Sobrien
5690075Sobrien# Now we process a simplified variant of the Solaris symbol version
5790075Sobrien# script.  We have one symbol per line, no semicolons, simple markers
5890075Sobrien# for beginning and ending each section, and %inherit markers for
5990075Sobrien# describing version inheritence.  A symbol may appear in more than
6090075Sobrien# one symbol version, and the last seen takes effect.
61169689Skan# The magic version name '%exclude' causes all the symbols given that
62169689Skan# version to be dropped from the output (unless a later version overrides).
6390075Sobrien
6490075SobrienNF == 3 && $1 == "%inherit" {
6590075Sobrien  next;
6690075Sobrien}
6790075Sobrien
6890075SobrienNF == 2 && $2 == "{" {
69169689Skan  if ($1 == "%exclude")
70169689Skan    excluding = 1;
7190075Sobrien  next;
7290075Sobrien}
7390075Sobrien
7490075Sobrien$1 == "}" {
75169689Skan  excluding = 0;
7690075Sobrien  next;
7790075Sobrien}
7890075Sobrien
7990075Sobrien{
80169689Skan  sym = prefix $1;
81169689Skan  if (excluding)
82169689Skan    delete export[sym];
83169689Skan  else
84169689Skan    export[sym] = 1;
8590075Sobrien  next;
8690075Sobrien}
8790075Sobrien
8890075SobrienEND {
8990075Sobrien  for (sym in export)
9090075Sobrien    if (def[sym])
9190075Sobrien      print sym;
9290075Sobrien}
93