--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use WannaBuild; # for version compare
+
+if (!@ARGV) {
+ print STDERR "Usage: $0 Packages1 Packages2 ..\n";
+ print STDERR "\n";
+ print STDERR "This perl scripts reads the Packages files given on the command line and\n";
+ print STDERR "outputs a Packages file which contians each package exactly once, using the\n";
+ print STDERR "one with the highest version number.\n";
+ print STDERR "";
+ print STDERR "Since it only looks at Package: and Version:, it works with Sources files\n";
+ print STDERR "as well\n";
+ exit 1;
+}
+
+my %version;
+my %data;
+
+local($/) = ""; # read in paragraph mode
+while (<>) {
+ my( $version, $name );
+ /^Package:\s*(\S+)$/mi and $name = $1;
+ /^Version:\s*(\S+)$/mi and $version = $1;
+ if (!defined $name or !defined $version) {
+ warn "Stanza without Package or Version\n";
+ next;
+ }
+
+ if ((!exists $version{$name}) or version_less($version{name},$version)) {
+ $version{$name} = $version;
+ $data{$name} = $_;
+ }
+}
+
+foreach (values %data) {
+ s/\n*$/\n\n/;# always one empty line to separate stanzas
+ print;
+}
+