8985cfb
# By Paul Bolle October 2014.
8985cfb
#
8985cfb
# Contributed to the public domain by its author.
8985cfb
8985cfb
use 5.016;
8985cfb
use warnings;
8985cfb
use autodie;
8985cfb
8985cfb
use File::Find;
8985cfb
8985cfb
my @Kconfigs;
8985cfb
8985cfb
my $Kconfigre = qr/Kconfig.*/;
8985cfb
my $configre = qr/^\s*(menu)?config\s+(?<config>(\w+))$/;
8985cfb
my $CONFIG_re = qr/\bCONFIG_(?<CONFIG_>(\w+))/;
8985cfb
8985cfb
sub match {
8985cfb
	push( @Kconfigs, $File::Find::name ) if ($_ =~ $Kconfigre);
8985cfb
}
8985cfb
8985cfb
sub parse_kconfig {
8985cfb
	my ($path) = @_;
8985cfb
8985cfb
	my @ret;
8985cfb
8985cfb
	open( my $kconfig, "<", $path );
8985cfb
	my $slurp = do { local $/ = undef; <$kconfig> };
8985cfb
	close( $kconfig );
8985cfb
	my @lines = split ( /\n/, $slurp );
8985cfb
	foreach my $line (@lines) {
8985cfb
		if ($line =~ /$configre/) {
8985cfb
			push( @ret, $+{config} );
8985cfb
		}
8985cfb
	}
8985cfb
8985cfb
	@ret;
8985cfb
}
8985cfb
8985cfb
sub parse_shipped {
8985cfb
	my ($path) = @_;
8985cfb
8985cfb
	my @ret;
8985cfb
8985cfb
	open( my $shipped, "<", $path );
8985cfb
	my $slurp = do { local $/ = undef; <$shipped> };
8985cfb
	close( $shipped );
8985cfb
	my @lines = split ( /\n/, $slurp );
8985cfb
	my $i = 1;
8985cfb
	foreach my $line (@lines) {
8985cfb
		if ($line =~ /$CONFIG_re/) {
8985cfb
			push( @ret, [$i, $+{CONFIG_}] );
8985cfb
		}
8985cfb
		$i++;
8985cfb
	}
8985cfb
8985cfb
	@ret;
8985cfb
}
8985cfb
8985cfb
exit main ( @ARGV );
8985cfb
8985cfb
sub main {
8985cfb
	my %configs;
8985cfb
8985cfb
	find( \&match, @_ );
8985cfb
8985cfb
	foreach my $Kconfig (@Kconfigs) {
8985cfb
		my (@tmp) = parse_kconfig( $Kconfig );
8985cfb
		foreach my $config ( @tmp ) {
8985cfb
			$configs{ $config }++;
8985cfb
		}
8985cfb
	}
8985cfb
8985cfb
	foreach my $shipped (glob("config-*")) {
8985cfb
		my (@tmp) = parse_shipped( $shipped );
8985cfb
		foreach my $ref ( @tmp ) {
8985cfb
			say( STDERR "$shipped:$ref->[0]: No Kconfig symbol matches 'CONFIG_$ref->[1]'" )
8985cfb
				unless (grep( /$ref->[1]/, keys( %configs )));
8985cfb
		}
8985cfb
	}
8985cfb
8985cfb
	0;
8985cfb
}
8985cfb