| 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::strip; |
| 20 |
|
| 21 |
use strict; |
| 22 |
use warnings; |
| 23 |
|
| 24 |
use base 'Exporter'; |
| 25 |
|
| 26 |
use installer::globals; |
| 27 |
use installer::logger; |
| 28 |
use installer::pathanalyzer; |
| 29 |
use installer::systemactions; |
| 30 |
|
| 31 |
our @EXPORT_OK = qw(strip_libraries); |
| 32 |
|
| 33 |
##################################################################### |
| 34 |
# Checking whether a file has to be stripped |
| 35 |
##################################################################### |
| 36 |
|
| 37 |
sub _need_to_strip |
| 38 |
{ |
| 39 |
my ( $filename ) = @_; |
| 40 |
|
| 41 |
my $strip = 0; |
| 42 |
|
| 43 |
# Check using the "file" command |
| 44 |
|
| 45 |
$filename =~ s/'/'\\''/g; |
| 46 |
open (FILE, "file '$filename' |"); |
| 47 |
my $fileoutput = <FILE>; |
| 48 |
close (FILE); |
| 49 |
|
| 50 |
if (( $fileoutput =~ /not stripped/i ) && ( $fileoutput =~ /\bELF\b/ )) { $strip = 1; } |
| 51 |
|
| 52 |
return $strip |
| 53 |
} |
| 54 |
|
| 55 |
##################################################################### |
| 56 |
# Checking whether a file has to be stripped |
| 57 |
##################################################################### |
| 58 |
|
| 59 |
sub _do_strip |
| 60 |
{ |
| 61 |
my ( $filename ) = @_; |
| 62 |
|
| 63 |
my $systemcall = "strip" . " " . $filename; |
| 64 |
|
| 65 |
my $returnvalue = system($systemcall); |
| 66 |
|
| 67 |
my $infoline = "Systemcall: $systemcall\n"; |
| 68 |
push( @installer::globals::logfileinfo, $infoline); |
| 69 |
|
| 70 |
if ($returnvalue) |
| 71 |
{ |
| 72 |
$infoline = "ERROR: Could not strip $filename!\n"; |
| 73 |
push( @installer::globals::logfileinfo, $infoline); |
| 74 |
} |
| 75 |
else |
| 76 |
{ |
| 77 |
$infoline = "SUCCESS: Stripped library $filename!\n"; |
| 78 |
push( @installer::globals::logfileinfo, $infoline); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
##################################################################### |
| 83 |
# Resolving all variables in the packagename |
| 84 |
##################################################################### |
| 85 |
|
| 86 |
sub strip_libraries |
| 87 |
{ |
| 88 |
my ( $filelist, $languagestringref ) = @_; |
| 89 |
|
| 90 |
installer::logger::include_header_into_logfile("Stripping files:"); |
| 91 |
|
| 92 |
my $strippeddirbase = installer::systemactions::create_directories("stripped", $languagestringref); |
| 93 |
|
| 94 |
if (! grep {$_ eq $strippeddirbase} @installer::globals::removedirs) |
| 95 |
{ |
| 96 |
push(@installer::globals::removedirs, $strippeddirbase); |
| 97 |
} |
| 98 |
|
| 99 |
for ( my $i = 0; $i <= $#{$filelist}; $i++ ) |
| 100 |
{ |
| 101 |
my $sourcefilename = ${$filelist}[$i]->{'sourcepath'}; |
| 102 |
|
| 103 |
if ( _need_to_strip($sourcefilename) ) |
| 104 |
{ |
| 105 |
my $shortfilename = $sourcefilename; |
| 106 |
installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$shortfilename); |
| 107 |
|
| 108 |
my $infoline = "Strip: $shortfilename\n"; |
| 109 |
push( @installer::globals::logfileinfo, $infoline); |
| 110 |
|
| 111 |
# copy file into directory for stripped libraries |
| 112 |
|
| 113 |
my $onelanguage = ${$filelist}[$i]->{'specificlanguage'}; |
| 114 |
|
| 115 |
# files without language into directory "00" |
| 116 |
|
| 117 |
if ($onelanguage eq "") { $onelanguage = "00"; } |
| 118 |
|
| 119 |
my $strippeddir = $strippeddirbase . $installer::globals::separator . $onelanguage; |
| 120 |
installer::systemactions::create_directory($strippeddir); # creating language specific subdirectories |
| 121 |
|
| 122 |
my $destfilename = $strippeddir . $installer::globals::separator . $shortfilename; |
| 123 |
installer::systemactions::copy_one_file($sourcefilename, $destfilename); |
| 124 |
|
| 125 |
# change sourcepath in files collector |
| 126 |
|
| 127 |
${$filelist}[$i]->{'sourcepath'} = $destfilename; |
| 128 |
|
| 129 |
# strip file |
| 130 |
|
| 131 |
_do_strip($destfilename); |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
1; |