+# Removes a whole substvar line.
+sub delsubstvar {
+ my $package=shift;
+ my $substvar=shift;
+
+ my $ext=pkgext($package);
+ my $substvarfile="debian/${ext}substvars";
+
+ if (-e $substvarfile) {
+ complex_doit("grep -v '^${substvar}=' $substvarfile > $substvarfile.new || true");
+ doit("mv", "$substvarfile.new","$substvarfile");
+ }
+}
+
+# Adds a dependency on some package to the specified
+# substvar in a package's substvar's file.
+sub addsubstvar {
+ my $package=shift;
+ my $substvar=shift;
+ my $deppackage=shift;
+ my $verinfo=shift;
+ my $remove=shift;
+
+ my $ext=pkgext($package);
+ my $substvarfile="debian/${ext}substvars";
+ my $str=$deppackage;
+ $str.=" ($verinfo)" if defined $verinfo && length $verinfo;
+
+ # Figure out what the line will look like, based on what's there
+ # now, and what we're to add or remove.
+ my $line="";
+ if (-e $substvarfile) {
+ my %items;
+ open(SUBSTVARS_IN, "$substvarfile") || die "read $substvarfile: $!";
+ while (<SUBSTVARS_IN>) {
+ chomp;
+ if (/^\Q$substvar\E=(.*)/) {
+ %items = map { $_ => 1} split(", ", $1);
+
+ last;
+ }
+ }
+ close SUBSTVARS_IN;
+ if (! $remove) {
+ $items{$str}=1;
+ }
+ else {
+ delete $items{$str};
+ }
+ $line=join(", ", keys %items);
+ }
+ elsif (! $remove) {
+ $line=$str;
+ }
+
+ if (length $line) {
+ complex_doit("echo '${substvar}=$line' >> $substvarfile");
+ }
+}
+
+# Reads in the specified file, one line at a time. splits on words,
+# and returns an array of arrays of the contents.
+# If a value is passed in as the second parameter, then glob