Blame SOURCES/merge.pl

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