19780544fSAndrew Rist#************************************************************** 29780544fSAndrew Rist# 39780544fSAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 49780544fSAndrew Rist# or more contributor license agreements. See the NOTICE file 59780544fSAndrew Rist# distributed with this work for additional information 69780544fSAndrew Rist# regarding copyright ownership. The ASF licenses this file 79780544fSAndrew Rist# to you under the Apache License, Version 2.0 (the 89780544fSAndrew Rist# "License"); you may not use this file except in compliance 99780544fSAndrew Rist# with the License. You may obtain a copy of the License at 109780544fSAndrew Rist# 119780544fSAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 129780544fSAndrew Rist# 139780544fSAndrew Rist# Unless required by applicable law or agreed to in writing, 149780544fSAndrew Rist# software distributed under the License is distributed on an 159780544fSAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169780544fSAndrew Rist# KIND, either express or implied. See the License for the 179780544fSAndrew Rist# specific language governing permissions and limitations 189780544fSAndrew Rist# under the License. 199780544fSAndrew Rist# 209780544fSAndrew Rist#************************************************************** 219780544fSAndrew Rist 229780544fSAndrew 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 69*b274bc22SAndre Fischer $installer::logger::Lang->printf("Systemcall: %s\n", $systemcall); 70cdf0e10cSrcweir 71cdf0e10cSrcweir if ($returnvalue) 72cdf0e10cSrcweir { 73*b274bc22SAndre Fischer $installer::logger::Lang->printf("ERROR: Could not strip %s!\n", $filename); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir else 76cdf0e10cSrcweir { 77*b274bc22SAndre Fischer $installer::logger::Lang->printf("SUCCESS: Stripped library %s!\n", $filename); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir} 80cdf0e10cSrcweir 81cdf0e10cSrcweir##################################################################### 82cdf0e10cSrcweir# Resolving all variables in the packagename. 83cdf0e10cSrcweir##################################################################### 84cdf0e10cSrcweir 85cdf0e10cSrcweirsub strip_binaries 86cdf0e10cSrcweir{ 87cdf0e10cSrcweir my ( $filelist, $languagestringref ) = @_; 88cdf0e10cSrcweir 89cdf0e10cSrcweir installer::logger::include_header_into_logfile("Stripping files:"); 90cdf0e10cSrcweir 91cdf0e10cSrcweir my $strippeddirbase = installer::systemactions::create_directories("stripped", $languagestringref); 92cdf0e10cSrcweir 93cdf0e10cSrcweir if (! installer::existence::exists_in_array($strippeddirbase, \@installer::globals::removedirs)) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir push(@installer::globals::removedirs, $strippeddirbase); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir my ($tmpfilehandle, $tmpfilename) = tmpnam(); 99cdf0e10cSrcweir open SOURCEPATHLIST, ">$tmpfilename" or die "oops...\n"; 100cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filelist}; $i++ ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir print SOURCEPATHLIST "${$filelist}[$i]->{'sourcepath'}\n"; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir close SOURCEPATHLIST; 105cdf0e10cSrcweir my @filetypelist = qx{file -f "$tmpfilename"}; 106cdf0e10cSrcweir chomp @filetypelist; 107cdf0e10cSrcweir unlink "$tmpfilename" or die "oops\n"; 108cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filelist}; $i++ ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir ${$filelist}[$i]->{'is_executable'} = ( $filetypelist[$i] =~ /:.*PE executable/ ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir if ( $^O =~ /cygwin/i ) { installer::worker::generate_cygwin_pathes($filelist); } 114cdf0e10cSrcweir 115cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filelist}; $i++ ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir my $sourcefilename = ${$filelist}[$i]->{'cyg_sourcepath'}; 118cdf0e10cSrcweir 119cdf0e10cSrcweir if ( ${$filelist}[$i]->{'is_executable'} && need_to_strip($sourcefilename) ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir my $shortfilename = $sourcefilename; 122cdf0e10cSrcweir installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$shortfilename); 123*b274bc22SAndre Fischer 124*b274bc22SAndre Fischer $installer::logger::Lang->printf("Strip: %s\n", $shortfilename); 125cdf0e10cSrcweir 126cdf0e10cSrcweir # copy file into directory for stripped libraries 127cdf0e10cSrcweir 128cdf0e10cSrcweir my $onelanguage = ${$filelist}[$i]->{'specificlanguage'}; 129cdf0e10cSrcweir 130cdf0e10cSrcweir # files without language into directory "00" 131cdf0e10cSrcweir 132cdf0e10cSrcweir if ($onelanguage eq "") { $onelanguage = "00"; } 133cdf0e10cSrcweir 134cdf0e10cSrcweir my $strippeddir = $strippeddirbase . $installer::globals::separator . $onelanguage; 135cdf0e10cSrcweir installer::systemactions::create_directory($strippeddir); # creating language specific subdirectories 136cdf0e10cSrcweir 137cdf0e10cSrcweir my $destfilename = $strippeddir . $installer::globals::separator . $shortfilename; 138cdf0e10cSrcweir installer::systemactions::copy_one_file($sourcefilename, $destfilename); 139cdf0e10cSrcweir 140cdf0e10cSrcweir # change sourcepath in files collector 141cdf0e10cSrcweir 142cdf0e10cSrcweir ${$filelist}[$i]->{'sourcepath'} = $destfilename; 143cdf0e10cSrcweir 144cdf0e10cSrcweir # strip file 145cdf0e10cSrcweir 146cdf0e10cSrcweir do_strip($destfilename); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir } 149cdf0e10cSrcweir} 150cdf0e10cSrcweir 151cdf0e10cSrcweir1; 152