Index: scripts/build-rdeps.pl
===================================================================
--- scripts/build-rdeps.pl	(Revision 1843)
+++ scripts/build-rdeps.pl	(Arbeitskopie)
@@ -51,6 +51,10 @@
 
 Ignore the given component (e.g. main, contrib, non-free).
 
+=item B<--origin>
+
+Select another origin (such as "Debian") to be searched for build-depends.
+
 =item B<-m> B<--print-maintainer>
 
 Print the value of the maintainer field for each package.
@@ -82,15 +86,16 @@
 my $version = '1.0';
 my $dctrl = "/usr/bin/grep-dctrl";
 my $sources_path = "/var/lib/apt/lists/";
-my $source_pattern = ".*_dists_(sid|unstable)_.*Sources\$";
+my $release_pattern = "(.*_dists_(sid|unstable))_Release\$";
+my %seen_origins;
 my @source_files;
-my $sources_count=0;
 my $opt_debug;
 my $opt_update;
 my $opt_sudo;
 my $opt_maintainer;
 my $opt_mainonly;
 my $opt_distribution;
+my $opt_origin = "Debian";
 my @opt_exclude_components;
 
 if (!(-x $dctrl)) {
@@ -124,6 +129,8 @@
    -m, --print-maintainer         Print the maintainer information (experimental)
    --distribution distribution    Select a distribution to search for build-depends
                                   (Default: unstable)
+   --origin origin                Select an origin to search for build-depends
+                                  (Default: Debian)
    --only-main                    Ignore contrib and non-free
    --exclude-component COMPONENT  Ignore the specified component (can be given multiple times)
 
@@ -133,6 +140,7 @@
 
 # Sub to test if a given section shall be included in the result
 sub test_for_valid_component {
+    $_ = shift;
     if ($opt_mainonly and /(contrib|non-free)/) {
 	return -1;
     }
@@ -142,20 +150,48 @@
 	    }
     }
 
-    print STDERR "DEBUG: Component ($_) may not be excluded." if ($opt_debug);
+    print STDERR "DEBUG: Component ($_) may not be excluded.\n" if ($opt_debug);
     return 0;
 }
 
-sub findsources {
-	if (/$source_pattern/ and $sources_count <= 3) {
-	    if (test_for_valid_component($_) == 0) {
-		push(@source_files, $_);
-		$sources_count+=1;
-		print STDERR "DEBUG: Added source file: $_ (#$sources_count)\n" if ($opt_debug);
-	    }
+# Scan Release files and add appropriate Sources files
+sub readrelease {
+	my $file = $_;
+	my $base = $1;
+	open(RELEASE, "<$sources_path/$file");
+	while (<RELEASE>) {
+		if (/^Origin:\s*(.*)$/) {
+			# skip undesired origins
+			last if ($opt_origin) and ($1 ne $opt_origin);
+			# we also don't use an origin twice
+			last if $seen_origins{$1};
+			$seen_origins{$1} = 1;
+		}
+		elsif (/^(MD5|SHA)/) {
+			# from a list of checksums, grab names of Sources files
+			while (<RELEASE>) {
+				last unless /^ /;
+				if (/([^ ]+\/Sources)$/) {
+					addsources($base, $1);
+				}
+			}
+			last;
+		}
 	}
+	close(RELEASE);
 }
 
+# Add a *_Sources file if test_for_valid_component likes it
+sub addsources {
+	my ($base, $filename) = @_;
+	$filename =~ s/\//_/g;			# main/source/Sources
+	$filename = "${base}_${filename}";	# -> ftp.debian.org_..._main_source_Sources
+	if (test_for_valid_component($filename) == 0) {
+		push(@source_files, $filename);
+		print STDERR "DEBUG: Added source file: $_\n" if ($opt_debug);
+	}
+}
+
 sub findreversebuilddeps {
 	my ($package, $source_file) = @_;
 	my %packages;
@@ -223,6 +259,7 @@
 	"distribution=s" => \$opt_distribution,
 	"only-main" => \$opt_mainonly,
 	"exclude-component=s" => \@opt_exclude_components,
+	"origin=s" => \$opt_origin,
 	"d|debug" => \$opt_debug,
 	"h|help" => sub { usage; },
 	"v|version" => sub { version; }
@@ -248,12 +285,12 @@
 }
 
 if ($opt_distribution) {
-	print STDERR "DEBUG: Setting distribution to $opt_distribution" if ($opt_debug);
-	$source_pattern = ".*_dists_" . $opt_distribution . "_.*Sources\$";
+	print STDERR "DEBUG: Setting distribution to $opt_distribution\n" if ($opt_debug);
+	$release_pattern = "(.*_dists_" . $opt_distribution . ")_Release\$";
 }
 
 # Find sources files
-find(\&findsources, $sources_path);
+find(sub { readrelease($_) if /$release_pattern/ }, $sources_path);
 
 if (($#source_files+1) <= 0) {
 	die "$progname: unable to find sources files.\nDid you forget to run apt-get update (or add --update to this command)?";
