+sub target_name($) {
+ my $target = shift;
+ my $parent = $target->{parent};
+ if ($parent) {
+ return $target->{parent}->{name}." - ".$target->{name};
+ } else {
+ return $target->{name};
+ }
+}
+
+sub kver($) {
+ my $v = shift;
+ $v =~ tr/\./_/;
+ $v =~ /(\d+_\d+_\d+)(_\d+)?/ and $v = $1;
+ return $v;
+}
+
+sub print_target($) {
+ my $target = shift;
+ my $features = target_config_features(@{$target->{features}});
+ my $help = $target->{desc};
+ my $kernel = $target->{kernel};
+ my $confstr;
+ $kernel =~ tr/./_/;
+
+ chomp $features;
+ $features .= "\n";
+ if ($help =~ /\w+/) {
+ $help =~ s/^\s*/\t /mg;
+ $help = "\thelp\n$help";
+ } else {
+ undef $help;
+ }
+
+ my $v = kver($target->{version});
+ if (@{$target->{subtargets}} == 0) {
+ $confstr = <<EOF;
+config TARGET_$target->{conf}
+ bool "$target->{name}"
+ select LINUX_$kernel
+ select LINUX_$v
+EOF
+ }
+ else {
+ $confstr = <<EOF;
+config TARGET_$target->{conf}
+ bool "$target->{name}"
+EOF
+ }
+ if ($target->{subtarget}) {
+ $confstr .= "\tdepends TARGET_$target->{boardconf}\n";
+ }
+ if (@{$target->{subtargets}} > 0) {
+ $confstr .= "\tselect HAS_SUBTARGETS\n";
+ }
+
+ if ($target->{arch} =~ /\w/) {
+ $confstr .= "\tselect $target->{arch}\n";
+ }
+ foreach my $dep (@{$target->{depends}}) {
+ my $mode = "depends";
+ my $flags;
+ my $name;
+
+ $dep =~ /^([@\+\-]+)(.+)$/;
+ $flags = $1;
+ $name = $2;
+
+ next if $name =~ /:/;
+ $flags =~ /-/ and $mode = "deselect";
+ $flags =~ /\+/ and $mode = "select";
+ $flags =~ /@/ and $confstr .= "\t$mode $name\n";
+ }
+ $confstr .= $features;
+ $confstr .= "$help\n\n";
+ print $confstr;
+}