# Perl script to extract the object names
# from the various makefiles.in
# Expects that:
#	- the Makefile.in in the src subdirectory contains a SRCDIRS =
#		line with the sub directories containing the object files
#	- the Makefile.in in the sub directories each contain an OBJECTS =
#		line with all the .o files listed
# This works with continuation lines as well

$objs = "";

open(MF, "<./src/Makefile.in");
while (<MF>) {
    if (/^SRCDIRS\s+\=/) {
	$_ =~ s/^SRCDIRS\s+\=\s+//;
	chop($_);
	while (/\\/) {
	    $_ =~ s/\\/ /;
	    push(@subdirs, split);
	    $_ = <MF>;
	    chop($_);
	    $_ =~ s/^\s+//;
	}
	push(@subdirs, split);
	break;
    }
}
close(MF);

foreach $dir (@subdirs) {
    open(MF, "<./src/$dir/Makefile.in");
    while (<MF>) {
	if (/^OBJECTS/) {
	    $_ =~ s/^OBJECTS\s+\=\s+//;
	    chop($_);
	    while (/\\/) {
		$_ =~ s/\\/ /;
		foreach $file (split) {
		    $objs .= " \$(srcdir)/$dir/$file";
		}
		$_ = <MF>;
		chop($_);
		$_ =~ s/^\s+//;
	    }
	    foreach $file (split) {
		$objs .= " \$(srcdir)/$dir/$file";
	    }
	    break;
        }
    }
    close(MF);
}

print "$objs";
