]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/tool/gen_kconfig
update
[l4.git] / kernel / fiasco / tool / gen_kconfig
1 #! /usr/bin/perl -W
2
3 use strict;
4
5 my $kconfig_src_file = shift;
6 my $kconfig_obj_file = shift;
7
8 my %pfs;
9 foreach my $f (@ARGV) {
10   my $bsp_name;
11   $bsp_name = $1 if $f =~ /\/bsp\/([^\/]+)\//;
12   open(X, $f) || die "Cannot open $f: $!";
13   my $pf;
14   my $pfdescr;
15   my @pfselect;
16   my @pfdep;
17   while ($_=<X>) {
18     $pf       = $1 if /^\s*\#\s*PF:\s*(\S+)/;
19     $pfdescr  = $1 if /^\s*\#\s*PFDESCR:\s*(.+)/;
20     push(@pfselect, split(/\s+/, $1)) if /^\s*\#\s*PFSELECT:\s*(.+)/;
21     push(@pfdep,    split(/\s+/, $1)) if /^\s*\#\s*PFDEPENDS:\s*(.+)/;
22
23     if (/^\s*\#\s*PFCAN:\s*(.+)/)
24       {
25         push(@pfselect, split(/\s+/, $1));
26         print "WARN: $f:$.: PFCAN is deprecated, use PFSELECT\n";
27       }
28   }
29   $pfs{$pf}{file}      = $f;
30   $pfs{$pf}{desc}      = $pfdescr;
31   @{$pfs{$pf}{select}} = @pfselect;
32   @{$pfs{$pf}{dep}}    = @pfdep;
33   $pfs{$pf}{name}      = $bsp_name;
34   close X;
35 }
36 open(IN, "$kconfig_src_file") || die "Cannot open $kconfig_src_file: $!";
37 open(OUT, ">$kconfig_obj_file") || die "Cannot open $kconfig_obj_file: $!";
38 while ($_=<IN>) {
39   print OUT;
40   if (/^\s*\#\s*PF_INCLUDE\W/) {
41     foreach my $i (keys %pfs) {
42       print OUT "if PF_$i\n";
43       if (defined $pfs{$i}{name}) {
44         print OUT "config BSP_NAME\n    string\n";
45         print OUT "     depends on PF_$i\n";
46         print OUT "     default \"$pfs{$i}{name}\"\n";
47       }
48       print OUT "source \"$pfs{$i}{file}\"\nendif\n";
49     }
50   }
51   if (/^\s*\#\s*PF_CHOICE\W/) {
52     foreach my $i (keys %pfs) {
53       if (defined $pfs{$i}{desc}) {
54         print OUT "config PF_$i\n       bool \"$pfs{$i}{desc}\"\n";
55       } else {
56         print OUT "config PF_$i\n       bool \"$i Platform\"\n";
57       }
58       print OUT "       depends on $_\n" foreach (@{$pfs{$i}{dep}});
59       print OUT "       select $_\n" foreach (@{$pfs{$i}{select}});
60       print OUT "\n";
61     }
62   }
63 }
64 close IN;
65 close OUT;