9423bd
#! /usr/bin/perl
9423bd
9423bd
my @args=@ARGV;
9423bd
my %configvalues;
9423bd
my @configoptions;
9423bd
my $configcounter = 0;
9423bd
9423bd
# optionally print out the architecture as the first line of our output
9423bd
my $arch = $args[2];
9423bd
if (defined $arch) {
9423bd
	print "# $arch\n";
9423bd
}
9423bd
9423bd
# first, read the override file
9423bd
9423bd
open (FILE,"$args[0]") || die "Could not open $args[0]";
9423bd
while (<FILE>) {
9423bd
	my $str = $_;
9423bd
	my $configname;
9423bd
9423bd
	if (/\# ([\w]+) is not set/) {
9423bd
		$configname = $1;
9423bd
	} elsif (/^\#/) {
9423bd
		# fall through on comments like 'avoid CONFIG_FOO=y'
9423bd
		;
9423bd
	} elsif (/([\w]+)=/) {
9423bd
		$configname = $1;
9423bd
	}
9423bd
9423bd
	if (defined($configname) && !exists($configvalues{$configname})) {
9423bd
		$configvalues{$configname} = $str;
9423bd
		$configoptions[$configcounter] = $configname;
9423bd
		$configcounter ++;
9423bd
	}
9423bd
};
9423bd
9423bd
# now, read and output the entire configfile, except for the overridden
9423bd
# parts... for those the new value is printed.
9423bd
9423bd
open (FILE2,"$args[1]") || die "Could not open $args[1]";
9423bd
while (<FILE2>) {
9423bd
	my $configname;
9423bd
9423bd
	if (/\# ([\w]+) is not set/) {
9423bd
		$configname = $1;
9423bd
	} elsif (/^\#/) {
9423bd
		# fall through on comments like 'avoid CONFIG_FOO=y'
9423bd
		;
9423bd
	} elsif (/([\w]+)=/) {
9423bd
		$configname  = $1;
9423bd
	}
9423bd
9423bd
	if (defined($configname) && exists($configvalues{$configname})) {
9423bd
		print "$configvalues{$configname}";
9423bd
		delete($configvalues{$configname});
9423bd
	} else {
9423bd
		print "$_";
9423bd
	}
9423bd
}
9423bd
9423bd
# now print the new values from the overridden configfile
9423bd
my $counter = 0;
9423bd
9423bd
while ($counter < $configcounter) {
9423bd
	my $configname = $configoptions[$counter];
9423bd
	if (exists($configvalues{$configname})) {
9423bd
		print "$configvalues{$configname}";
9423bd
	}
9423bd
	$counter++;
9423bd
}
9423bd
9423bd
1;