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::windows::strip; 25 26use File::Temp qw(tmpnam); 27use installer::converter; 28use installer::existence; 29use installer::globals; 30use installer::logger; 31use installer::pathanalyzer; 32use installer::systemactions; 33 34##################################################################### 35# Checking whether a file has to be stripped 36##################################################################### 37 38sub need_to_strip 39{ 40 my ( $filename ) = @_; 41 42 my $strip = 0; 43 44 # Check using the "nm" command 45 46 $filename =~ s/\\/\\\\/g; 47 48 open (FILE, "nm $filename 2>&1 |"); 49 my $nmoutput = <FILE>; 50 close (FILE); 51 52 if ( $nmoutput && !( $nmoutput =~ /no symbols/i || $nmoutput =~ /not recognized/i )) { $strip = 1; } 53 54 return $strip 55} 56 57##################################################################### 58# Checking whether a file has to be stripped 59##################################################################### 60 61sub do_strip 62{ 63 my ( $filename ) = @_; 64 65 my $systemcall = "strip" . " " . $filename; 66 67 my $returnvalue = system($systemcall); 68 69 my $infoline = "Systemcall: $systemcall\n"; 70 push( @installer::globals::logfileinfo, $infoline); 71 72 if ($returnvalue) 73 { 74 $infoline = "ERROR: Could not strip $filename!\n"; 75 push( @installer::globals::logfileinfo, $infoline); 76 } 77 else 78 { 79 $infoline = "SUCCESS: Stripped library $filename!\n"; 80 push( @installer::globals::logfileinfo, $infoline); 81 } 82} 83 84##################################################################### 85# Resolving all variables in the packagename. 86##################################################################### 87 88sub strip_binaries 89{ 90 my ( $filelist, $languagestringref ) = @_; 91 92 installer::logger::include_header_into_logfile("Stripping files:"); 93 94 my $strippeddirbase = installer::systemactions::create_directories("stripped", $languagestringref); 95 96 if (! installer::existence::exists_in_array($strippeddirbase, \@installer::globals::removedirs)) 97 { 98 push(@installer::globals::removedirs, $strippeddirbase); 99 } 100 101 my ($tmpfilehandle, $tmpfilename) = tmpnam(); 102 open SOURCEPATHLIST, ">$tmpfilename" or die "oops...\n"; 103 for ( my $i = 0; $i <= $#{$filelist}; $i++ ) 104 { 105 print SOURCEPATHLIST "${$filelist}[$i]->{'sourcepath'}\n"; 106 } 107 close SOURCEPATHLIST; 108 my @filetypelist = qx{file -f "$tmpfilename"}; 109 chomp @filetypelist; 110 unlink "$tmpfilename" or die "oops\n"; 111 for ( my $i = 0; $i <= $#{$filelist}; $i++ ) 112 { 113 ${$filelist}[$i]->{'is_executable'} = ( $filetypelist[$i] =~ /:.*PE executable/ ); 114 } 115 116 if ( $^O =~ /cygwin/i ) { installer::worker::generate_cygwin_pathes($filelist); } 117 118 for ( my $i = 0; $i <= $#{$filelist}; $i++ ) 119 { 120 my $sourcefilename = ${$filelist}[$i]->{'cyg_sourcepath'}; 121 122 if ( ${$filelist}[$i]->{'is_executable'} && need_to_strip($sourcefilename) ) 123 { 124 my $shortfilename = $sourcefilename; 125 installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$shortfilename); 126 127 $infoline = "Strip: $shortfilename\n"; 128 push( @installer::globals::logfileinfo, $infoline); 129 130 # copy file into directory for stripped libraries 131 132 my $onelanguage = ${$filelist}[$i]->{'specificlanguage'}; 133 134 # files without language into directory "00" 135 136 if ($onelanguage eq "") { $onelanguage = "00"; } 137 138 my $strippeddir = $strippeddirbase . $installer::globals::separator . $onelanguage; 139 installer::systemactions::create_directory($strippeddir); # creating language specific subdirectories 140 141 my $destfilename = $strippeddir . $installer::globals::separator . $shortfilename; 142 installer::systemactions::copy_one_file($sourcefilename, $destfilename); 143 144 # change sourcepath in files collector 145 146 ${$filelist}[$i]->{'sourcepath'} = $destfilename; 147 148 # strip file 149 150 do_strip($destfilename); 151 } 152 } 153} 154 1551; 156