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