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