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