#!/usr/local/bin/perl
#
# makemixer: replicate input N times, replacing a single parameter
# with each of N settings in turn.  Intended for constructing a pile of
# make rules to emulate multidimensional pattern rules.
#
# The input comes from stdin (typicaly redirected from a file)
# the parameter and the list of settings are on the command line.
#
# Example:
#
# given this input file:
#	%.@foo@.o: $.c
#		gcc -Dbar=@foo@ -c $*.c
#
# This command:
#	makemixer foo k1 k2 k3
#
# will produce this output
#	%.k1.o: $.c
#       	gcc -Dbar=k1 -c $*.c
#	%.k2.o: $.c
#       	gcc -Dbar=k2 -c $*.c
#	%.k3.o: $.c
#       	gcc -Dbar=k3 -c $*.c
#

use English;

$param = shift(@ARGV);
@settings = @ARGV;

# disabling input record seperator (newline) enables
# <STDIN> to slurp whole file into string
undef $INPUT_RECORD_SEPARATOR;

$_ = <STDIN>;

foreach $val (@settings) {
	$out = $_;
	$out =~ s/\@$param\@/$val/g;
	print $out;
}
