summaryrefslogtreecommitdiff
path: root/scripts/deps.pl
blob: 21f816b0d4d41014e506b840ca58d23833ea868c (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
#!/usr/bin/perl -w

use strict;

my %depends;
my %tokenpath;

sub getdepends ($$)
{
	my ($token, $path, $intoken);
	$token = shift || return;
	$token =~ s/CONFIG_//;
	$path = shift || return;
#print "opening $path/config.in\n";
#	print "token is $token\n";
	open( FILE, "< $path/config.in" ) || return;
	$intoken = 0;
	while( <FILE> ) {
		if( $intoken == 1 ) {
			/depends\S*(.*)/ && return $1;
			if( /^\s*(config|menu)/ ) {
				$intoken = 0;
				return;
			}
		} else {
			/$token/ || next;
			$intoken = 1;
		}
		/$token/ || next;
	}
	close( FILE );
	return;
}

sub makedepends ($$)
{
	my ($depends, $tokenpath, $token, $depword, $mustbesep, $state);
	$depends = shift || return;
	$tokenpath = shift || return;
	$mustbesep = 0;

	for $token (keys %$depends){
		print ${$tokenpath}{$token} . " : ";
		for (split(/\s+/, ${$depends}{$token})){
			/^\s+$/ && next;
			/\&\&/ && next;
			/\|\|/ && next;
			/^$/ && next;
			/^\($/ && next;
			/^\)$/ && next;
			/^on$/ && next;
			/^!$/ && next;
			if(defined(${$tokenpath}{"CONFIG_" . $_})){
				print '$(if $(CONFIG_' . $_ . '),' . ${$tokenpath}{"CONFIG_" . $_} . ') ';
			} else {
#				print STDERR "Warning: unable to locate path for token CONFIG_$_\n";
			}
		}
		print "\n";
	}
}

while( <> ) {
	my $dep;
	my ($token, $path, $pro);
	chomp;
	s/^\s*//g;
	s/\s*$//g;
	($token, $path, $pro) = split(/\s+/,$_);
	$tokenpath{$token} = $path;
	$dep = getdepends($token, $path);
	if( $dep ) {
		$depends{$token} = $dep;
	}
}

makedepends(\%depends, \%tokenpath);