1*9780544fSAndrew Rist#************************************************************** 2*9780544fSAndrew Rist# 3*9780544fSAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 4*9780544fSAndrew Rist# or more contributor license agreements. See the NOTICE file 5*9780544fSAndrew Rist# distributed with this work for additional information 6*9780544fSAndrew Rist# regarding copyright ownership. The ASF licenses this file 7*9780544fSAndrew Rist# to you under the Apache License, Version 2.0 (the 8*9780544fSAndrew Rist# "License"); you may not use this file except in compliance 9*9780544fSAndrew Rist# with the License. You may obtain a copy of the License at 10*9780544fSAndrew Rist# 11*9780544fSAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 12*9780544fSAndrew Rist# 13*9780544fSAndrew Rist# Unless required by applicable law or agreed to in writing, 14*9780544fSAndrew Rist# software distributed under the License is distributed on an 15*9780544fSAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9780544fSAndrew Rist# KIND, either express or implied. See the License for the 17*9780544fSAndrew Rist# specific language governing permissions and limitations 18*9780544fSAndrew Rist# under the License. 19*9780544fSAndrew Rist# 20*9780544fSAndrew Rist#************************************************************** 21*9780544fSAndrew Rist 22*9780544fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweirpackage installer::windows::strip; 25cdf0e10cSrcweir 26cdf0e10cSrcweiruse File::Temp qw(tmpnam); 27cdf0e10cSrcweiruse installer::converter; 28cdf0e10cSrcweiruse installer::existence; 29cdf0e10cSrcweiruse installer::globals; 30cdf0e10cSrcweiruse installer::logger; 31cdf0e10cSrcweiruse installer::pathanalyzer; 32cdf0e10cSrcweiruse installer::systemactions; 33cdf0e10cSrcweir 34cdf0e10cSrcweir##################################################################### 35cdf0e10cSrcweir# Checking whether a file has to be stripped 36cdf0e10cSrcweir##################################################################### 37cdf0e10cSrcweir 38cdf0e10cSrcweirsub need_to_strip 39cdf0e10cSrcweir{ 40cdf0e10cSrcweir my ( $filename ) = @_; 41cdf0e10cSrcweir 42cdf0e10cSrcweir my $strip = 0; 43cdf0e10cSrcweir 44cdf0e10cSrcweir # Check using the "nm" command 45cdf0e10cSrcweir 46cdf0e10cSrcweir $filename =~ s/\\/\\\\/g; 47cdf0e10cSrcweir 48cdf0e10cSrcweir open (FILE, "nm $filename 2>&1 |"); 49cdf0e10cSrcweir my $nmoutput = <FILE>; 50cdf0e10cSrcweir close (FILE); 51cdf0e10cSrcweir 52cdf0e10cSrcweir if ( $nmoutput && !( $nmoutput =~ /no symbols/i || $nmoutput =~ /not recognized/i )) { $strip = 1; } 53cdf0e10cSrcweir 54cdf0e10cSrcweir return $strip 55cdf0e10cSrcweir} 56cdf0e10cSrcweir 57cdf0e10cSrcweir##################################################################### 58cdf0e10cSrcweir# Checking whether a file has to be stripped 59cdf0e10cSrcweir##################################################################### 60cdf0e10cSrcweir 61cdf0e10cSrcweirsub do_strip 62cdf0e10cSrcweir{ 63cdf0e10cSrcweir my ( $filename ) = @_; 64cdf0e10cSrcweir 65cdf0e10cSrcweir my $systemcall = "strip" . " " . $filename; 66cdf0e10cSrcweir 67cdf0e10cSrcweir my $returnvalue = system($systemcall); 68cdf0e10cSrcweir 69cdf0e10cSrcweir my $infoline = "Systemcall: $systemcall\n"; 70cdf0e10cSrcweir push( @installer::globals::logfileinfo, $infoline); 71cdf0e10cSrcweir 72cdf0e10cSrcweir if ($returnvalue) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir $infoline = "ERROR: Could not strip $filename!\n"; 75cdf0e10cSrcweir push( @installer::globals::logfileinfo, $infoline); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir else 78cdf0e10cSrcweir { 79cdf0e10cSrcweir $infoline = "SUCCESS: Stripped library $filename!\n"; 80cdf0e10cSrcweir push( @installer::globals::logfileinfo, $infoline); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir} 83cdf0e10cSrcweir 84cdf0e10cSrcweir##################################################################### 85cdf0e10cSrcweir# Resolving all variables in the packagename. 86cdf0e10cSrcweir##################################################################### 87cdf0e10cSrcweir 88cdf0e10cSrcweirsub strip_binaries 89cdf0e10cSrcweir{ 90cdf0e10cSrcweir my ( $filelist, $languagestringref ) = @_; 91cdf0e10cSrcweir 92cdf0e10cSrcweir installer::logger::include_header_into_logfile("Stripping files:"); 93cdf0e10cSrcweir 94cdf0e10cSrcweir my $strippeddirbase = installer::systemactions::create_directories("stripped", $languagestringref); 95cdf0e10cSrcweir 96cdf0e10cSrcweir if (! installer::existence::exists_in_array($strippeddirbase, \@installer::globals::removedirs)) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir push(@installer::globals::removedirs, $strippeddirbase); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir my ($tmpfilehandle, $tmpfilename) = tmpnam(); 102cdf0e10cSrcweir open SOURCEPATHLIST, ">$tmpfilename" or die "oops...\n"; 103cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filelist}; $i++ ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir print SOURCEPATHLIST "${$filelist}[$i]->{'sourcepath'}\n"; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir close SOURCEPATHLIST; 108cdf0e10cSrcweir my @filetypelist = qx{file -f "$tmpfilename"}; 109cdf0e10cSrcweir chomp @filetypelist; 110cdf0e10cSrcweir unlink "$tmpfilename" or die "oops\n"; 111cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filelist}; $i++ ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir ${$filelist}[$i]->{'is_executable'} = ( $filetypelist[$i] =~ /:.*PE executable/ ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir if ( $^O =~ /cygwin/i ) { installer::worker::generate_cygwin_pathes($filelist); } 117cdf0e10cSrcweir 118cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filelist}; $i++ ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir my $sourcefilename = ${$filelist}[$i]->{'cyg_sourcepath'}; 121cdf0e10cSrcweir 122cdf0e10cSrcweir if ( ${$filelist}[$i]->{'is_executable'} && need_to_strip($sourcefilename) ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir my $shortfilename = $sourcefilename; 125cdf0e10cSrcweir installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$shortfilename); 126cdf0e10cSrcweir 127cdf0e10cSrcweir $infoline = "Strip: $shortfilename\n"; 128cdf0e10cSrcweir push( @installer::globals::logfileinfo, $infoline); 129cdf0e10cSrcweir 130cdf0e10cSrcweir # copy file into directory for stripped libraries 131cdf0e10cSrcweir 132cdf0e10cSrcweir my $onelanguage = ${$filelist}[$i]->{'specificlanguage'}; 133cdf0e10cSrcweir 134cdf0e10cSrcweir # files without language into directory "00" 135cdf0e10cSrcweir 136cdf0e10cSrcweir if ($onelanguage eq "") { $onelanguage = "00"; } 137cdf0e10cSrcweir 138cdf0e10cSrcweir my $strippeddir = $strippeddirbase . $installer::globals::separator . $onelanguage; 139cdf0e10cSrcweir installer::systemactions::create_directory($strippeddir); # creating language specific subdirectories 140cdf0e10cSrcweir 141cdf0e10cSrcweir my $destfilename = $strippeddir . $installer::globals::separator . $shortfilename; 142cdf0e10cSrcweir installer::systemactions::copy_one_file($sourcefilename, $destfilename); 143cdf0e10cSrcweir 144cdf0e10cSrcweir # change sourcepath in files collector 145cdf0e10cSrcweir 146cdf0e10cSrcweir ${$filelist}[$i]->{'sourcepath'} = $destfilename; 147cdf0e10cSrcweir 148cdf0e10cSrcweir # strip file 149cdf0e10cSrcweir 150cdf0e10cSrcweir do_strip($destfilename); 151cdf0e10cSrcweir } 152cdf0e10cSrcweir } 153cdf0e10cSrcweir} 154cdf0e10cSrcweir 155cdf0e10cSrcweir1; 156