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