dump-target-info.pl 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use Cwd;
  5. my (%targets, %architectures);
  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_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 =~ /^Target-Features: (.+)$/) {
  20. @target_features = split /\s+/, $1;
  21. }
  22. elsif ($line =~ /^@\@$/) {
  23. if ($target_name && $target_arch &&
  24. !grep { $_ eq 'broken' or $_ eq 'source-only' } @target_features) {
  25. $targets{$target_name} = $target_arch;
  26. $architectures{$target_arch} ||= [];
  27. push @{$architectures{$target_arch}}, $target_name;
  28. }
  29. undef $target_name;
  30. undef $target_arch;
  31. @target_features = ();
  32. }
  33. }
  34. close M;
  35. }
  36. }
  37. sub get_targetinfo {
  38. foreach my $target_makefile (glob "target/linux/*/Makefile") {
  39. my ($target_dir) = $target_makefile =~ m!^(.+)/Makefile$!;
  40. my @subtargets;
  41. if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 val.FEATURES V=s 2>/dev/null |") {
  42. if (defined(my $line = readline M)) {
  43. chomp $line;
  44. if (grep { $_ eq 'broken' or $_ eq 'source-only' } split /\s+/, $line) {
  45. next;
  46. }
  47. }
  48. }
  49. if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 val.SUBTARGETS V=s 2>/dev/null |") {
  50. if (defined(my $line = readline M)) {
  51. chomp $line;
  52. @subtargets = split /\s+/, $line;
  53. }
  54. close M;
  55. }
  56. push @subtargets, 'generic' if @subtargets == 0;
  57. foreach my $subtarget (@subtargets) {
  58. parse_targetinfo($target_dir, $subtarget);
  59. }
  60. }
  61. }
  62. if (@ARGV == 1 && $ARGV[0] eq 'targets') {
  63. get_targetinfo();
  64. foreach my $target_name (sort keys %targets) {
  65. printf "%s %s\n", $target_name, $targets{$target_name};
  66. }
  67. }
  68. elsif (@ARGV == 1 && $ARGV[0] eq 'architectures') {
  69. get_targetinfo();
  70. foreach my $target_arch (sort keys %architectures) {
  71. printf "%s %s\n", $target_arch, join ' ', @{$architectures{$target_arch}};
  72. }
  73. }
  74. else {
  75. print "Usage: $0 targets\n";
  76. print "Usage: $0 architectures\n";
  77. }