better elf libs checker.

okay pvalchev@
This commit is contained in:
espie 2004-02-01 23:07:30 +00:00
parent b83b0bb04f
commit 1c19b2641b
2 changed files with 95 additions and 8 deletions

View File

@ -0,0 +1,87 @@
#!/usr/bin/perl -w
# $OpenBSD: check-libs-elf,v 1.1 2004/02/01 23:07:30 espie Exp $
# Copyright (c) 2001 Marc Espie
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Check that all libraries are mentioned in lib depends.
use strict;
sub find_library
{
my $libname = shift;
my $LIBDIR=$ENV{'PKG_DBDIR'};
my @list = `fgrep -l lib$libname.so $LIBDIR/*/+CONTENTS`;
local $_;
if (@list != 1) {
return '???';
}
my $pkgname = $list[0];
chomp $pkgname;
open(FILE, $pkgname);
while (<FILE>) {
chomp;
if (m/^\@comment subdir\=(\S+)/) {
close FILE;
return $1;
}
}
$pkgname =~ s|$LIBDIR/(.*?)/\+CONTENTS|$1|;
return $pkgname;
}
my $error = 0;
my %registered = map { s/.*\///; s/\.$//; s/(?:\.\d+){1,2}$//; ($_, 1); }
split(/[ ,\n]+/, $ENV{'LIB_DEPENDS'});
open(my $libs, '<', shift) or die;
open(my $builds, '<', shift) or die;
while (<$builds>) {
chomp;
if (m/^.*\/lib(.*?)\.so((?:\.\d+)*)$/) {
$registered{$1} = $2;
}
}
close($builds);
while (<$libs>) {
my ($name, $major, $minor);
chomp;
if (m/^lib(\S+)\s+(\d+)\s+(\d+)$/) {
($name, $major, $minor) = ($1, $2, $3);
} elsif (m/^lib(\S+)$/) {
$name = $1;
}
unless (defined $registered{$name}) {
print "lib-depends-check: no mention of $name (".find_library($name).")\n";
$error = 1;
}
}
close($libs);
exit($error);

View File

@ -1,6 +1,6 @@
#-*- mode: Makefile; tab-width: 4; -*-
# ex:ts=4 sw=4 filetype=make:
# $OpenBSD: bsd.port.mk,v 1.605 2004/01/28 22:15:21 espie Exp $
# $OpenBSD: bsd.port.mk,v 1.606 2004/02/01 23:07:30 espie Exp $
# $FreeBSD: bsd.port.mk,v 1.264 1996/12/25 02:27:44 imp Exp $
# $NetBSD: bsd.port.mk,v 1.62 1998/04/09 12:47:02 hubertf Exp $
#
@ -1305,6 +1305,7 @@ ${_DEP}-depends: ${_DEP${_DEP}_COOKIES}
# Do a brute-force ldd/objdump on all files under WRKINST.
.if ${ELF_TOOLCHAIN:L} == "no"
_CHECK_LIBS_SCRIPT=${PORTSDIR}/infrastructure/install/check-libs
${_LIBLIST}: ${_FAKE_COOKIE}
@${SUDO} mkdir -p ${WRKINST}/usr/libexec
@-${SUDO} cp -f /usr/libexec/ld.so ${WRKINST}/usr/libexec
@ -1316,14 +1317,13 @@ ${_LIBLIST}: ${_FAKE_COOKIE}
grep '^ '|\
sort -u >$@
.else
_CHECK_LIBS_SCRIPT=${PORTSDIR}/infrastructure/install/check-libs-elf
${_LIBLIST}: ${_FAKE_COOKIE}
@cd ${WRKINST} && ${SUDO} find . -type f|\
xargs objdump -p 2>/dev/null |\
grep NEEDED |\
sed 's/\ lib//g' |\
sed 's/ NEEDED / library: /g' |\
sed 's/\.so\./ /g' |\
sed 's/^\(.*\)\ \([^\.]*\)\.\([^\.]*\)/\1\ \2\ \3/g' |\
sed -n \
-e '/^ *NEEDED *\(.*\)\.so\.\([0-9][0-9]*\)\.\([0-9][0-9]*\)$$/s//\1 \2 \3/p' \
-e '/^ *NEEDED *\(.*\)\.so$$/s//\1/p'| \
sort -u >$@
.endif
@ -1334,7 +1334,7 @@ ${_BUILDLIBLIST}: ${_FAKE_COOKIE}
find /usr/lib -path /usr/lib -o -type d -prune -o -type f -print; \
find ${X11BASE}/lib -path ${X11BASE}/lib -o -type d -prune -o -type f -print; \
}|\
fgrep .so.|${SUDO} xargs file -L|fgrep 'shared'|cut -d\: -f1|sort -u >$@
egrep '(\.so\.|\.so$$)'|${SUDO} xargs file -L|fgrep 'shared'|cut -d\: -f1|sort -u >$@
@ -1358,7 +1358,7 @@ lib-depends-check: ${_LIBLIST} ${_BUILDLIBLIST}
@${_depfile_fragment}; \
LIB_DEPENDS="`${MAKE} _recurse-lib-depends-check`" \
PKG_DBDIR='${PKG_DBDIR}' \
perl ${PORTSDIR}/infrastructure/install/check-libs \
perl ${_CHECK_LIBS_SCRIPT} \
${_LIBLIST} ${_BUILDLIBLIST}
manpages-check: ${_FAKE_COOKIE}