#!/usr/bin/perl -w
# This script reads configure.ac, and replaces all occurences of
# @.+@ in script and manpage with values.
# It returns 0 on success, 1 if it missed something.
#
# Stéphane (kwisatz) Jourdois <kwisatz@rubis.org>
# Mon, 16 Aug 2004 15:22:24 +0200

use strict;

my %vars = (
	'PERL' => '/usr/bin/perl',
);

my ($from, $to) = @ARGV;

open AC, '<configure.ac' or die "Cannot read configure.ac: $!\n";

while (<AC>) {
	if (/^AC_INIT\((\w+), ([0-9.]+), .+\)/) {
		$vars{'PACKAGE_NAME'} = $1;
		$vars{'PACKAGE_VERSION'} = $2;

		# Remove this line if there is are
		# other interesting lines in configure.ac
		# For now there isn't.
		last;
	}
}
close AC;

open FROM, "<$from" or die "Cannot read $from: $!\n";
open TO, ">$to" or die "Cannot write $to: $!\n";

while (<FROM>) {
	for my $var (keys %vars) {
		s/\@$var\@/$vars{$var}/g;
	}
	print TO;
}

close FROM;
close TO;
