| 1 |
# |
| 2 |
# This file is part of the LibreOffice project. |
| 3 |
# |
| 4 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 |
# |
| 8 |
# This file incorporates work covered by the following license notice: |
| 9 |
# |
| 10 |
# Licensed to the Apache Software Foundation (ASF) under one or more |
| 11 |
# contributor license agreements. See the NOTICE file distributed |
| 12 |
# with this work for additional information regarding copyright |
| 13 |
# ownership. The ASF licenses this file to you under the Apache |
| 14 |
# License, Version 2.0 (the "License"); you may not use this file |
| 15 |
# except in compliance with the License. You may obtain a copy of |
| 16 |
# the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 17 |
# |
| 18 |
|
| 19 |
package installer::windows::strip; |
| 20 |
|
| 21 |
use strict; |
| 22 |
use warnings; |
| 23 |
|
| 24 |
use File::Temp qw(tmpnam); |
| 25 |
use installer::converter; |
| 26 |
use installer::globals; |
| 27 |
use installer::logger; |
| 28 |
use installer::pathanalyzer; |
| 29 |
use installer::systemactions; |
| 30 |
|
| 31 |
##################################################################### |
| 32 |
# Checking whether a file has to be stripped |
| 33 |
##################################################################### |
| 34 |
|
| 35 |
sub need_to_strip |
| 36 |
{ |
| 37 |
my ( $filename ) = @_; |
| 38 |
|
| 39 |
my $strip = 0; |
| 40 |
|
| 41 |
# Check using the "nm" command |
| 42 |
|
| 43 |
$filename =~ s/\\/\\\\/g; |
| 44 |
|
| 45 |
open (FILE, "nm $filename 2>&1 |"); |
| 46 |
my $nmoutput = <FILE>; |
| 47 |
close (FILE); |
| 48 |
|
| 49 |
if ( $nmoutput && !( $nmoutput =~ /no symbols/i || $nmoutput =~ /not recognized/i )) { $strip = 1; } |
| 50 |
|
| 51 |
return $strip |
| 52 |
} |
| 53 |
|
| 54 |
##################################################################### |
| 55 |
# Checking whether a file has to be stripped |
| 56 |
##################################################################### |
| 57 |
|
| 58 |
sub 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 |
push( @installer::globals::logfileinfo, $infoline); |
| 68 |
|
| 69 |
if ($returnvalue) |
| 70 |
{ |
| 71 |
$infoline = "ERROR: Could not strip $filename!\n"; |
| 72 |
push( @installer::globals::logfileinfo, $infoline); |
| 73 |
} |
| 74 |
else |
| 75 |
{ |
| 76 |
$infoline = "SUCCESS: Stripped library $filename!\n"; |
| 77 |
push( @installer::globals::logfileinfo, $infoline); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
##################################################################### |
| 82 |
# Resolving all variables in the packagename. |
| 83 |
##################################################################### |
| 84 |
|
| 85 |
sub strip_binaries |
| 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 (! grep {$_ eq $strippeddirbase} @installer::globals::removedirs) |
| 94 |
{ |
| 95 |
push(@installer::globals::removedirs, $strippeddirbase); |
| 96 |
} |
| 97 |
|
| 98 |
my ($tmpfilehandle, $tmpfilename) = tmpnam(); |
| 99 |
open SOURCEPATHLIST, ">$tmpfilename" or die "oops...\n"; |
| 100 |
for ( my $i = 0; $i <= $#{$filelist}; $i++ ) |
| 101 |
{ |
| 102 |
print SOURCEPATHLIST "${$filelist}[$i]->{'sourcepath'}\n"; |
| 103 |
} |
| 104 |
close SOURCEPATHLIST; |
| 105 |
my @filetypelist = qx{file -f "$tmpfilename"}; |
| 106 |
chomp @filetypelist; |
| 107 |
unlink "$tmpfilename" or die "oops\n"; |
| 108 |
for ( my $i = 0; $i <= $#{$filelist}; $i++ ) |
| 109 |
{ |
| 110 |
${$filelist}[$i]->{'is_executable'} = ( $filetypelist[$i] =~ /:.*PE executable/ ); |
| 111 |
} |
| 112 |
|
| 113 |
if ( $^O =~ /cygwin/i ) { installer::worker::generate_cygwin_paths($filelist); } |
| 114 |
|
| 115 |
for ( my $i = 0; $i <= $#{$filelist}; $i++ ) |
| 116 |
{ |
| 117 |
my $sourcefilename = ${$filelist}[$i]->{'cyg_sourcepath'}; |
| 118 |
|
| 119 |
if ( ${$filelist}[$i]->{'is_executable'} && need_to_strip($sourcefilename) ) |
| 120 |
{ |
| 121 |
my $shortfilename = $sourcefilename; |
| 122 |
installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$shortfilename); |
| 123 |
|
| 124 |
my $infoline = "Strip: $shortfilename\n"; |
| 125 |
push( @installer::globals::logfileinfo, $infoline); |
| 126 |
|
| 127 |
# copy file into directory for stripped libraries |
| 128 |
|
| 129 |
my $onelanguage = ${$filelist}[$i]->{'specificlanguage'}; |
| 130 |
|
| 131 |
# files without language into directory "00" |
| 132 |
|
| 133 |
if ($onelanguage eq "") { $onelanguage = "00"; } |
| 134 |
|
| 135 |
my $strippeddir = $strippeddirbase . $installer::globals::separator . $onelanguage; |
| 136 |
installer::systemactions::create_directory($strippeddir); # creating language specific subdirectories |
| 137 |
|
| 138 |
my $destfilename = $strippeddir . $installer::globals::separator . $shortfilename; |
| 139 |
installer::systemactions::copy_one_file($sourcefilename, $destfilename); |
| 140 |
|
| 141 |
# change sourcepath in files collector |
| 142 |
|
| 143 |
${$filelist}[$i]->{'sourcepath'} = $destfilename; |
| 144 |
|
| 145 |
# strip file |
| 146 |
|
| 147 |
do_strip($destfilename); |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
1; |