19780544fSAndrew Rist#************************************************************** 2*756cacb8SJim Jagielski# 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 10*756cacb8SJim Jagielski# 119780544fSAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 12*756cacb8SJim Jagielski# 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. 19*756cacb8SJim Jagielski# 209780544fSAndrew Rist#************************************************************** 219780544fSAndrew Rist 229780544fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweirpackage installer::strip; 25cdf0e10cSrcweir 26cdf0e10cSrcweiruse installer::converter; 27cdf0e10cSrcweiruse installer::existence; 28cdf0e10cSrcweiruse installer::globals; 29cdf0e10cSrcweiruse installer::logger; 30cdf0e10cSrcweiruse installer::pathanalyzer; 31cdf0e10cSrcweiruse installer::systemactions; 32cdf0e10cSrcweir 33cdf0e10cSrcweir##################################################################### 34cdf0e10cSrcweir# Checking whether a file has to be stripped 35cdf0e10cSrcweir##################################################################### 36cdf0e10cSrcweir 37cdf0e10cSrcweirsub need_to_strip 38cdf0e10cSrcweir{ 39cdf0e10cSrcweir my ( $filename ) = @_; 40*756cacb8SJim Jagielski 41cdf0e10cSrcweir my $strip = 0; 42*756cacb8SJim Jagielski 43cdf0e10cSrcweir # Check using the "file" command 44cdf0e10cSrcweir 45cdf0e10cSrcweir open (FILE, "file $filename |"); 46cdf0e10cSrcweir my $fileoutput = <FILE>; 47cdf0e10cSrcweir close (FILE); 48cdf0e10cSrcweir 49cdf0e10cSrcweir if (( $fileoutput =~ /not stripped/i ) && ( $fileoutput =~ /\bELF\b/ )) { $strip = 1; } 50cdf0e10cSrcweir 51*756cacb8SJim Jagielski return $strip 52cdf0e10cSrcweir} 53cdf0e10cSrcweir 54cdf0e10cSrcweir##################################################################### 55cdf0e10cSrcweir# Checking whether a file has to be stripped 56cdf0e10cSrcweir##################################################################### 57cdf0e10cSrcweir 58cdf0e10cSrcweirsub do_strip 59cdf0e10cSrcweir{ 60cdf0e10cSrcweir my ( $filename ) = @_; 61*756cacb8SJim Jagielski 62cdf0e10cSrcweir my $systemcall = "strip" . " " . $filename; 63*756cacb8SJim Jagielski 64cdf0e10cSrcweir my $returnvalue = system($systemcall); 65cdf0e10cSrcweir 66cdf0e10cSrcweir my $infoline = "Systemcall: $systemcall\n"; 67b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 68*756cacb8SJim Jagielski 69cdf0e10cSrcweir if ($returnvalue) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir $infoline = "ERROR: Could not strip $filename!\n"; 72b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir else 75cdf0e10cSrcweir { 76cdf0e10cSrcweir $infoline = "SUCCESS: Stripped library $filename!\n"; 77b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir} 80cdf0e10cSrcweir 81cdf0e10cSrcweir##################################################################### 82*756cacb8SJim Jagielski# Resolving all variables in the packagename 83cdf0e10cSrcweir##################################################################### 84cdf0e10cSrcweir 85cdf0e10cSrcweirsub strip_libraries 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 { 95*756cacb8SJim Jagielski push(@installer::globals::removedirs, $strippeddirbase); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filelist}; $i++ ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir my $sourcefilename = ${$filelist}[$i]->{'sourcepath'}; 101cdf0e10cSrcweir 102cdf0e10cSrcweir if ( need_to_strip($sourcefilename) ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir my $shortfilename = $sourcefilename; 105cdf0e10cSrcweir installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$shortfilename); 106*756cacb8SJim Jagielski 107cdf0e10cSrcweir $infoline = "Strip: $shortfilename\n"; 108b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 109cdf0e10cSrcweir 110cdf0e10cSrcweir # copy file into directory for stripped libraries 111cdf0e10cSrcweir 112cdf0e10cSrcweir my $onelanguage = ${$filelist}[$i]->{'specificlanguage'}; 113*756cacb8SJim Jagielski 114cdf0e10cSrcweir # files without language into directory "00" 115*756cacb8SJim Jagielski 116cdf0e10cSrcweir if ($onelanguage eq "") { $onelanguage = "00"; } 117*756cacb8SJim Jagielski 118cdf0e10cSrcweir my $strippeddir = $strippeddirbase . $installer::globals::separator . $onelanguage; 119*756cacb8SJim Jagielski installer::systemactions::create_directory($strippeddir); # creating language specific subdirectories 120cdf0e10cSrcweir 121cdf0e10cSrcweir my $destfilename = $strippeddir . $installer::globals::separator . $shortfilename; 122cdf0e10cSrcweir installer::systemactions::copy_one_file($sourcefilename, $destfilename); 123cdf0e10cSrcweir 124cdf0e10cSrcweir # change sourcepath in files collector 125cdf0e10cSrcweir 126cdf0e10cSrcweir ${$filelist}[$i]->{'sourcepath'} = $destfilename; 127cdf0e10cSrcweir 128cdf0e10cSrcweir # strip file 129*756cacb8SJim Jagielski 130cdf0e10cSrcweir do_strip($destfilename); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir } 133cdf0e10cSrcweir} 134cdf0e10cSrcweir 135cdf0e10cSrcweir1; 136