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