1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer
::upx
;
34 use installer
::converter
;
35 use installer
::existence
;
36 use installer
::globals
;
37 use installer
::logger
;
38 use installer
::pathanalyzer
;
39 use installer
::scriptitems
;
40 use installer
::systemactions
;
42 #####################################################################
43 # Checking whether a file has to be stripped
44 #####################################################################
48 my ( $filename, $onefile ) = @_;
52 if (( $filename =~ /\.so\s*$/ ) ||
53 ( $filename =~ /\.dll\s*$/ ) ||
54 ( $filename =~ /\.exe\s*$/ ) ||
55 ( $filename =~ /\.bin\s*$/ ))
58 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
59 if ( ! ( $styles =~ /\bDONT_UPX\b/ )) { $useupx = 1; }
65 #####################################################################
66 # Checking whether a file has to be stripped
67 #####################################################################
71 my ( $filename ) = @_;
73 my $compression = "9";
74 my $systemcall = $installer::globals
::upxfile
. " -" . $compression . " " . $filename;
76 my $returnvalue = system($systemcall);
78 my $infoline = "Systemcall: $systemcall\n";
79 push( @installer::globals
::logfileinfo
, $infoline);
83 $infoline = "WARNING: Could not successfully upx $filename! Using original file.\n";
84 push( @installer::globals
::logfileinfo
, $infoline);
88 $infoline = "SUCCESS: upx $filename!\n";
89 push( @installer::globals
::logfileinfo
, $infoline);
95 #####################################################################
96 # Using upx to decrease file size
97 #####################################################################
101 my ( $filelist, $languagestringref) = @_;
103 installer
::logger
::include_header_into_logfile
("UPX'ing files:");
106 if ( ! $installer::globals
::upx_in_path
)
108 $infoline = "\n\nWarning: This is an UPX product, but upx was not found in PATH!\n\n";
109 push( @installer::globals
::logfileinfo
, $infoline);
113 $infoline = "Using upx: $installer::globals::upxfile\n";
114 push( @installer::globals
::logfileinfo
, $infoline);
116 my $upxdirbase = installer
::systemactions
::create_directories
("upx", $languagestringref);
118 if (! installer
::existence
::exists_in_array
($upxdirbase, \
@installer::globals
::removedirs
))
120 push(@installer::globals
::removedirs
, $upxdirbase);
123 for ( my $i = 0; $i <= $#{$filelist}; $i++ )
125 my $sourcefilename = ${$filelist}[$i]->{'sourcepath'};
127 if ( is_upx_candidate
($sourcefilename, ${$filelist}[$i]) )
129 my $shortfilename = $sourcefilename;
130 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$shortfilename);
132 $infoline = "\nUpx: $shortfilename";
133 push( @installer::globals
::logfileinfo
, $infoline);
135 # copy file into directory for stripped libraries
136 my $onelanguage = ${$filelist}[$i]->{'specificlanguage'};
138 # files without language into directory "00"
139 if ($onelanguage eq "") { $onelanguage = "00"; }
141 my $upxdir = $upxdirbase . $installer::globals
::separator
. $onelanguage;
142 installer
::systemactions
::create_directory
($upxdir); # creating language specific subdirectories
144 my $destfilename = $upxdir . $installer::globals
::separator
. $shortfilename;
145 installer
::systemactions
::copy_one_file
($sourcefilename, $destfilename);
147 # change sourcepath in files collector
148 ${$filelist}[$i]->{'sourcepath'} = $destfilename;
151 my $return = do_upx
($destfilename);
153 # Using original file, if upx was not successful (no reason for error)
154 if ( $return ) { ${$filelist}[$i]->{'sourcepath'} = $sourcefilename; }