| 1 |
#! /usr/bin/perl |
| 2 |
use warnings; |
| 3 |
use strict; |
| 4 |
|
| 5 |
my %subst = (); |
| 6 |
while ($ARGV[0] =~ /(.*?)=(.*)/) { |
| 7 |
$subst{$1} = $2; |
| 8 |
shift; |
| 9 |
} |
| 10 |
|
| 11 |
die "no package specified\n" unless exists $subst{PACKAGE}; |
| 12 |
(my $package = $subst{PACKAGE}) =~ s/-(?:bin|dbg)$//; |
| 13 |
|
| 14 |
my $grub_dir_path = "debian/tmp-$package/usr/lib/grub"; |
| 15 |
opendir my $grub_dir, $grub_dir_path or die "can't opendir $grub_dir_path: $!"; |
| 16 |
my @cpu_platforms = grep { !/^\./ } readdir $grub_dir; |
| 17 |
closedir $grub_dir; |
| 18 |
|
| 19 |
$subst{FIRST_CPU_PLATFORM} = $cpu_platforms[0]; |
| 20 |
|
| 21 |
sub emit ($) { |
| 22 |
my $line = shift; |
| 23 |
while (my ($key, $value) = each %subst) { |
| 24 |
$line =~ s/\@$key\@/$value/g; |
| 25 |
} |
| 26 |
print $line; |
| 27 |
} |
| 28 |
|
| 29 |
while (<>) { |
| 30 |
if (/\@CPU_PLATFORM\@/) { |
| 31 |
for my $cpu_platform (@cpu_platforms) { |
| 32 |
(my $line = $_) =~ s/\@CPU_PLATFORM\@/$cpu_platform/g; |
| 33 |
emit($line); |
| 34 |
} |
| 35 |
} else { |
| 36 |
emit($_); |
| 37 |
} |
| 38 |
} |