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