Blob Blame History Raw
#! /usr/bin/perl -w

#############################################################################
# Copyright (c) 2007 Novell, Inc.
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com
#############################################################################

if (@ARGV < 2) {
    print STDERR "Usage: $0 <config1> <config2> [<config3>]\n";
    print STDERR "Diff kernel config files config1 and config2, or " .
		 "apply those differences to config3\n";
    exit 1;
}

open CONFIG1, $ARGV[0]
    or die $ARGV[0] . ": $!\n";
while (<CONFIG1>) {
    next unless /^(CONFIG_\w+)/a || /^# (CONFIG_\w+) is not set/a;
    $config1{$1} = $_;
}

open CONFIG2, $ARGV[1]
    or die $ARGV[1] . ": $!\n";
while (<CONFIG2>) {
    next unless /^(CONFIG_\w+)/a || /^# (CONFIG_\w+) is not set/a;
    $config2{$1} = $_;
}

while (($key, $value) = each %config2) {
    if (!exists $config1{$key} || $config1{$key} ne $value) {
	$diff{$key} = $value;
    }
}

if (@ARGV >= 3) {
    open OLD, $ARGV[2]
	or die $ARGV[2] . ": $!\n";
    while (<OLD>) {
	if (/^(CONFIG_\w+)/a || /^# (CONFIG_\w+) is not set/a) {
	    if (exists $diff{$1}) {
		print $diff{$1};
		$diff_used{$1} = 1;
		next;
   	    }
	}
	print;
    }
}

foreach my $key (sort(keys(%diff))) {
    next if exists $diff_used{$key};
    print $diff{$key};
}