xref: /aoo42x/main/solenv/bin/mapgen.pl (revision cdf0e10c)
1:
2eval 'exec perl -wS $0 ${1+"$@"}'
3    if 0;
4#*************************************************************************
5#
6# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7#
8# Copyright 2000, 2010 Oracle and/or its affiliates.
9#
10# OpenOffice.org - a multi-platform office productivity suite
11#
12# This file is part of OpenOffice.org.
13#
14# OpenOffice.org is free software: you can redistribute it and/or modify
15# it under the terms of the GNU Lesser General Public License version 3
16# only, as published by the Free Software Foundation.
17#
18# OpenOffice.org is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21# GNU Lesser General Public License version 3 for more details
22# (a copy is included in the LICENSE file that accompanied this code).
23#
24# You should have received a copy of the GNU Lesser General Public License
25# version 3 along with OpenOffice.org.  If not, see
26# <http://www.openoffice.org/license.html>
27# for a copy of the LGPLv3 License.
28#
29#*************************************************************************
30
31#
32# mapgen  - generate a map file for Unix libraries
33#
34
35#use File::Path;
36#use File::Copy;
37
38#### script id #####
39
40( $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/;
41
42$id_str = ' $Revision: 1.6 $ ';
43$id_str =~ /Revision:\s+(\S+)\s+\$/
44  ? ($script_rev = $1) : ($script_rev = "-");
45
46print "$script_name -- version: $script_rev\n";
47print "Multi Platform Enabled Edition\n";
48
49#########################
50#                       #
51#   Globale Variablen   #
52#                       #
53#########################
54
55$dump_file = '';
56$flt_file = '';
57$map_file = '';
58$first_string = '';
59$tab = '    ';
60
61#### main ####
62
63&get_options;
64if (!(open (DUMP_FILE, $dump_file))) {
65	&print_error("Unable open $dump_file");
66};
67if (!(open (FLT_FILE, $flt_file))) {
68	close DUMP_FILE;
69	&print_error("Unable open $flt_file");
70};
71unlink $map_file;
72if (!(open (MAP_FILE, ">>$map_file"))) {
73	close DUMP_FILE;
74	close FLT_FILE;
75	&print_error("Unable open $map_file");
76};
77
78if ($ENV{OS} eq 'SOLARIS') {
79	&gen_sol;
80} elsif ($ENV{OS} eq 'LINUX') {
81	&gen_lnx;
82} else {
83	&print_error ('Environment not set!!');
84};
85
86close DUMP_FILE;
87close FLT_FILE;
88close MAP_FILE;
89
90#### end of main procedure ####
91
92#########################
93#                       #
94#      Procedures       #
95#                       #
96#########################
97
98#
99# Generate a map file for solaris
100#
101sub gen_sol {
102	my %symbols = ();
103	foreach (<DUMP_FILE>) {
104		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*/));
105		next if (($7 =~ /UNDEF/) || ($7 =~ /ABS/));
106		next if ($5 eq 'LOCL');
107		$symbols{$8}++;
108	};
109	&filter_symbols(\%symbols);
110};
111
112#
113# Generate a map file for linux
114#
115sub gen_lnx {
116	my %symbols = ();
117	foreach (<DUMP_FILE>) {
118		next if (!(/^\S+ [A|B|C|D|G|I|N|R|S|T|U|V|W|-|\?|-] (\S+)/));
119		$symbols{$1}++;
120	};
121	&filter_symbols(\%symbols);
122}
123
124#
125# Filter symbols with filters from $flt_file
126#
127sub filter_symbols {
128	my $symbols = shift;
129	my $env_section = '';
130	my @filters = ();
131	my @filtered_symbols = ();
132	while (<FLT_FILE>) {
133		s/\r//;
134		s/\n//;
135		$env_section = '1' and next if ((/^# SOLARIS #$/) && ($ENV{OS} eq 'SOLARIS'));
136		$env_section = '1' and next if ((/^# LINUX #$/) && ($ENV{OS} eq 'LINUX'));
137		$env_section = '1' and next if ((/^# FREEBSD #$/) && ($ENV{OS} eq 'FREEBSD'));
138		last if ($env_section && ((/^# SOLARIS #$/) || (/^# FREEBSD #$/) || (/^# LINUX #$/)));
139		next if (!$_ || /^#/);
140		push(@filters, $_);
141	};
142	foreach my $symbol (keys %$symbols) {
143		my $export = '-';
144        foreach my $filter_str (@filters) {
145            my $add = substr ($filter_str, 0, 1);
146            my $filter = substr($filter_str, 1);
147			if ($symbol =~ /$filter/) {
148				$export = $add;
149			};
150		};
151		if ($export eq '+') {
152			push(@filtered_symbols, $symbol);
153		};
154	};
155	&write_mapfile(\@filtered_symbols);
156};
157
158#
159# Write a map file
160#
161sub write_mapfile {
162	my $symbols = shift;
163	print MAP_FILE $first_string . " {\n$tab" . "global:\n";
164	foreach (@$symbols) {
165		print MAP_FILE "$tab$tab$_\;\n";
166	};
167	print MAP_FILE "$tab" . "local:\n$tab\*\;\n}\;";
168};
169
170#
171# Get all options passed
172#
173sub get_options {
174
175$dump_file = '';
176$flt_file = '';
177$map_file = '';
178	my ($arg);
179	&usage() && exit(0) if ($#ARGV == -1);
180	while ($arg = shift @ARGV) {
181		$arg =~ /^-d$/			and $dump_file = shift @ARGV	and next;
182		$arg =~ /^-f$/			and $flt_file = shift @ARGV		and next;
183		$arg =~ /^-m$/			and $map_file = shift @ARGV		and next;
184		$arg =~ /^-h$/			and &usage						and exit(0);
185		$arg =~ /^--help$/		and &usage						and exit(0);
186		$arg =~ /^-s$/			and $first_string = shift @ARGV	and next;
187	};
188	if (!$dump_file ||
189        !$flt_file  ||
190        !$first_string  ||
191        !$map_file) {
192		&usage;
193		exit(1);
194	};
195};
196
197sub print_error {
198    my $message = shift;
199    print STDERR "\nERROR: $message\n";
200	exit(1)
201};
202
203sub usage {
204	print STDERR "\nmapgen:\n";
205    print STDERR "Syntax:    mapgen -d dump_file -s first_string -f filter_file -m map_file [-h|--help]\n";
206};
207
208