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