Jeff Mahoney 32677c
#!/usr/bin/perl -w
Jeff Mahoney 32677c
use strict;
Jeff Mahoney 32677c
Jeff Mahoney 32677c
if (@ARGV < 2) {
Jeff Mahoney 32677c
	print STDERR "Usage: $0 <config1> <config2>\n";
Jeff Mahoney 32677c
	print STDERR "Merge kernel config files config1 and config2. " .
Jeff Mahoney 32677c
		     "Differences will be selected from config2.\n";
Jeff Mahoney 32677c
	exit 1;
Jeff Mahoney 32677c
}
Jeff Mahoney 32677c
Jeff Mahoney 32677c
my %config;
Michal Marek 8529da
my @lines;
Jeff Mahoney 32677c
Jeff Mahoney 32677c
open CONFIG1, $ARGV[0]
Jeff Mahoney 32677c
    or die $ARGV[0] . ": $!\n";
Jeff Mahoney 32677c
while (<CONFIG1>) {
Michal Marek 8529da
    push(@lines, $_);
Jeff Mahoney 32677c
    next unless /^(CONFIG_[A-Za-z0-9_]+)/ || /^# (CONFIG_[A-Za-z0-9_]+) is not set/;
Jeff Mahoney 32677c
    $config{$1} = $_;
Jeff Mahoney 32677c
}
Michal Marek 8529da
close(CONFIG1);
Jeff Mahoney 32677c
Jeff Mahoney 32677c
open CONFIG2, $ARGV[1]
Jeff Mahoney 32677c
    or die $ARGV[1] . ": $!\n";
Jeff Mahoney 32677c
while (<CONFIG2>) {
Jeff Mahoney 32677c
    next unless /^(CONFIG_[A-Za-z0-9_]+)/ || /^# (CONFIG_[A-Za-z0-9_]+) is not set/;
Jeff Mahoney 32677c
    $config{$1} = $_;
Jeff Mahoney 32677c
}
Jeff Mahoney 32677c
close(CONFIG2);
Jeff Mahoney 32677c
Michal Marek 8529da
foreach (@lines) {
Jeff Mahoney 32677c
    if (/^(CONFIG_[A-Za-z0-9_]+)/ || /^# (CONFIG_[A-Za-z0-9_]+) is not set/) {
Michal Marek 851874
	if (exists($config{$1})) {
Michal Marek 851874
	    print $config{$1};
Michal Marek 851874
	    delete $config{$1};
Michal Marek 851874
	}
Jeff Mahoney 32677c
    } else {
Jeff Mahoney 32677c
	print;
Jeff Mahoney 32677c
    }
Jeff Mahoney 32677c
Jeff Mahoney 32677c
}
Jeff Mahoney 32677c
Michal Marek bdd5e8
foreach my $value (sort(values(%config))) {
Jeff Mahoney 32677c
	print $value;
Jeff Mahoney 32677c
}