xref: /AOO41X/main/solenv/bin/modules/installer/windows/strip.pm (revision fe22d2cfc602815794415026f1317bd625db6f83)
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    $installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
70
71    if ($returnvalue)
72    {
73        $installer::logger::Lang->printf("ERROR: Could not strip %s!\n", $filename);
74    }
75    else
76    {
77        $installer::logger::Lang->printf("SUCCESS: Stripped library %s!\n", $filename);
78    }
79}
80
81#####################################################################
82# Resolving all variables in the packagename.
83#####################################################################
84
85sub 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 (! installer::existence::exists_in_array($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_pathes($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            $installer::logger::Lang->printf("Strip: %s\n", $shortfilename);
125
126            # copy file into directory for stripped libraries
127
128            my $onelanguage = ${$filelist}[$i]->{'specificlanguage'};
129
130            # files without language into directory "00"
131
132            if ($onelanguage eq "") { $onelanguage = "00"; }
133
134            my $strippeddir = $strippeddirbase . $installer::globals::separator . $onelanguage;
135            installer::systemactions::create_directory($strippeddir);   # creating language specific subdirectories
136
137            my $destfilename = $strippeddir . $installer::globals::separator . $shortfilename;
138            installer::systemactions::copy_one_file($sourcefilename, $destfilename);
139
140            # change sourcepath in files collector
141
142            ${$filelist}[$i]->{'sourcepath'} = $destfilename;
143
144            # strip file
145
146            do_strip($destfilename);
147        }
148    }
149}
150
1511;
152