dump-target-info.pl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use Cwd;
  5. my (%targets, %architectures, %kernels);
  6. $ENV{'TOPDIR'} = Cwd::getcwd();
  7. sub parse_targetinfo {
  8. my ($target_dir, $subtarget) = @_;
  9. if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 SUBTARGET='$subtarget' |") {
  10. my ($target_name, $target_arch, $target_kernel, $target_testing_kernel, @target_features);
  11. while (defined(my $line = readline M)) {
  12. chomp $line;
  13. if ($line =~ /^Target: (.+)$/) {
  14. $target_name = $1;
  15. }
  16. elsif ($line =~ /^Target-Arch-Packages: (.+)$/) {
  17. $target_arch = $1;
  18. }
  19. elsif ($line =~ /^Linux-Version: (\d\.\d+)\.\d+$/) {
  20. $target_kernel = $1;
  21. }
  22. elsif ($line =~ /^Linux-Testing-Version: (\d\.\d+)\.\d+$/) {
  23. $target_testing_kernel = $1;
  24. }
  25. elsif ($line =~ /^Target-Features: (.+)$/) {
  26. @target_features = split /\s+/, $1;
  27. }
  28. elsif ($line =~ /^@\@$/) {
  29. if ($target_name && $target_arch && $target_kernel &&
  30. !grep { $_ eq 'broken' or $_ eq 'source-only' } @target_features) {
  31. $targets{$target_name} = $target_arch;
  32. $architectures{$target_arch} ||= [];
  33. push @{$architectures{$target_arch}}, $target_name;
  34. $kernels{$target_name} ||= [];
  35. push @{$kernels{$target_name}}, $target_kernel;
  36. if ($target_testing_kernel) {
  37. push @{$kernels{$target_name}}, $target_testing_kernel;
  38. }
  39. }
  40. undef $target_name;
  41. undef $target_arch;
  42. undef $target_kernel;
  43. undef $target_testing_kernel;
  44. @target_features = ();
  45. }
  46. }
  47. close M;
  48. }
  49. }
  50. sub get_targetinfo {
  51. foreach my $target_makefile (glob "target/linux/*/Makefile") {
  52. my ($target_dir) = $target_makefile =~ m!^(.+)/Makefile$!;
  53. my @subtargets;
  54. if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 val.FEATURES V=s 2>/dev/null |") {
  55. if (defined(my $line = readline M)) {
  56. chomp $line;
  57. if (grep { $_ eq 'broken' or $_ eq 'source-only' } split /\s+/, $line) {
  58. next;
  59. }
  60. }
  61. }
  62. if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 val.SUBTARGETS V=s 2>/dev/null |") {
  63. if (defined(my $line = readline M)) {
  64. chomp $line;
  65. @subtargets = split /\s+/, $line;
  66. }
  67. close M;
  68. }
  69. push @subtargets, 'generic' if @subtargets == 0;
  70. foreach my $subtarget (@subtargets) {
  71. parse_targetinfo($target_dir, $subtarget);
  72. }
  73. }
  74. }
  75. if (@ARGV == 1 && $ARGV[0] eq 'targets') {
  76. get_targetinfo();
  77. foreach my $target_name (sort keys %targets) {
  78. printf "%s %s\n", $target_name, $targets{$target_name};
  79. }
  80. }
  81. elsif (@ARGV == 1 && $ARGV[0] eq 'architectures') {
  82. get_targetinfo();
  83. foreach my $target_arch (sort keys %architectures) {
  84. printf "%s %s\n", $target_arch, join ' ', @{$architectures{$target_arch}};
  85. }
  86. }
  87. elsif (@ARGV == 1 && $ARGV[0] eq 'kernels') {
  88. get_targetinfo();
  89. foreach my $target_name (sort keys %targets) {
  90. printf "%s %s\n", $target_name, join ' ', @{$kernels{$target_name}};
  91. }
  92. }
  93. else {
  94. print "Usage: $0 targets\n";
  95. print "Usage: $0 architectures\n";
  96. print "Usage: $0 kernels\n";
  97. }