38.4 Saturate Dependencies

The following function is called for each key in the DEP hash as represented by the variable LIBfile. The procedure recursively sets the appropriate dependencies.

For example, if a depends on b and b depends on c, then also a depends on c. The latter dependency is explicitly added.

The following code should not break if cyclic dependencies occur. Thus we mark whether we have already seen a file and do not recurse further.

521saturate dependencies 521  (507b)
sub saturateDependencies {
    my($LIBfile)=@_;
    my($AlreadySeen)={};
    &saturateRecursive($LIBfile, $LIBfile, 0, $AlreadySeen);
}

sub saturateRecursive {
    my($LIBfile, $recursive, $depth, $AlreadySeen)=@_;
    my(@circular)=();
    &setDependency($LIBfile, $recursive);
    if ($AlreadySeen->{$recursive} == 1) { #don’t recurse
        if ($LIBfile eq $recursive) {
            push @circular, $recursive;
            return @circular;
        }
        return @circular;
    }
    $AlreadySeen->{$recursive}=1;
    for $f (keys %{$DEP{$recursive}}) {
        @circular = &saturateRecursive($LIBfile, $f, $depth+1, $AlreadySeen);
        if (scalar(@circular) > 0) {
            push @circular, $recursive;
            return @circular;
        }
    }
    return @circular; # no circular dependency
}

Defines:
saturateDependencies, used in chunks 505a, 506b, and 518.

Uses DEP 504c and setDependency 512.