1#*************************************************************************
2#
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# Copyright 2000, 2010 Oracle and/or its affiliates.
6#
7# OpenOffice.org - a multi-platform office productivity suite
8#
9# This file is part of OpenOffice.org.
10#
11# OpenOffice.org is free software: you can redistribute it and/or modify
12# it under the terms of the GNU Lesser General Public License version 3
13# only, as published by the Free Software Foundation.
14#
15# OpenOffice.org is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU Lesser General Public License version 3 for more details
19# (a copy is included in the LICENSE file that accompanied this code).
20#
21# You should have received a copy of the GNU Lesser General Public License
22# version 3 along with OpenOffice.org.  If not, see
23# <http://www.openoffice.org/license.html>
24# for a copy of the LGPLv3 License.
25#
26#*************************************************************************
27
28package installer::windows::strip;
29
30use File::Temp qw(tmpnam);
31use installer::converter;
32use installer::existence;
33use installer::globals;
34use installer::logger;
35use installer::pathanalyzer;
36use installer::systemactions;
37
38#####################################################################
39# Checking whether a file has to be stripped
40#####################################################################
41
42sub need_to_strip
43{
44	my ( $filename ) = @_;
45
46	my $strip = 0;
47
48	# Check using the "nm" command
49
50	$filename =~ s/\\/\\\\/g;
51
52	open (FILE, "nm $filename 2>&1 |");
53	my $nmoutput = <FILE>;
54	close (FILE);
55
56	if ( $nmoutput && !( $nmoutput =~ /no symbols/i || $nmoutput =~ /not recognized/i )) { $strip = 1; }
57
58	return $strip
59}
60
61#####################################################################
62# Checking whether a file has to be stripped
63#####################################################################
64
65sub do_strip
66{
67	my ( $filename ) = @_;
68
69	my $systemcall = "strip" . " " . $filename;
70
71	my $returnvalue = system($systemcall);
72
73	my $infoline = "Systemcall: $systemcall\n";
74	push( @installer::globals::logfileinfo, $infoline);
75
76	if ($returnvalue)
77	{
78		$infoline = "ERROR: Could not strip $filename!\n";
79		push( @installer::globals::logfileinfo, $infoline);
80	}
81	else
82	{
83		$infoline = "SUCCESS: Stripped library $filename!\n";
84		push( @installer::globals::logfileinfo, $infoline);
85	}
86}
87
88#####################################################################
89# Resolving all variables in the packagename.
90#####################################################################
91
92sub strip_binaries
93{
94	my ( $filelist, $languagestringref ) = @_;
95
96	installer::logger::include_header_into_logfile("Stripping files:");
97
98	my $strippeddirbase = installer::systemactions::create_directories("stripped", $languagestringref);
99
100	if (! installer::existence::exists_in_array($strippeddirbase, \@installer::globals::removedirs))
101	{
102		push(@installer::globals::removedirs, $strippeddirbase);
103	}
104
105	my ($tmpfilehandle, $tmpfilename) = tmpnam();
106	open SOURCEPATHLIST, ">$tmpfilename" or die "oops...\n";
107	for ( my $i = 0; $i <= $#{$filelist}; $i++ )
108	{
109		print SOURCEPATHLIST "${$filelist}[$i]->{'sourcepath'}\n";
110	}
111	close SOURCEPATHLIST;
112	my @filetypelist = qx{file -f "$tmpfilename"};
113	chomp @filetypelist;
114	unlink "$tmpfilename" or die "oops\n";
115	for ( my $i = 0; $i <= $#{$filelist}; $i++ )
116	{
117		${$filelist}[$i]->{'is_executable'} = ( $filetypelist[$i] =~ /:.*PE executable/ );
118	}
119
120	if ( $^O =~ /cygwin/i ) { installer::worker::generate_cygwin_pathes($filelist); }
121
122	for ( my $i = 0; $i <= $#{$filelist}; $i++ )
123	{
124		my $sourcefilename = ${$filelist}[$i]->{'cyg_sourcepath'};
125
126		if ( ${$filelist}[$i]->{'is_executable'} && need_to_strip($sourcefilename) )
127		{
128			my $shortfilename = $sourcefilename;
129			installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$shortfilename);
130
131			$infoline = "Strip: $shortfilename\n";
132			push( @installer::globals::logfileinfo, $infoline);
133
134			# copy file into directory for stripped libraries
135
136			my $onelanguage = ${$filelist}[$i]->{'specificlanguage'};
137
138			# files without language into directory "00"
139
140			if ($onelanguage eq "") { $onelanguage = "00"; }
141
142			my $strippeddir = $strippeddirbase . $installer::globals::separator . $onelanguage;
143			installer::systemactions::create_directory($strippeddir);	# creating language specific subdirectories
144
145			my $destfilename = $strippeddir . $installer::globals::separator . $shortfilename;
146			installer::systemactions::copy_one_file($sourcefilename, $destfilename);
147
148			# change sourcepath in files collector
149
150			${$filelist}[$i]->{'sourcepath'} = $destfilename;
151
152			# strip file
153
154			do_strip($destfilename);
155		}
156	}
157}
158
1591;
160