summaryrefslogtreecommitdiff
path: root/Debian/Debhelper
diff options
context:
space:
mode:
Diffstat (limited to 'Debian/Debhelper')
-rw-r--r--Debian/Debhelper/Dh_Lib.pm23
1 files changed, 20 insertions, 3 deletions
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 10ae69f7..7b550b0e 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -504,7 +504,8 @@ sub pkgfilename {
# 1: package
# 2: script to add to
# 3: filename of snippet
-# 4: sed to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
+# 4: either text: shell-quoted sed to run on the snippet. Ie, 's/#PACKAGE#/$PACKAGE/'
+# or a sub to run on each line of the snippet. Ie sub { s/#PACKAGE#/$PACKAGE/ }
sub autoscript {
my $package=shift;
my $script=shift;
@@ -533,18 +534,34 @@ sub autoscript {
&& !compat(5)) {
# Add fragments to top so they run in reverse order when removing.
complex_doit("echo \"# Automatically added by ".basename($0)."\"> $outfile.new");
- complex_doit("sed \"$sed\" $infile >> $outfile.new");
+ autoscript_sed($sed, $infile, "$outfile.new");
complex_doit("echo '# End automatically added section' >> $outfile.new");
complex_doit("cat $outfile >> $outfile.new");
complex_doit("mv $outfile.new $outfile");
}
else {
complex_doit("echo \"# Automatically added by ".basename($0)."\">> $outfile");
- complex_doit("sed \"$sed\" $infile >> $outfile");
+ autoscript_sed($sed, $infile, $outfile);
complex_doit("echo '# End automatically added section' >> $outfile");
}
}
+sub autoscript_sed {
+ my $sed = shift;
+ my $infile = shift;
+ my $outfile = shift;
+ if (ref($sed) eq 'CODE') {
+ open(IN, $infile) or die "$infile: $!";
+ open(OUT, ">>$outfile") or die "$outfile: $!";
+ while (<IN>) { $sed->(); print OUT }
+ close(OUT) or die "$outfile: $!";
+ close(IN) or die "$infile: $!";
+ }
+ else {
+ complex_doit("sed \"$sed\" $infile >> $outfile");
+ }
+}
+
# Removes a whole substvar line.
sub delsubstvar {
my $package=shift;