From d84c2891b3ad47419b42b742f9b1d56e31eb13cf Mon Sep 17 00:00:00 2001
From: Osamu Aoki <osamu@debian.org>
Date: Wed, 26 Aug 2015 09:03:17 +0000
Subject: [PATCH 2/3] mk-origtargz.pl

---
 scripts/mk-origtargz.pl | 48 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 39 insertions(+), 9 deletions(-)

diff --git a/scripts/mk-origtargz.pl b/scripts/mk-origtargz.pl
index ef2c75e..8602f46 100755
--- a/scripts/mk-origtargz.pl
+++ b/scripts/mk-origtargz.pl
@@ -41,7 +41,8 @@ mk-origtargz - rename upstream tarball, optionally changing the compression and
 B<mk-origtargz> renames the given file to match what is expected by
 B<dpkg-buildpackage>, based on the source package name and version in
 F<debian/changelog>. It can convert B<zip> to B<tar>, optionally change the
-compression scheme and remove files according to B<Files-Excluded> in
+compression scheme and remove files according to B<Files-Excluded> 
+and B<Files-Excluded->I<component> in
 F<debian/copyright>. The resulting file is placed in F<debian/../..>.
 
 If the package name is given via the B<--package> option, no information is
@@ -121,10 +122,22 @@ If the file has to be modified (because it is a B<zip> file, because of B<--repa
 If the given file is not compressed using the desired format (see
 B<--compression>), recompress it.
 
+=item B<-s>, B<--suffix> I<suffix>
+
+Always append I<suffix> to the upstream version.  (Useful for multiple upstream tarballs under 
+version=4.
+
 =item B<-S>, B<--repack-suffix> I<suffix>
 
 If the file has to be modified, because of B<Files-Excluded>, append I<suffix> to the upstream version.
 
+=item B<-c>, B<--component> I<componentname>
+
+Use <componentname> as the component name for the secondary upstream tarball.
+Set I<componentname> as the component namei.  This is used only for the 
+secondary upstream tarball of the Debian source package.  
+Then I<packagename_version.orig-componentiname.tar.gz> is created.
+
 =item B<--compression> [ B<gzip> | B<bzip2> | B<lzma> | B<xz> ]
 
 If B<--repack> is used, or if the given file is a B<zip> file, ensure that the resulting file is compressed using the given scheme. The default is B<gzip>.
@@ -179,6 +192,9 @@ sub compress_archive($$$);
 
 my $package = undef;
 my $version = undef;
+my $component = undef;
+my $orig="orig";
+my $excludestanza="Files-Excluded";
 my @exclude_globs = ();
 my @copyright_files = ();
 
@@ -186,7 +202,8 @@ my $destdir = undef;
 my $compression = "gzip";
 my $mode = undef; # can be symlink, rename or copy. Can internally be repacked if the file was repacked.
 my $repack = 0;
-my $suffix = '';
+my $suffix = undef;
+my $repacksuffix = '';
 
 my $upstream = undef;
 
@@ -207,6 +224,7 @@ sub setmode {
 GetOptions(
     "package=s" => \$package,
     "version|v=s" => \$version,
+    "component|c=s" => \$component,
     "exclude-file=s" => \@exclude_globs,
     "copyright-file=s" => \@copyright_files,
     "compression=s" => \$compression,
@@ -214,13 +232,20 @@ GetOptions(
     "rename" => \&setmode,
     "copy" => \&setmode,
     "repack" => \$repack,
-    'repack-suffix|S=s' => \$suffix,
+    'suffix|s=s' => \$suffix,
+    'repack-suffix|S=s' => \$repacksuffix,
     "directory|C=s" => \$destdir,
     "help|h" => sub { pod2usage({-exitval => 0, -verbose => 1}); },
 ) or pod2usage({-exitval => 3, -verbose=>1});
 
 $mode ||= "symlink";
 
+if (defined $suffix) {
+    $repacksuffix = $suffix;
+} else {
+    $suffix = "";
+}
+
 # sanity checks
 unless (compression_is_supported($compression)) {
     die_opts (sprintf "Unknown compression scheme %s", $compression);
@@ -230,6 +255,11 @@ if (defined $package and not defined $version) {
     die_opts "If you use --package, you also have to specify --version."
 }
 
+if (defined $component) {
+    $orig="orig-$component";
+    $excludestanza="Files-Excluded-$component";
+}
+
 if (@ARGV != 1) {
     die_opts "Please specify original tarball."
 }
@@ -287,14 +317,14 @@ for my $copyright_file (@copyright_files) {
 	     && defined $data->{format}
 	     && $data->{format} =~ m@^$okformat/?$@)
     {
-	if ($data->{'files-excluded'}) {
-	    push(@exclude_globs, grep { $_ } split(/\s+/, $data->{'files-excluded'}));
+	if ($data->{$excludestanza}) {
+	    push(@exclude_globs, grep { $_ } split(/\s+/, $data->{$excludestanza}));
 	}
     } else {
 	open my $file, '<', $copyright_file or die "Unable to read $copyright_file: $!\n";
 	while (my $line = <$file>) {
-	    if ($line =~ m/\bFiles-Excluded:/i) {
-		warn "WARNING: The file $copyright_file mentions Files-Excluded, but its ".
+	    if ($line =~ m/\b${excludestanza}.*:/i) {
+		warn "WARNING: The file $copyright_file mentions $excludestanza, but its ".
 		     "format is not recognized. Specify Format: ".
 		     "https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ ".
 		     "in order to remove files from the tarball with mk-origtargz.\n";
@@ -343,7 +373,7 @@ if ($is_tarfile and not $repack) {
 
 
 # Now we know what the final filename will be
-my $destfilebase = sprintf "%s_%s.orig.tar", $package, $version;
+my $destfilebase = sprintf "%s_%s%s.%s.tar", $package, $version, $suffix, $orig;
 my $destfiletar = sprintf "%s/%s", $destdir, $destfilebase;
 my $destext = compression_get_property($compression, "file_ext");
 my $destfile = sprintf "%s.%s", $destfiletar, $destext;
@@ -455,7 +485,7 @@ if (@exclude_globs) {
 }
 
 if ($deletecount) {
-    $destfilebase = sprintf "%s_%s%s.orig.tar", $package, $version, $suffix;
+    $destfilebase = sprintf "%s_%s%s.%s.tar", $package, $version, $repacksuffix, $orig;
     $destfiletar = sprintf "%s/%s", $destdir, $destfilebase;
     $destfile = sprintf "%s.%s", $destfiletar, $destext;
 
-- 
2.1.4

