summaryrefslogtreecommitdiff
path: root/v4l/scripts/make_kconfig.pl
blob: 91c37693f85836ec63b23a6a563b118233f748ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl
use FileHandle;

my $ARCH=shift;

my %depend = ();
my %config = ();

sub add_config($)
{
	my $arg=shift;

	if ($arg =~ m/^([A-Z0-9_]+)/) {
		$config{$1} = 1;
	}
}

sub check_deps($)
{
	my $arg=shift;
	$arg=$arg." ";

	while ($arg ne "") {
		if ($arg =~ m/^([A-Z0-9_]+) /) {
			my $val=$1;
			my $prev=$depend{$val};
			$depend { $val } = 1+$prev;
		}
		$arg =~ s/^[^ ]+ //;
	}
}

sub open_kconfig($$) {
	my ($dir,$file)=@_;
	my $in = new FileHandle;

#print "opening $file\n";
	open $in,"$file";
	while (<$in>) {
#		if (m;^\s*source[\s\"]+drivers/media/(video|dvb)/Kconfig;) {
#			next;
#		}
		if (m|^\s*source[\s\"]+([^\n\s\"]+)[\n\s\"]|) {
			open_kconfig($dir,"$dir/$1");
			next;
		}
		if (m|^\s+depends on (.*)\n|) {
			check_deps ($1);
		}
		if (m|^\s+select (.*)\n|) {
			check_deps ($1);
		}
		if (m|^\s*config (.*)\n|) {
			add_config ($1);
		}

		s/^main(menu\s\"[^\"]+)/\1 - DON'T CHANGE IT!/;
		print OUT $_;
	}
	close $in;
}

open OUT,">Kconfig";
print OUT "mainmenu \"V4L/DVB menu\"\n";

print OUT "source Kconfig.kern\n";
open_kconfig ("../linux","../linux/drivers/media/Kconfig");

close OUT;

while ( my ($key, $value) = each(%config) ) {
		delete $depend{$key};
}

open OUT,">Kconfig.kern";
while ( my ($key, $value) = each(%depend) ) {
	print OUT "# $key with $value refs\nconfig $key\n\ttristate\n\tdefault m\n\n";
}
close OUT;