Fix MIPS bits/fcntl.h namespace (bug 17780).
[glibc.git] / scripts / test-installation.pl
blobcac15624dc4d828da7a9fa766a6a905efa0423e2
1 #! /usr/bin/perl -w
2 # Copyright (C) 1997-2015 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, see
18 # <http://www.gnu.org/licenses/>.
21 $PACKAGE = "libc";
22 $progname = $0;
23 if ($ENV{CC}) {
24 $CC = $ENV{CC};
25 } else {
26 $CC= "gcc";
28 if ($ENV{LD_SO}) {
29 $LD_SO = $ENV{LD_SO};
30 } else {
31 $LD_SO = "";
34 sub 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;
41 sub 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";
44 print "- Did you change the gcc specs file (necessary after upgrading from\n";
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;
57 arglist: 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";
62 print "Copyright (C) 2015 Free Software Foundation, Inc.\n";
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";
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;
80 # We expect none or one argument.
81 if ($#ARGV == -1) {
82 $soversions="soversions.mk";
83 } elsif ($#ARGV == 0) {
84 if (-d $ARGV[0]) {
85 $soversions = "$ARGV[0]/soversions.mk";
86 } else {
87 $soversions = $ARGV[0];
89 } else {
90 die "Wrong number of arguments.";
94 # Read names and versions of all shared libraries that are part of
95 # glibc
96 open SOVERSIONS, $soversions
97 or die ("Couldn't open $soversions in build directory!");
99 $link_libs = "";
100 %versions = ();
102 while (<SOVERSIONS>) {
103 next if (/^all-sonames/);
104 chop;
105 if (/^lib/) {
106 ($name, $version)= /^lib(.*)\.so-version=\.(.*)$/;
107 # Filter out some libraries we don't want to link:
108 # - nss_ldap since it's not yet available
109 # - libdb1 since it conflicts with libdb
110 # - libnss1_* from glibc-compat add-on
111 # - libthread_db since it contains unresolved references
112 # - it's just a test NSS module
113 # - We don't provide the libgcc so we don't test it
114 if ($name ne "nss_ldap" && $name ne "db1"
115 && !($name =~/^nss1_/) && $name ne "thread_db"
116 && $name ne "nss_test1" && $name ne "libgcc_s") {
117 $link_libs .= " -l$name";
118 $versions{$name} = $version;
120 } elsif ($LD_SO ne "") {
121 ($ld_so_name, $ld_so_version) = split ('\.so\.', $LD_SO);
122 } else {
123 if (/^ld\.so/) {
124 ($ld_so_name, $ld_so_version)= /=(.*)\.so\.(.*)$/;
129 close SOVERSIONS;
131 # Create test program and link it against all
132 # shared libraries
134 open PRG, ">/tmp/test-prg$$.c"
135 or die ("Couldn't write test file /tmp/test-prg$$.c");
137 print PRG '
138 #include <stdio.h>
139 #include <stdlib.h>
140 int main(void) {
141 printf ("Your new glibc installation seems to be ok.\n");
142 exit (0);
145 close PRG;
147 open GCC, "$CC /tmp/test-prg$$.c $link_libs -o /tmp/test-prg$$ 2>&1 |"
148 or die ("Couldn't execute $CC!");
150 while (<GCC>) {
151 print $_ if (! /warning/);
153 close GCC;
154 if ($?) {
155 print "Execution of $CC failed!\n";
156 &installation_problem;
159 # Test if test program is linked against the right versions of
160 # shared libraries
162 $ok = 1;
163 %found = ();
165 open LDD, "ldd /tmp/test-prg$$ |"
166 or die ("Couldn't execute ldd");
167 while (<LDD>) {
168 if (/^\s*lib/) {
169 ($name, $version1, $version2) =
170 /^\s*lib(\w*)\.so\.([0-9\.]*)\s*=>.*\.so\.([0-9\.]*)/;
171 $found{$name} = 1;
172 if ($versions{$name} ne $version1 || $version1 ne $version2) {
173 print "Library lib$name is not correctly installed.\n";
174 print "Please check your installation!\n";
175 print "Offending line of ldd output: $_\n";
176 $ok = 0;
179 if (/$ld_so_name/) {
180 ($version1) = /$ld_so_name\.so\.([0-9\.]*)/;
181 if ($version1 ne $ld_so_version) {
182 print "The dynamic linker $ld_so_name.so is not correctly installed.\n";
183 print "Please check your installation!\n";
184 print "Offending line of ldd output: $_\n";
185 $ok = 0;
190 close LDD;
191 die "ldd execution failed" if $?;
193 foreach (keys %versions) {
194 unless ($found{$_}) {
195 print "Library lib$_ is not correctly installed since the test program\n";
196 print "was not linked dynamically against it.\n";
197 print "Do you have a file/link lib$_.so?\n";
198 $ok = 0;
202 &installation_problem unless $ok;
204 # Finally execute the test program
205 system ("/tmp/test-prg$$") == 0
206 or die ("Execution of test program failed");
208 # Clean up after ourselves
209 unlink ("/tmp/test-prg$$", "/tmp/test-prg$$.c");