/
relocate.pl
77 lines (53 loc) · 1.48 KB
/
relocate.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl -w
# relocate.pl
#
# Rewrite pathnames or other values that need to be hardcoded in
# files. Take a commented line, remove the leading hash character,
# substitute for the variable inside ~_~HERE~_~, and place the
# result on the line above the comment, like this:
=for example
Original:
#use lib '~_~INSTALLPRIVLIB~_~';
Output:
use lib '/home/jon/interchange/lib';
#use lib '~_~INSTALLPRIVLIB~_~';
=cut
# If the leading comment starts with #- then the output of the original
# commented line will be suppressed.
=for example
Original:
#-use lib '~_~INSTALLPRIVLIB~_~';
Output:
use lib '/home/jon/interchange/lib';
=cut
# A single output filename can be specified on the command line, and
# the input filename will be the same, with a .PL extension added.
# If no filename is given, just filter from stdin to stdout.
use strict;
use Config;
require './scripts/initp.pl';
sub doit {
my ($key) = @_;
my $val;
if ($MV::Self->{RPMBUILDDIR} and $val = $MV::Self->{$key}) {
$val =~ s!^$MV::Self->{RPMBUILDDIR}/!/!;
return $val;
}
return $MV::Self->{$key} unless $key =~ /[a-z]/;
return $Config{$key};
}
no warnings 'void';
DOIT: {
my ($input, $output);
$output = $ARGV[0];
$input = "$output.PL" if $output;
local ($/);
@ARGV = ($input) if $input;
local ($_) = <>;
s{.*\n(#(-?)(.*)~_~(\w+)~_~(.*))}{$3 . doit($4) . $5 . ($2 ? '' : "\n$1" )}eg;
if ($output) {
open STDOUT, ">$output" or die "Error creating $output: $!\n";
}
print;
close STDOUT;
}