summaryrefslogtreecommitdiff
path: root/util/src-dep.pl
blob: ad997e4746838fcf3152fa2f5b673c0caf83bdcc (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/local/bin/perl

# we make up an array of
# $file{function_name}=filename;
# $unres{filename}="func1 func2 ...."
$debug=1;
#$nm_func="parse_linux";
$nm_func="parse_solaris";

foreach (@ARGV)
	{
	&$nm_func($_);
	}

foreach $file (sort keys %unres)
	{
	@a=split(/\s+/,$unres{$file});
	%ff=();
	foreach $func (@a)
		{
		$f=$file{$func};
		$ff{$f}=1 if $f ne "";
		}

	foreach $a (keys %ff)
		{ $we_need{$file}.="$a "; }
	}

foreach $file (sort keys %we_need)
	{
#	print "	$file $we_need{$file}\n";
	foreach $bit (split(/\s+/,$we_need{$file}))
		{ push(@final,&walk($bit)); }

	foreach (@final) { $fin{$_}=1; }
	@final="";
	foreach (sort keys %fin)
		{ push(@final,$_); }

	print "$file: @final\n";
	}

sub walk
	{
	local($f)=@_;
	local(@a,%seen,@ret,$r);

	@ret="";
	$f =~ s/^\s+//;
	$f =~ s/\s+$//;
	return "" if ($f =~ "^\s*$");

	return(split(/\s/,$done{$f})) if defined ($done{$f});

	return if $in{$f} > 0;
	$in{$f}++;
	push(@ret,$f);
	foreach $r (split(/\s+/,$we_need{$f}))
		{
		push(@ret,&walk($r));
		}
	$in{$f}--;
	$done{$f}=join(" ",@ret);
	return(@ret);
	}

sub parse_linux
	{
	local($name)=@_;

	open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n";
	while (<IN>)
		{
		chop;
		next if /^\s*$/;
		if (/^[^[](.*):$/)
			{
			$file=$1;
			$file="$1.c" if /\[(.*).o\]/;
			print STDERR "$file\n";
			$we_need{$file}=" ";
			next;
			}

		@a=split(/\s*\|\s*/);
		next unless $#a == 7;
		next unless $a[4] eq "GLOB";
		if ($a[6] eq "UNDEF")
			{
			$unres{$file}.=$a[7]." ";
			}
		else
			{
			if ($file{$a[7]} ne "")
				{
				print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n";
				}
			else
				{
				$file{$a[7]}=$file;
				}
			}
		}
	close(IN);
	}

sub parse_solaris
	{
	local($name)=@_;

	open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n";
	while (<IN>)
		{
		chop;
		next if /^\s*$/;
		if (/^(\S+):$/)
			{
			$file=$1;
			#$file="$1.c" if $file =~ /^(.*).o$/;
			print STDERR "$file\n";
			$we_need{$file}=" ";
			next;
			}
		@a=split(/\s*\|\s*/);
		next unless $#a == 7;
		next unless $a[4] eq "GLOB";
		if ($a[6] eq "UNDEF")
			{
			$unres{$file}.=$a[7]." ";
			print STDERR "$file needs $a[7]\n" if $debug;
			}
		else
			{
			if ($file{$a[7]} ne "")
				{
				print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n";
				}
			else
				{
				$file{$a[7]}=$file;
				print STDERR "$file has $a[7]\n" if $debug;
				}
			}
		}
	close(IN);
	}