Update.
[glibc.git] / scripts / test-installation.pl
bloba68edc8af01eefc9b980d3b492ba37b283d78866
1 #! /usr/bin/perl -w
3 # Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
5 # Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1997.
7 # The GNU C Library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Library General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # The GNU C Library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Library General Public License for more details.
17 # You should have received a copy of the GNU Library General Public
18 # License along with the GNU C Library; see the file COPYING.LIB. If not,
19 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 # Boston, MA 02111-1307, USA.
23 $PACKAGE = "libc";
24 $progname = $0;
25 if ($ENV{CC}) {
26 $CC = $ENV{CC};
27 } else {
28 $CC= "gcc";
31 sub usage {
32 print "Usage: test-installation [soversions.mk]\n";
33 print " --help print this help, then exit\n";
34 print " --version print version number, then exit\n";
35 exit 0;
38 sub installation_problem {
39 print "The script has found some problems with your installation!\n";
40 print "Please read the FAQ and the README file and check the following:\n";
41 print "- Did you change the gcc specs file (necessary after upgrading from\n";
42 print " Linux libc5)?\n";
43 print "- Are there any symbolic links of the form libXXX.so to old libraries?\n";
44 print " Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong,\n";
45 print " libm.so should point to the newly installed glibc file - and there should be\n";
46 print " only one such link (check e.g. /lib and /usr/lib)\n";
47 print "You should restart this script from your build directory after you've\n";
48 print "fixed all problems!\n";
49 print "Btw. the script doesn't work if you're installing GNU libc not as your\n";
50 print "primary library!\n";
51 exit 1;
54 arglist: while (@ARGV) {
55 if ($ARGV[0] eq "--v" || $ARGV[0] eq "--ve" || $ARGV[0] eq "--ver" ||
56 $ARGV[0] eq "--vers" || $ARGV[0] eq "--versi" ||
57 $ARGV[0] eq "--versio" || $ARGV[0] eq "--version") {
58 print "test-installation (GNU $PACKAGE)\n";
59 print "Copyright (C) 1997, 1998 Free Software Foundation, Inc.\n";
60 print "This is free software; see the source for copying conditions. There is NO\n";
61 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
62 print "Written by Andreas Jaeger <aj\@arthur.rhein-neckar.de>\n";
64 exit 0;
65 } elsif ($ARGV[0] eq "--h" || $ARGV[0] eq "--he" || $ARGV[0] eq "--hel" ||
66 $ARGV[0] eq "--help") {
67 &usage;
68 } elsif ($ARGV[0] =~ /^-/) {
69 print "$progname: unrecognized option `$ARGV[0]'\n";
70 print "Try `$progname --help' for more information.\n";
71 exit 1;
72 } else {
73 last arglist;
77 # We expect none or one argument.
78 if ($#ARGV == -1) {
79 $soversions="soversions.mk";
80 } elsif ($#ARGV == 0) {
81 if (-d $ARGV[0]) {
82 $soversions = "$ARGV[0]/soversions.mk";
83 } else {
84 $soversions = $ARGV[0];
86 } else {
87 die "Wrong number of arguments.";
91 # Read names and versions of all shared libraries that are part of
92 # glibc
93 open SOVERSIONS, $soversions
94 or die ("Couldn't open $soversions in build directory!");
96 $link_libs = "";
97 %versions = ();
99 while (<SOVERSIONS>) {
100 next if (/^all-sonames/);
101 chop;
102 if (/^lib/) {
103 ($name, $version)= /^lib(.*)\.so-version=\.(.*)$/;
104 # Filter out some libraries we don't want to link:
105 # - nss_ldap since it's not yet available
106 # - libdb1 since it conflicts with libdb
107 # - libnss1_* from glibc-compat add-on
108 # - libthread_db since it contains unresolved references
109 if ($name ne "nss_ldap" && $name ne "db1"
110 && !($name =~/^nss1_/) && $name ne "thread_db") {
111 $link_libs .= " -l$name";
112 $versions{$name} = $version;
114 } else {
115 if (/^ld\.so/) {
116 ($ld_so_name, $ld_so_version)= /=(.*)\.so\.(.*)$/;
121 close SOVERSIONS;
123 # Create test program and link it against all
124 # shared libraries
126 open PRG, ">/tmp/test-prg$$.c"
127 or die ("Couldn't write test file /tmp/test-prg$$.c");
129 print PRG '
130 #include <stdio.h>
131 #include <stdlib.h>
132 int main(void) {
133 printf ("Your new glibc installation seems to be ok.\n");
134 exit (0);
137 close PRG;
139 open GCC, "$CC /tmp/test-prg$$.c $link_libs -o /tmp/test-prg$$ 2>&1 |"
140 or die ("Couldn't execute $CC!");
142 while (<GCC>) {
143 print $_ if (! /warning/);
145 close GCC;
146 if ($?) {
147 print "Execution of $CC failed!\n";
148 &installation_problem;
151 # Test if test program is linked against the right versions of
152 # shared libraries
154 $ok = 1;
155 %found = ();
157 open LDD, "ldd /tmp/test-prg$$ |"
158 or die ("Couldn't execute ldd");
159 while (<LDD>) {
160 if (/^\s*lib/) {
161 ($name, $version1, $version2) =
162 /^\s*lib(\w*)\.so\.([0-9\.]*)\s*=>.*\.so\.([0-9\.]*)/;
163 $found{$name} = 1;
164 if ($versions{$name} ne $version1 || $version1 ne $version2) {
165 print "Library lib$name is not correctly installed.\n";
166 print "Please check your installation!\n";
167 print "Offending line of ldd output: $_\n";
168 $ok = 0;
171 if (/$ld_so_name/) {
172 ($version1, $version2) =
173 /$ld_so_name\.so\.([0-9\.]*)\s*=>.*\.so\.([0-9\.]*)/;
174 if ($version1 ne $version2 || $version1 ne $ld_so_version) {
175 print "The dynamic linker $ld_so_name.so is not correctly installed.\n";
176 print "Please check your installation!\n";
177 print "Offending line of ldd output: $_\n";
178 $ok = 0;
183 close LDD;
184 die "ldd execution failed" if $?;
186 foreach (keys %versions) {
187 unless ($found{$_}) {
188 print "Library lib$_ is not correctly installed since the test program\n";
189 print "was not linked dynamically against it.\n";
190 print "Do you have a file/link lib$_.so?\n";
191 $ok = 0;
195 &installation_problem unless $ok;
197 # Finally execute the test program
198 system ("/tmp/test-prg$$") == 0
199 or die ("Execution of test program failed");
201 # Clean up after ourselves
202 unlink ("/tmp/test-prg$$", "/tmp/test-prg$$.c");