Files
foc/l4/tool/bin/genexportpack
2013-01-11 17:00:47 +01:00

104 lines
2.8 KiB
Perl
Executable File

#! /usr/bin/perl -w
#
# (c) 2011 Technische Universität Dresden
# This file is part of TUD:OS and distributed under the terms of the
# GNU General Public License 2.
# Please see the COPYING-GPL-2 file for details.
#
# Adam Lackorzynski <adam@os.inf.tu-dresden.de>
#
use strict;
BEGIN { unshift @INC, $ENV{L4DIR}.'/tool/lib'
if $ENV{L4DIR} && -d $ENV{L4DIR}.'/tool/lib/L4';}
use L4::ModList;
use L4::Grub;
use File::Temp qw/tempdir/;
my $qemu = $ENV{QEMU} || 'qemu';
my $module_path = $ENV{SEARCHPATH} || ".";
my %opts = L4::Grub::parse_gengrub_args();
my $qemu_options = $ENV{QEMU_OPTIONS} || "";
my $modulesfile = shift;
my $targetdir = shift;
my $unzip_tmp = tempdir(CLEANUP => 1);
unless (defined $targetdir) {
print "usage: $0 MODULESFILE TARGETDIR entry1 [entry2] ...\n";
exit(1);
}
system("mkdir -p \"$targetdir\"");
open(GRUB1, ">$targetdir/menu.lst")
|| die "Cannot create '$targetdir/menu.lst': $!!";
open(GRUB2, ">$targetdir/grub.cfg")
|| die "Cannot create '$targetdir/grub.cfg': $!!";
open(QEMU, ">$targetdir/qemu.sh")
|| die "Cannot create '$targetdir/qemu.sh': $!!";
delete $opts{timeout}
if @ARGV > 1 and defined $opts{timeout} and $opts{timeout} == 0;
print GRUB1 L4::Grub::grub1_config_prolog(%opts);
print GRUB2 L4::Grub::grub2_config_prolog(%opts);
print QEMU "#! /bin/sh\n".
"case \"\$1\" in\n";
$qemu =~ s@.*/@@;
my %files;
sub qemu_get_file($$)
{
my $command = shift;
my $cmdline = shift;
my $fp = L4::ModList::get_file_uncompressed_or_die($command, $module_path,
$unzip_tmp);
$fp = (reverse split(/\/+/, $fp))[0];
$cmdline =~ s/^\S+\s*//;
$cmdline =~ s/,/,,/g;
$fp.' '.$cmdline;
}
foreach my $entryname (@ARGV)
{
print "Processing entry '$entryname'\n";
my %entry = L4::ModList::get_module_entry($modulesfile, $entryname);
print GRUB1 L4::ModList::generate_grub1_entry($entryname, '', %entry), "\n";
print GRUB2 L4::ModList::generate_grub2_entry($entryname, '', %entry);
my @mods = @{$entry{mods}};
my $kernel = L4::ModList::search_file_or_die($entry{bootstrap}{command}, $module_path);
my $initrd = join(',', map { qemu_get_file($_->{command}, $_->{cmdline}) } @mods);
$kernel =~ s@.*/@@;
print QEMU
" $entryname) $qemu -kernel $kernel -append \"$entry{bootstrap}{cmdline}\" ".
"-initrd \"$initrd\" $qemu_options ;;\n";
$files{$_} = 1 foreach @{$entry{files}};
}
L4::ModList::copy_file_uncompressed_or_die($_, $module_path, $targetdir)
foreach keys %files;
print QEMU " *) echo \"Give entry:\"\n";
print QEMU map { " echo \" $_\"\n" } @ARGV;
print QEMU " exit 1;;\n";
print QEMU "esac\n";
close GRUB1;
close GRUB2;
close QEMU;
chmod 0755, "$targetdir/qemu.sh";