# $Id: gen_module_libs,v 1.2 2003/10/18 16:20:28 jeff Exp $

# gen_module_libs -- generates list of module shared objects for linking

use Config;
use File::Spec;
use ExtUtils::Installed;

my @mods = @ARGV;
if ($#mods < 0) {
	# don't run if we're not linking with any modules
	exit(0);
}

# set some per-system values and initialize ExtUtils::Installed
my $dlext = $Config{'dlext'};
my $archlib = $Config{'installarchlib'};
my $i = ExtUtils::Installed->new();

# find requested core modules
my @so;
my %found;
foreach my $m (@mods) {
	my $path = File::Spec->catfile($archlib, 'auto', split(/::/, $m));
	my @files = grep(/\.$dlext$/, $i->files('Perl', 'all', $path));
	if ($#files > -1) {
		push(@so, @files);
		$found{$m} = 1;
	}
}

# find other non-core modules, excluding ExtProc, which is statically linked
# make sure we don't search for core modules, or ExtUtils::Installed will croak
foreach my $m (@mods) {
	next if (exists($found{$m}) || $m eq 'ExtProc');
	push(@so, grep(/\.$dlext$/, $i->files($m)));
}

print join(' ', @so), "\n";
