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