#!/bin/sh
#!perl -w # --*- Perl -*--
eval 'exec perl -x $0 ${1+"$@"}'
    if 0;
#------------------------------------------------------------------------------
#$Author: andrius $
#$Date: 2017-05-15 11:15:53 +0300 (Mon, 15 May 2017) $
#$Revision: 5250 $
#$URL: svn://www.crystallography.net/cod-tools/tags/v2.6/tools/mkperldepend $
#------------------------------------------------------------------------------

use strict;
use warnings;
use Module::ScanDeps;

local $\ = "\n";

foreach my $file (@ARGV) {
    my $stderr;
    close( STDERR );
    open( STDERR, '>', \$stderr );
    my @deps = keys %{ scan_deps( files => [ $file ],
                                  recurse => 1,
                                  warn_missing => 1 ) };
    close( STDERR );
    while( $stderr =~ /Could not find source file '([^']+)'/g ) {
        push @deps, $1;
    }
    print "$file: ", join( ' ', sort map { "src/lib/perl5/$_" }
                                     grep {/^COD/} @deps );
}
