Blame scripts/test-installation.pl

Packit 6c4009
#!/usr/bin/perl -w
Packit 6c4009
# Copyright (C) 1997-2018 Free Software Foundation, Inc.
Packit 6c4009
# This file is part of the GNU C Library.
Packit 6c4009
# Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1997.
Packit 6c4009
Packit 6c4009
# The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
# modify it under the terms of the GNU Lesser General Public
Packit 6c4009
# License as published by the Free Software Foundation; either
Packit 6c4009
# version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
# The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
# Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
# You should have received a copy of the GNU Lesser General Public
Packit 6c4009
# License along with the GNU C Library; if not, see
Packit 6c4009
# <http://www.gnu.org/licenses/>.
Packit 6c4009
Packit 6c4009
Packit 6c4009
$PACKAGE = "libc";
Packit 6c4009
$progname = $0;
Packit 6c4009
if ($ENV{CC}) {
Packit 6c4009
  $CC = $ENV{CC};
Packit 6c4009
} else {
Packit 6c4009
  $CC= "gcc";
Packit 6c4009
}
Packit 6c4009
if ($ENV{LD_SO}) {
Packit 6c4009
  $LD_SO = $ENV{LD_SO};
Packit 6c4009
} else {
Packit 6c4009
  $LD_SO = "";
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
sub usage {
Packit 6c4009
  print "Usage: test-installation [soversions.mk]\n";
Packit 6c4009
  print "  --help       print this help, then exit\n";
Packit 6c4009
  print "  --version    print version number, then exit\n";
Packit 6c4009
  exit 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
sub installation_problem {
Packit 6c4009
  print "The script has found some problems with your installation!\n";
Packit 6c4009
  print "Please read the FAQ and the README file and check the following:\n";
Packit 6c4009
  print "- Did you change the gcc specs file (necessary after upgrading from\n";
Packit 6c4009
  print "  Linux libc5)?\n";
Packit 6c4009
  print "- Are there any symbolic links of the form libXXX.so to old libraries?\n";
Packit 6c4009
  print "  Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong,\n";
Packit 6c4009
  print "  libm.so should point to the newly installed glibc file - and there should be\n";
Packit 6c4009
  print "  only one such link (check e.g. /lib and /usr/lib)\n";
Packit 6c4009
  print "You should restart this script from your build directory after you've\n";
Packit 6c4009
  print "fixed all problems!\n";
Packit 6c4009
  print "Btw. the script doesn't work if you're installing GNU libc not as your\n";
Packit 6c4009
  print "primary library!\n";
Packit 6c4009
  exit 1;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
arglist: while (@ARGV) {
Packit 6c4009
  if ($ARGV[0] eq "--v" || $ARGV[0] eq "--ve" || $ARGV[0] eq "--ver" ||
Packit 6c4009
      $ARGV[0] eq "--vers" || $ARGV[0] eq "--versi" ||
Packit 6c4009
      $ARGV[0] eq "--versio" || $ARGV[0] eq "--version") {
Packit 6c4009
    print "test-installation (GNU $PACKAGE)\n";
Packit 6c4009
    print "Copyright (C) 2018 Free Software Foundation, Inc.\n";
Packit 6c4009
    print "This is free software; see the source for copying conditions.  There is NO\n";
Packit 6c4009
    print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
Packit 6c4009
    print "Written by Andreas Jaeger <aj\@arthur.rhein-neckar.de>\n";
Packit 6c4009
Packit 6c4009
    exit 0;
Packit 6c4009
  } elsif ($ARGV[0] eq "--h" || $ARGV[0] eq "--he" || $ARGV[0] eq "--hel" ||
Packit 6c4009
	   $ARGV[0] eq "--help") {
Packit 6c4009
    &usage;
Packit 6c4009
  } elsif ($ARGV[0] =~ /^-/) {
Packit 6c4009
    print "$progname: unrecognized option `$ARGV[0]'\n";
Packit 6c4009
    print "Try `$progname --help' for more information.\n";
Packit 6c4009
    exit 1;
Packit 6c4009
  } else {
Packit 6c4009
    last arglist;
Packit 6c4009
  }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
# We expect none or one argument.
Packit 6c4009
if ($#ARGV == -1) {
Packit 6c4009
    $dir = ".";
Packit 6c4009
    $soversions="soversions.mk";
Packit 6c4009
    $config="config.make";
Packit 6c4009
} elsif ($#ARGV == 0) {
Packit 6c4009
    if (-d $ARGV[0]) {
Packit 6c4009
      $dir = $ARGV[0];
Packit 6c4009
      $soversions = "$ARGV[0]/soversions.mk";
Packit 6c4009
      $config = "$ARGV[0]/config.make";
Packit 6c4009
    } else {
Packit 6c4009
      $soversions = $dir = $ARGV[0];
Packit 6c4009
      $dir =~ s!/?[^/]*/*$!!;
Packit 6c4009
      $config = $dir . "/config.make";
Packit 6c4009
    }
Packit 6c4009
} else {
Packit 6c4009
    die "Wrong number of arguments.";
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
if (system ("grep -q \"build-mathvec = yes\" $config") == 0) {
Packit 6c4009
    $build_mathvec = 1;
Packit 6c4009
} else {
Packit 6c4009
    $build_mathvec = 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
# Read names and versions of all shared libraries that are part of
Packit 6c4009
# glibc
Packit 6c4009
open SOVERSIONS, $soversions
Packit 6c4009
  or die ("Couldn't open $soversions in build directory!");
Packit 6c4009
Packit 6c4009
$link_libs = "";
Packit 6c4009
%versions = ();
Packit 6c4009
Packit 6c4009
while (<SOVERSIONS>) {
Packit 6c4009
  next if (/^all-sonames/);
Packit 6c4009
  chop;
Packit 6c4009
  if (/^lib/) {
Packit 6c4009
    ($name, $version)= /^lib(.*)\.so-version=\.(.*)$/;
Packit 6c4009
    # Filter out some libraries we don't want to link:
Packit 6c4009
    # - nss_ldap since it's not yet available
Packit 6c4009
    # - libdb1 since it conflicts with libdb
Packit 6c4009
    # - libthread_db since it contains unresolved references
Packit 6c4009
    # - it's just a test NSS module
Packit 6c4009
    # - We don't provide the libgcc so we don't test it
Packit 6c4009
    # - libmvec if it wasn't built
Packit 6c4009
    next if ($build_mathvec == 0 && $name eq "mvec");
Packit 6c4009
    if ($name ne "nss_ldap" && $name ne "db1"
Packit 6c4009
	&& $name ne "thread_db"
Packit 6c4009
	&& $name ne "nss_test1" && $name ne "libgcc_s") {
Packit 6c4009
      $link_libs .= " -l$name";
Packit 6c4009
      $versions{$name} = $version;
Packit 6c4009
    }
Packit 6c4009
  } elsif ($LD_SO ne "") {
Packit 6c4009
    ($ld_so_name, $ld_so_version) = split ('\.so\.', $LD_SO);
Packit 6c4009
  } else {
Packit 6c4009
    if (/^ld\.so/) {
Packit 6c4009
      ($ld_so_name, $ld_so_version)= /=(.*)\.so\.(.*)$/;
Packit 6c4009
    }
Packit 6c4009
  }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
close SOVERSIONS;
Packit 6c4009
Packit 6c4009
# Create test program and link it against all
Packit 6c4009
# shared libraries
Packit 6c4009
Packit 6c4009
open PRG, ">$dir/test-prg$$.c"
Packit 6c4009
  or die ("Couldn't write test file $dir/test-prg$$.c");
Packit 6c4009
Packit 6c4009
print PRG '
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
int main(void) {
Packit 6c4009
  printf ("Your new glibc installation seems to be ok.\n");
Packit 6c4009
  exit (0);
Packit 6c4009
}
Packit 6c4009
';
Packit 6c4009
close PRG;
Packit 6c4009
Packit 6c4009
open GCC, "$CC $dir/test-prg$$.c $link_libs -o $dir/test-prg$$ 2>&1 |"
Packit 6c4009
  or die ("Couldn't execute $CC!");
Packit 6c4009
Packit 6c4009
while (<GCC>) {
Packit 6c4009
  print $_ if (! /warning/);
Packit 6c4009
}
Packit 6c4009
close GCC;
Packit 6c4009
if ($?) {
Packit 6c4009
  print "Execution of $CC failed!\n";
Packit 6c4009
  &installation_problem;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
# Test if test program is linked against the right versions of
Packit 6c4009
# shared libraries
Packit 6c4009
Packit 6c4009
$ok = 1;
Packit 6c4009
%found = ();
Packit 6c4009
Packit 6c4009
open LDD, "ldd $dir/test-prg$$ |"
Packit 6c4009
  or die ("Couldn't execute ldd");
Packit 6c4009
while (<LDD>) {
Packit 6c4009
  if (/^\s*lib/) {
Packit 6c4009
    ($name, $version1, $version2) =
Packit 6c4009
      /^\s*lib(\w*)\.so\.([0-9\.]*)\s*=>.*\.so\.([0-9\.]*)/;
Packit 6c4009
    $found{$name} = 1;
Packit 6c4009
    if ($versions{$name} ne $version1 || $version1 ne $version2) {
Packit 6c4009
      print "Library lib$name is not correctly installed.\n";
Packit 6c4009
      print "Please check your installation!\n";
Packit 6c4009
      print "Offending line of ldd output: $_\n";
Packit 6c4009
      $ok = 0;
Packit 6c4009
    }
Packit 6c4009
  }
Packit 6c4009
  if (/$ld_so_name/) {
Packit 6c4009
    ($version1) = /$ld_so_name\.so\.([0-9\.]*)/;
Packit 6c4009
    if ($version1 ne $ld_so_version) {
Packit 6c4009
      print "The dynamic linker $ld_so_name.so is not correctly installed.\n";
Packit 6c4009
      print "Please check your installation!\n";
Packit 6c4009
      print "Offending line of ldd output: $_\n";
Packit 6c4009
      $ok = 0;
Packit 6c4009
    }
Packit 6c4009
  }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
close LDD;
Packit 6c4009
die "ldd execution failed" if $?;
Packit 6c4009
Packit 6c4009
foreach (keys %versions) {
Packit 6c4009
  unless ($found{$_}) {
Packit 6c4009
    print "Library lib$_ is not correctly installed since the test program\n";
Packit 6c4009
    print "was not linked dynamically against it.\n";
Packit 6c4009
    print "Do you have a file/link lib$_.so?\n";
Packit 6c4009
    $ok = 0;
Packit 6c4009
  }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
&installation_problem unless $ok;
Packit 6c4009
Packit 6c4009
# Finally execute the test program
Packit 6c4009
system ("$dir/test-prg$$") == 0
Packit 6c4009
  or die ("Execution of test program failed");
Packit 6c4009
Packit 6c4009
# Clean up after ourselves
Packit 6c4009
unlink ("$dir/test-prg$$", "$dir/test-prg$$.c");