e4f1e2c985
indirect run dependencies which needs a little more code
86 lines
2.6 KiB
Perl
Executable File
86 lines
2.6 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
# $OpenBSD: check-indirect-dependencies,v 1.2 2006/12/15 09:58:55 sturm Exp $
|
|
# Copyright (c) 2006 Nikolay Sturm <sturm@openbsd.org>.
|
|
#
|
|
# 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 OPENBSD PROJECT AND CONTRIBUTORS
|
|
# ``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 OPENBSD
|
|
# PROJECT OR CONTRIBUTORS 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.
|
|
|
|
# reduce the amount of direct dependencies by pointing out those which
|
|
# are pulled in as indirect dependencies
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
my $mainport;
|
|
my $make = $ENV{MAKE} || "make";
|
|
|
|
sub check_deps($)
|
|
{
|
|
my $kind = shift;
|
|
my %directdeps;
|
|
my %indirectdeps;
|
|
my @dirstack;
|
|
|
|
print "checking $kind dependencies\n";
|
|
|
|
open(my $dirdepends, "-|", "$make $kind-dir-depends") or
|
|
die "Cannot execute '$make $kind-dir-depends': $!\n";
|
|
while (<$dirdepends>) {
|
|
chomp;
|
|
my ($port, $dep) = split;
|
|
$mainport = $port if not defined $mainport;
|
|
|
|
if (not @dirstack) {
|
|
push @dirstack, $port;
|
|
push @dirstack, $dep;
|
|
} elsif ($dirstack[-1] eq $port) {
|
|
push @dirstack, $dep;
|
|
} else {
|
|
while ($dirstack[-1] ne $port) {
|
|
pop @dirstack;
|
|
}
|
|
push @dirstack, $dep;
|
|
}
|
|
|
|
if ($port eq $mainport) {
|
|
if (exists $indirectdeps{$dep}) {
|
|
print "\nprobably unneeded dependency: $dep\n";
|
|
print "@{$indirectdeps{$dep}}\n";
|
|
next;
|
|
}
|
|
$directdeps{$dep} = 1;
|
|
} else {
|
|
if (exists $directdeps{$dep}) {
|
|
print "\nprobably unneeded dependency: $dep\n";
|
|
print "@dirstack\n";
|
|
}
|
|
$indirectdeps{$dep} = [ @dirstack ];
|
|
}
|
|
}
|
|
close $dirdepends;
|
|
}
|
|
|
|
for my $kind ("run") {
|
|
check_deps($kind);
|
|
}
|
|
|