]> git.ipfire.org Git - thirdparty/glibc.git/blame - scripts/test-installation.pl
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / scripts / test-installation.pl
CommitLineData
48d0341c 1#!/usr/bin/perl -w
04277e02 2# Copyright (C) 1997-2019 Free Software Foundation, Inc.
cc3fa755
UD
3# This file is part of the GNU C Library.
4# Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1997.
5
6# The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
7# modify it under the terms of the GNU Lesser General Public
8# License as published by the Free Software Foundation; either
9# version 2.1 of the License, or (at your option) any later version.
cc3fa755
UD
10
11# The GNU C Library is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 14# Lesser General Public License for more details.
cc3fa755 15
41bdb6e2 16# You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
17# License along with the GNU C Library; if not, see
18# <http://www.gnu.org/licenses/>.
cc3fa755
UD
19
20
21$PACKAGE = "libc";
22$progname = $0;
23if ($ENV{CC}) {
24 $CC = $ENV{CC};
25} else {
26 $CC= "gcc";
27}
d22e28b0
L
28if ($ENV{LD_SO}) {
29 $LD_SO = $ENV{LD_SO};
30} else {
31 $LD_SO = "";
32}
cc3fa755
UD
33
34sub usage {
35 print "Usage: test-installation [soversions.mk]\n";
36 print " --help print this help, then exit\n";
37 print " --version print version number, then exit\n";
38 exit 0;
39}
40
41sub installation_problem {
42 print "The script has found some problems with your installation!\n";
43 print "Please read the FAQ and the README file and check the following:\n";
49c091e5 44 print "- Did you change the gcc specs file (necessary after upgrading from\n";
cc3fa755
UD
45 print " Linux libc5)?\n";
46 print "- Are there any symbolic links of the form libXXX.so to old libraries?\n";
47 print " Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong,\n";
48 print " libm.so should point to the newly installed glibc file - and there should be\n";
49 print " only one such link (check e.g. /lib and /usr/lib)\n";
50 print "You should restart this script from your build directory after you've\n";
51 print "fixed all problems!\n";
52 print "Btw. the script doesn't work if you're installing GNU libc not as your\n";
53 print "primary library!\n";
54 exit 1;
55}
56
57arglist: while (@ARGV) {
58 if ($ARGV[0] eq "--v" || $ARGV[0] eq "--ve" || $ARGV[0] eq "--ver" ||
59 $ARGV[0] eq "--vers" || $ARGV[0] eq "--versi" ||
60 $ARGV[0] eq "--versio" || $ARGV[0] eq "--version") {
61 print "test-installation (GNU $PACKAGE)\n";
09533208 62 print "Copyright (C) 2018 Free Software Foundation, Inc.\n";
cc3fa755
UD
63 print "This is free software; see the source for copying conditions. There is NO\n";
64 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
65 print "Written by Andreas Jaeger <aj\@arthur.rhein-neckar.de>\n";
66
67 exit 0;
68 } elsif ($ARGV[0] eq "--h" || $ARGV[0] eq "--he" || $ARGV[0] eq "--hel" ||
69 $ARGV[0] eq "--help") {
70 &usage;
71 } elsif ($ARGV[0] =~ /^-/) {
72 print "$progname: unrecognized option `$ARGV[0]'\n";
73 print "Try `$progname --help' for more information.\n";
74 exit 1;
75 } else {
76 last arglist;
77 }
78}
79
80# We expect none or one argument.
81if ($#ARGV == -1) {
27f10a09 82 $dir = ".";
cc3fa755 83 $soversions="soversions.mk";
a08e80d1 84 $config="config.make";
cc3fa755
UD
85} elsif ($#ARGV == 0) {
86 if (-d $ARGV[0]) {
27f10a09 87 $dir = $ARGV[0];
cc3fa755 88 $soversions = "$ARGV[0]/soversions.mk";
a08e80d1 89 $config = "$ARGV[0]/config.make";
cc3fa755 90 } else {
a08e80d1
AS
91 $soversions = $dir = $ARGV[0];
92 $dir =~ s!/?[^/]*/*$!!;
93 $config = $dir . "/config.make";
cc3fa755
UD
94 }
95} else {
96 die "Wrong number of arguments.";
97}
98
a08e80d1
AS
99if (system ("grep -q \"build-mathvec = yes\" $config") == 0) {
100 $build_mathvec = 1;
101} else {
102 $build_mathvec = 0;
103}
cc3fa755
UD
104
105# Read names and versions of all shared libraries that are part of
106# glibc
107open SOVERSIONS, $soversions
108 or die ("Couldn't open $soversions in build directory!");
109
110$link_libs = "";
111%versions = ();
112
113while (<SOVERSIONS>) {
114 next if (/^all-sonames/);
115 chop;
116 if (/^lib/) {
117 ($name, $version)= /^lib(.*)\.so-version=\.(.*)$/;
34a4b66d
UD
118 # Filter out some libraries we don't want to link:
119 # - nss_ldap since it's not yet available
120 # - libdb1 since it conflicts with libdb
d7a4856e 121 # - libthread_db since it contains unresolved references
9191c04a 122 # - it's just a test NSS module
6e236b92 123 # - We don't provide the libgcc so we don't test it
a08e80d1
AS
124 # - libmvec if it wasn't built
125 next if ($build_mathvec == 0 && $name eq "mvec");
c1349648 126 if ($name ne "nss_ldap" && $name ne "db1"
644d3857 127 && $name ne "thread_db"
6e236b92 128 && $name ne "nss_test1" && $name ne "libgcc_s") {
cc3fa755
UD
129 $link_libs .= " -l$name";
130 $versions{$name} = $version;
131 }
d22e28b0
L
132 } elsif ($LD_SO ne "") {
133 ($ld_so_name, $ld_so_version) = split ('\.so\.', $LD_SO);
cc3fa755
UD
134 } else {
135 if (/^ld\.so/) {
136 ($ld_so_name, $ld_so_version)= /=(.*)\.so\.(.*)$/;
137 }
138 }
139}
140
141close SOVERSIONS;
142
143# Create test program and link it against all
144# shared libraries
145
27f10a09
JM
146open PRG, ">$dir/test-prg$$.c"
147 or die ("Couldn't write test file $dir/test-prg$$.c");
cc3fa755
UD
148
149print PRG '
cba1ddc1 150#include <stdio.h>
cc3fa755
UD
151#include <stdlib.h>
152int main(void) {
153 printf ("Your new glibc installation seems to be ok.\n");
154 exit (0);
155}
156';
157close PRG;
158
27f10a09 159open GCC, "$CC $dir/test-prg$$.c $link_libs -o $dir/test-prg$$ 2>&1 |"
cc3fa755
UD
160 or die ("Couldn't execute $CC!");
161
162while (<GCC>) {
163 print $_ if (! /warning/);
164}
165close GCC;
166if ($?) {
167 print "Execution of $CC failed!\n";
168 &installation_problem;
169}
170
171# Test if test program is linked against the right versions of
172# shared libraries
173
174$ok = 1;
175%found = ();
176
27f10a09 177open LDD, "ldd $dir/test-prg$$ |"
cc3fa755
UD
178 or die ("Couldn't execute ldd");
179while (<LDD>) {
180 if (/^\s*lib/) {
181 ($name, $version1, $version2) =
182 /^\s*lib(\w*)\.so\.([0-9\.]*)\s*=>.*\.so\.([0-9\.]*)/;
183 $found{$name} = 1;
184 if ($versions{$name} ne $version1 || $version1 ne $version2) {
185 print "Library lib$name is not correctly installed.\n";
186 print "Please check your installation!\n";
187 print "Offending line of ldd output: $_\n";
188 $ok = 0;
189 }
190 }
191 if (/$ld_so_name/) {
610e3e7f
UD
192 ($version1) = /$ld_so_name\.so\.([0-9\.]*)/;
193 if ($version1 ne $ld_so_version) {
cc3fa755
UD
194 print "The dynamic linker $ld_so_name.so is not correctly installed.\n";
195 print "Please check your installation!\n";
196 print "Offending line of ldd output: $_\n";
197 $ok = 0;
198 }
199 }
200}
201
202close LDD;
203die "ldd execution failed" if $?;
204
205foreach (keys %versions) {
206 unless ($found{$_}) {
207 print "Library lib$_ is not correctly installed since the test program\n";
208 print "was not linked dynamically against it.\n";
209 print "Do you have a file/link lib$_.so?\n";
210 $ok = 0;
211 }
212}
213
214&installation_problem unless $ok;
215
216# Finally execute the test program
27f10a09 217system ("$dir/test-prg$$") == 0
cc3fa755
UD
218 or die ("Execution of test program failed");
219
220# Clean up after ourselves
27f10a09 221unlink ("$dir/test-prg$$", "$dir/test-prg$$.c");