]> rtime.felk.cvut.cz Git - l4.git/blobdiff - kernel/fiasco/tool/gen_kconfig
Update
[l4.git] / kernel / fiasco / tool / gen_kconfig
index 92ed609cf4c95a654b7f838704ce6850a1b87e1f..14f46df895a085a88cb9b1bc6583bc68cf0d8ab7 100755 (executable)
@@ -6,50 +6,125 @@ my $kconfig_src_file = shift;
 my $kconfig_obj_file = shift;
 
 my %pfs;
+my %archs;
+my %files;
+
+my $tag = qr {^\s*\#\s*};
+
 foreach my $f (@ARGV) {
   my $bsp_name;
   $bsp_name = $1 if $f =~ /\/bsp\/([^\/]+)\//;
   open(X, $f) || die "Cannot open $f: $!";
   my $pf;
-  my $pfdescr;
-  my @pfselect;
-  my @pfdep;
+  my $arch;
+  my $arch_cpu;
   while ($_=<X>) {
-    $pf       = $1 if /^\s*\#\s*PF:\s*(\S+)/;
-    $pfdescr  = $1 if /^\s*\#\s*PFDESCR:\s*(.+)/;
-    push(@pfselect, split(/\s+/, $1)) if /^\s*\#\s*PFSELECT:\s*(.+)/;
-    push(@pfdep,    split(/\s+/, $1)) if /^\s*\#\s*PFDEPENDS:\s*(.+)/;
+    if (/$tag PF:\s*(\S+)/x) {
+      $pf = { name => $bsp_name, file => $f };
+      push (@{$files{$f}}, "PF_$1");
+      $pfs{$1} = $pf;
+    }
+    if  (defined $pf) {
+      $pf->{desc}  = $1                        if /$tag PFDESCR:\s*(.+)/x;
+      push(@{$pf->{select}}, split(/\s+/, $1)) if /$tag PFSELECT:\s*(.+)/x;
+      push(@{$pf->{dep}},    split(/\s+/, $1)) if /$tag PFDEPENDS:\s*(.+)/x;
+    }
 
-    if (/^\s*\#\s*PFCAN:\s*(.+)/)
-      {
-        push(@pfselect, split(/\s+/, $1));
-        print "WARN: $f:$.: PFCAN is deprecated, use PFSELECT\n";
+    if (/^$tag ARCH:\s*(\S+)\s+(\S+)/x) {
+      $arch_cpu = undef;
+      $arch = { name => $2, file => $f };
+      $archs{$1} = $arch;
+      push (@{$files{$f}}, $1);
+    }
+    if (defined $arch) {
+      $arch->{desc} = $1            if /$tag ARCHDESCR:\s*(.+)/x;
+      $arch->{default_cpu} = $1     if /$tag ARCHDEFAULTCPU:\s*(.+)/x;
+      $arch->{default_pf} = $1      if /$tag ARCHDEFAULTPF:\s*(.+)/x;
+      push (@{$arch->{select}}, $1) if /$tag ARCHSELECT:\s*(.+)/x;
+      push (@{$arch->{dep}}, $1)    if /$tag ARCHDEPENDS:\s*(.+)/x;
+      push (@{$arch->{help}}, $1)   if /$tag ARCHHELP:\s*(.+)/x;
+      if (/$tag ARCHCPU:\s*(\S+)\s+(.+)/x) {
+        $arch_cpu = { name => $1, desc => $2 };
+        push (@{$arch->{cpus}}, $arch_cpu);
       }
+    }
+    if (defined $arch_cpu) {
+      push (@{$arch_cpu->{dep}}, $1)    if /$tag ARCHCPUDEPENDS:\s*(.+)/x;
+      push (@{$arch_cpu->{select}}, $1) if /$tag ARCHCPUSELECT:\s*(.+)/x;
+      push (@{$arch_cpu->{help}}, $1)   if /$tag ARCHCPUHELP:\s*(.+)/x;
+    }
   }
-  $pfs{$pf}{file}      = $f;
-  $pfs{$pf}{desc}      = $pfdescr;
-  @{$pfs{$pf}{select}} = @pfselect;
-  @{$pfs{$pf}{dep}}    = @pfdep;
-  $pfs{$pf}{name}      = $bsp_name;
+
   close X;
 }
 open(IN, "$kconfig_src_file") || die "Cannot open $kconfig_src_file: $!";
 open(OUT, ">$kconfig_obj_file") || die "Cannot open $kconfig_obj_file: $!";
 while ($_=<IN>) {
   print OUT;
-  if (/^\s*\#\s*PF_INCLUDE\W/) {
-    foreach my $i (keys %pfs) {
-      print OUT "if PF_$i\n";
+  if (/$tag ARCH_DEFAULT_CPU\W/x) {
+    foreach my $i (sort keys %archs) {
+      print OUT "\tdefault $archs{$i}{default_cpu}  if $i\n"
+        if defined $archs{$i}{default_cpu};
+    }
+  }
+  if (/$tag ARCH_DEFAULT_PF\W/x) {
+    foreach my $i (sort keys %archs) {
+      print OUT "\tdefault $archs{$i}{default_pf}  if $i\n"
+        if defined $archs{$i}{default_pf};
+    }
+  }
+  if (/$tag ARCH_NAME\W/x) {
+    foreach my $i (sort keys %archs) {
+      print OUT "\tdefault \"$archs{$i}{name}\"  if $i\n"
+        if defined $archs{$i}{name};
+    }
+  }
+  if (/$tag ARCH_CHOICE\W/x) {
+    foreach my $i (sort keys %archs) {
+      next unless defined $archs{$i}{desc};
+      print OUT "config $i\n";
+      print OUT "\tbool \"$archs{$i}{desc}\"\n";
+      print OUT "\tdepends on $_\n" foreach (@{$archs{$i}{dep}});
+      print OUT "\tselect $_\n" foreach (@{$archs{$i}{select}});
+      if (defined $archs{$i}{help}) {
+        print OUT "\thelp\n";
+        print OUT "\t\t$_\n" foreach (@{$archs{$i}{help}});
+      }
+      print OUT "\n";
+    }
+  }
+  if (/$tag ARCH_CPU\W/x) {
+    foreach my $i (sort keys %archs) {
+      foreach my $c (@{$archs{$i}{cpus}}) {
+        print OUT "config $c->{name}\n";
+        print OUT "\tbool \"$c->{desc}\"\n";
+        print OUT "\tdepends on $i\n";
+        print OUT "\tdepends on $_\n" foreach (@{$c->{dep}});
+        print OUT "\tselect $_\n" foreach (@{$c->{select}});
+        next unless $c->{help};
+        print OUT "\thelp\n";
+        print OUT "\t\t$_\n" foreach (@{$c->{help}});
+        print OUT "\n";
+      }
+    }
+  }
+
+  if (/$tag PF_INCLUDE\W/x) {
+    foreach my $i (sort keys %files) {
+      print OUT "if " . join(" || ", @{$files{$i}})."\n";
+      print OUT "\tsource \"$i\"\n";
+      print OUT "endif\n";
+    }
+    print OUT "config BSP_NAME\n";
+    print OUT "\tstring\n";
+    foreach my $i (sort keys %pfs) {
       if (defined $pfs{$i}{name}) {
-       print OUT "config BSP_NAME\n    string\n";
-       print OUT "     depends on PF_$i\n";
-       print OUT "     default \"$pfs{$i}{name}\"\n";
+       print OUT "     default \"$pfs{$i}{name}\" if PF_$i\n";
       }
-      print OUT "source \"$pfs{$i}{file}\"\nendif\n";
     }
   }
-  if (/^\s*\#\s*PF_CHOICE\W/) {
-    foreach my $i (keys %pfs) {
+  if (/$tag PF_CHOICE\W/x) {
+    foreach my $i (sort keys %pfs) {
       if (defined $pfs{$i}{desc}) {
        print OUT "config PF_$i\n       bool \"$pfs{$i}{desc}\"\n";
       } else {