forked from i1i1/lampos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makedeps.awk
executable file
·102 lines (72 loc) · 1.32 KB
/
makedeps.awk
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
#!/usr/bin/awk -f
function setdeps(arr, was, inc, idx, fs, l, r, i, j, tmp, flag) {
if (!fs)
return idx
if (was[arr[fs]])
return idx
was[fs] = 1
l = idx
while (getline <fs > 0) {
if ($0 !~ /^[ \t]*#[ \t]*include[ \t]+\"/)
continue
split($0, tmp, "\"")
s = tmp[2]
if (inc)
arr[idx] = inc "/"
arr[idx] = arr[idx] s
if (was[arr[idx]])
continue
idx++
}
r = idx
for (i = l; i < r; i++) {
flag = 0
for (j in was) {
if (j == arr[i]) {
flag = 1
break
}
}
if (flag)
continue
idx = setdeps(arr, was, inc, idx, arr[i])
}
return idx
}
function getdeps(s, inc, arr, was, idx) {
idx = 1
idx = setdeps(arr, was, inc, idx, s)
return idx - 1
}
function join(arr, len, sep) {
if (len != 0)
s = arr[1]
for (i = 2; i <= len; i++)
s = s sep arr[i]
return s
}
{
if (!out)
out = "/dev/stdout"
else
printf("") > out
for (i in ARGV) {
if (ARGV[i] ~ /\.h$/) {
src = ARGV[i]
len = getdeps(src, inc, arr)
hdrs = join(arr, len, " ")
printf("%s: %s\n", src, hdrs) >> out
} else if (ARGV[i] ~ /\.c$/) {
src = ARGV[i]
obj = src
gsub(/[^/]+\//, "", obj)
sub(/\.c/, ".o", obj)
len = getdeps(src, inc, arr)
hdrs = join(arr, len, " ")
if (build)
printf("%s/", build) >> out
printf("%s: %s %s\n", obj, src, hdrs) >> out
}
}
exit
}