xref: /aoo42x/main/solenv/bin/mapgen.pl (revision 7e90fac2)
1:
2eval 'exec perl -wS $0 ${1+"$@"}'
3    if 0;
4#**************************************************************
5#
6#  Licensed to the Apache Software Foundation (ASF) under one
7#  or more contributor license agreements.  See the NOTICE file
8#  distributed with this work for additional information
9#  regarding copyright ownership.  The ASF licenses this file
10#  to you under the Apache License, Version 2.0 (the
11#  "License"); you may not use this file except in compliance
12#  with the License.  You may obtain a copy of the License at
13#
14#    http://www.apache.org/licenses/LICENSE-2.0
15#
16#  Unless required by applicable law or agreed to in writing,
17#  software distributed under the License is distributed on an
18#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19#  KIND, either express or implied.  See the License for the
20#  specific language governing permissions and limitations
21#  under the License.
22#
23#**************************************************************
24
25
26
27#
28# mapgen  - generate a map file for Unix libraries
29#
30
31#use File::Path;
32#use File::Copy;
33
34#### script id #####
35
36( $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/;
37
38$id_str = ' $Revision: 1.6 $ ';
39$id_str =~ /Revision:\s+(\S+)\s+\$/
40  ? ($script_rev = $1) : ($script_rev = "-");
41
42print "$script_name -- version: $script_rev\n";
43print "Multi Platform Enabled Edition\n";
44
45#########################
46#                       #
47#   Globale Variablen   #
48#                       #
49#########################
50
51$dump_file = '';
52$flt_file = '';
53$map_file = '';
54$first_string = '';
55$tab = '    ';
56
57#### main ####
58
59&get_options;
60if (!(open (DUMP_FILE, $dump_file))) {
61	&print_error("Unable open $dump_file");
62};
63if (!(open (FLT_FILE, $flt_file))) {
64	close DUMP_FILE;
65	&print_error("Unable open $flt_file");
66};
67unlink $map_file;
68if (!(open (MAP_FILE, ">>$map_file"))) {
69	close DUMP_FILE;
70	close FLT_FILE;
71	&print_error("Unable open $map_file");
72};
73
74if ($ENV{OS} eq 'SOLARIS') {
75	&gen_sol;
76} elsif ($ENV{OS} eq 'LINUX') {
77	&gen_lnx;
78} else {
79	&print_error ('Environment not set!!');
80};
81
82close DUMP_FILE;
83close FLT_FILE;
84close MAP_FILE;
85
86#### end of main procedure ####
87
88#########################
89#                       #
90#      Procedures       #
91#                       #
92#########################
93
94#
95# Generate a map file for solaris
96#
97sub gen_sol {
98	my %symbols = ();
99	foreach (<DUMP_FILE>) {
100		next if (!(/\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*/));
101		next if (($7 =~ /UNDEF/) || ($7 =~ /ABS/));
102		next if ($5 eq 'LOCL');
103		$symbols{$8}++;
104	};
105	&filter_symbols(\%symbols);
106};
107
108#
109# Generate a map file for linux
110#
111sub gen_lnx {
112	my %symbols = ();
113	foreach (<DUMP_FILE>) {
114		next if (!(/^\S+ [A|B|C|D|G|I|N|R|S|T|U|V|W|-|\?|-] (\S+)/));
115		$symbols{$1}++;
116	};
117	&filter_symbols(\%symbols);
118}
119
120#
121# Filter symbols with filters from $flt_file
122#
123sub filter_symbols {
124	my $symbols = shift;
125	my $env_section = '';
126	my @filters = ();
127	my @filtered_symbols = ();
128	while (<FLT_FILE>) {
129		s/\r//;
130		s/\n//;
131		$env_section = '1' and next if ((/^# SOLARIS #$/) && ($ENV{OS} eq 'SOLARIS'));
132		$env_section = '1' and next if ((/^# LINUX #$/) && ($ENV{OS} eq 'LINUX'));
133		$env_section = '1' and next if ((/^# FREEBSD #$/) && ($ENV{OS} eq 'FREEBSD'));
134		last if ($env_section && ((/^# SOLARIS #$/) || (/^# FREEBSD #$/) || (/^# LINUX #$/)));
135		next if (!$_ || /^#/);
136		push(@filters, $_);
137	};
138	foreach my $symbol (keys %$symbols) {
139		my $export = '-';
140        foreach my $filter_str (@filters) {
141            my $add = substr ($filter_str, 0, 1);
142            my $filter = substr($filter_str, 1);
143			if ($symbol =~ /$filter/) {
144				$export = $add;
145			};
146		};
147		if ($export eq '+') {
148			push(@filtered_symbols, $symbol);
149		};
150	};
151	&write_mapfile(\@filtered_symbols);
152};
153
154#
155# Write a map file
156#
157sub write_mapfile {
158	my $symbols = shift;
159	print MAP_FILE $first_string . " {\n$tab" . "global:\n";
160	foreach (@$symbols) {
161		print MAP_FILE "$tab$tab$_\;\n";
162	};
163	print MAP_FILE "$tab" . "local:\n$tab\*\;\n}\;";
164};
165
166#
167# Get all options passed
168#
169sub get_options {
170
171$dump_file = '';
172$flt_file = '';
173$map_file = '';
174	my ($arg);
175	&usage() && exit(0) if ($#ARGV == -1);
176	while ($arg = shift @ARGV) {
177		$arg =~ /^-d$/			and $dump_file = shift @ARGV	and next;
178		$arg =~ /^-f$/			and $flt_file = shift @ARGV		and next;
179		$arg =~ /^-m$/			and $map_file = shift @ARGV		and next;
180		$arg =~ /^-h$/			and &usage						and exit(0);
181		$arg =~ /^--help$/		and &usage						and exit(0);
182		$arg =~ /^-s$/			and $first_string = shift @ARGV	and next;
183	};
184	if (!$dump_file ||
185        !$flt_file  ||
186        !$first_string  ||
187        !$map_file) {
188		&usage;
189		exit(1);
190	};
191};
192
193sub print_error {
194    my $message = shift;
195    print STDERR "\nERROR: $message\n";
196	exit(1)
197};
198
199sub usage {
200	print STDERR "\nmapgen:\n";
201    print STDERR "Syntax:    mapgen -d dump_file -s first_string -f filter_file -m map_file [-h|--help]\n";
202};
203
204