xref: /trunk/main/solenv/bin/modules/installer/strip.pm (revision ef1ef8e674fabf3a541d12c6e6c14cecdfc2f9e7)
1#*************************************************************************
2#
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# Copyright 2000, 2010 Oracle and/or its affiliates.
6#
7# OpenOffice.org - a multi-platform office productivity suite
8#
9# This file is part of OpenOffice.org.
10#
11# OpenOffice.org is free software: you can redistribute it and/or modify
12# it under the terms of the GNU Lesser General Public License version 3
13# only, as published by the Free Software Foundation.
14#
15# OpenOffice.org is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU Lesser General Public License version 3 for more details
19# (a copy is included in the LICENSE file that accompanied this code).
20#
21# You should have received a copy of the GNU Lesser General Public License
22# version 3 along with OpenOffice.org.  If not, see
23# <http://www.openoffice.org/license.html>
24# for a copy of the LGPLv3 License.
25#
26#*************************************************************************
27
28package installer::strip;
29
30use installer::converter;
31use installer::existence;
32use installer::globals;
33use installer::logger;
34use installer::pathanalyzer;
35use installer::systemactions;
36
37#####################################################################
38# Checking whether a file has to be stripped
39#####################################################################
40
41sub need_to_strip
42{
43    my ( $filename ) = @_;
44
45    my $strip = 0;
46
47    # Check using the "file" command
48
49    open (FILE, "file $filename |");
50    my $fileoutput = <FILE>;
51    close (FILE);
52
53    if (( $fileoutput =~ /not stripped/i ) && ( $fileoutput =~ /\bELF\b/ )) { $strip = 1; }
54
55    return $strip
56}
57
58#####################################################################
59# Checking whether a file has to be stripped
60#####################################################################
61
62sub do_strip
63{
64    my ( $filename ) = @_;
65
66    my $systemcall = "strip" . " " . $filename;
67
68    my $returnvalue = system($systemcall);
69
70    my $infoline = "Systemcall: $systemcall\n";
71    push( @installer::globals::logfileinfo, $infoline);
72
73    if ($returnvalue)
74    {
75        $infoline = "ERROR: Could not strip $filename!\n";
76        push( @installer::globals::logfileinfo, $infoline);
77    }
78    else
79    {
80        $infoline = "SUCCESS: Stripped library $filename!\n";
81        push( @installer::globals::logfileinfo, $infoline);
82    }
83}
84
85#####################################################################
86# Resolving all variables in the packagename.
87#####################################################################
88
89sub strip_libraries
90{
91    my ( $filelist, $languagestringref ) = @_;
92
93    installer::logger::include_header_into_logfile("Stripping files:");
94
95    my $strippeddirbase = installer::systemactions::create_directories("stripped", $languagestringref);
96
97    if (! installer::existence::exists_in_array($strippeddirbase, \@installer::globals::removedirs))
98    {
99        push(@installer::globals::removedirs, $strippeddirbase);
100    }
101
102    for ( my $i = 0; $i <= $#{$filelist}; $i++ )
103    {
104        my $sourcefilename = ${$filelist}[$i]->{'sourcepath'};
105
106        if ( need_to_strip($sourcefilename) )
107        {
108            my $shortfilename = $sourcefilename;
109            installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$shortfilename);
110
111            $infoline = "Strip: $shortfilename\n";
112            push( @installer::globals::logfileinfo, $infoline);
113
114            # copy file into directory for stripped libraries
115
116            my $onelanguage = ${$filelist}[$i]->{'specificlanguage'};
117
118            # files without language into directory "00"
119
120            if ($onelanguage eq "") { $onelanguage = "00"; }
121
122            my $strippeddir = $strippeddirbase . $installer::globals::separator . $onelanguage;
123            installer::systemactions::create_directory($strippeddir);   # creating language specific subdirectories
124
125            my $destfilename = $strippeddir . $installer::globals::separator . $shortfilename;
126            installer::systemactions::copy_one_file($sourcefilename, $destfilename);
127
128            # change sourcepath in files collector
129
130            ${$filelist}[$i]->{'sourcepath'} = $destfilename;
131
132            # strip file
133
134            do_strip($destfilename);
135        }
136    }
137}
138
1391;
140