kernel_config_diff.pl 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 16 March 2013
  5. # https://github.com/trizen
  6. # List activated options from config_2, which are
  7. # not activated in config_1, or have different values.
  8. # Will print them in CSV format.
  9. use 5.010;
  10. use strict;
  11. use autodie;
  12. use warnings;
  13. use Text::CSV qw();
  14. $#ARGV == 1 or die <<"USAGE";
  15. usage: $0 [config_1] [config_2]
  16. USAGE
  17. my ($config_1, $config_2) = @ARGV;
  18. sub parse_option {
  19. my ($line) = @_;
  20. if ($line =~ /^(CONFIG_\w+)=(.*)$/) {
  21. return $1, $2;
  22. }
  23. elsif ($line =~ /^# (CONFIG_\w+) is not set$/) {
  24. return $1, undef;
  25. }
  26. elsif ($line =~ /^\W*CONFIG_\w/) {
  27. die "ERROR: Can't parse line: $line\n";
  28. }
  29. return;
  30. }
  31. my %table;
  32. {
  33. open my $fh, '<', $config_1;
  34. while (<$fh>) {
  35. my ($name, $value) = parse_option($_);
  36. $name // next;
  37. $table{$name} = $value;
  38. }
  39. }
  40. {
  41. my $csv = Text::CSV->new({binary => 1, eol => "\n"})
  42. or die "Cannot use CSV: " . Text::CSV->error_diag();
  43. $csv->print(\*STDOUT, ["OPTION NAME", $config_1, $config_2]);
  44. open my $fh, '<', $config_2;
  45. while (<$fh>) {
  46. my ($name, $value) = parse_option($_);
  47. $name // next;
  48. if (defined $value) {
  49. if (not defined $table{$name}) {
  50. $csv->print(\*STDOUT, [$name, (exists $table{$name} ? "is not set" : "-"), $value]);
  51. }
  52. else {
  53. if ($table{$name} ne $value) {
  54. $csv->print(\*STDOUT, [$name, $table{$name}, $value]);
  55. }
  56. }
  57. }
  58. }
  59. }