mkcapflags.pl 966 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/perl -w
  2. #
  3. # Generate the x86_cap_flags[] array from include/asm-x86/cpufeature.h
  4. #
  5. ($in, $out) = @ARGV;
  6. open(IN, "< $in\0") or die "$0: cannot open: $in: $!\n";
  7. open(OUT, "> $out\0") or die "$0: cannot create: $out: $!\n";
  8. print OUT "#ifndef _ASM_X86_CPUFEATURE_H\n";
  9. print OUT "#include <asm/cpufeature.h>\n";
  10. print OUT "#endif\n";
  11. print OUT "\n";
  12. print OUT "const char * const x86_cap_flags[NCAPINTS*32] = {\n";
  13. %features = ();
  14. $err = 0;
  15. while (defined($line = <IN>)) {
  16. if ($line =~ /^\s*\#\s*define\s+(X86_FEATURE_(\S+))\s+(.*)$/) {
  17. $macro = $1;
  18. $feature = "\L$2";
  19. $tail = $3;
  20. if ($tail =~ /\/\*\s*\"([^"]*)\".*\*\//) {
  21. $feature = "\L$1";
  22. }
  23. next if ($feature eq '');
  24. if ($features{$feature}++) {
  25. print STDERR "$in: duplicate feature name: $feature\n";
  26. $err++;
  27. }
  28. printf OUT "\t%-32s = \"%s\",\n", "[$macro]", $feature;
  29. }
  30. }
  31. print OUT "};\n";
  32. close(IN);
  33. close(OUT);
  34. if ($err) {
  35. unlink($out);
  36. exit(1);
  37. }
  38. exit(0);