Newer
Older
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
#!/bin/awk -f
{
# lines in input look like ARCH TYPE path/to/TYPE/ARCH/modules/foo.ver
ARCH=$1
ARCHES[ARCH]=1
TYPE=$2
TYPES[TYPE]=1
NTOTAL++
NARCHES[TYPE]++
NTYPES[ARCH]++
FILE=$3
# read files that look like pairs of repeating
# #define __ver_foo hexstring
# #define foo _set_ver(foo)
while ((getline < FILE) > 0) {
if ($0 ~ /^[ ]*$/)
continue
if ($1 != "#define" || $2 !~ /^__ver_/)
exit 1
# this is a "#define __ver_foo somehex" line
SYMBOL=gensub(/^__ver_/,"","",$2)
VALUE=gensub(/^(smp_|2gig_|smp2gig_)/,"","",$3)
VALUE=gensub(/^(smp|2gig|smp2gig)/,"","",VALUE)
values[SYMBOL,ARCH,TYPE]=VALUE
# skip the "#define foo _set_ver(foo)" line
if ((getline < FILE) <= 0)
exit 2
if ($1 != "#define" || $2 != SYMBOL || $3 != "_set_ver(" SYMBOL ")")
exit 3
}
close(FILE)
}
END {
count=0
for (key in values)
if (values[key]) {
count++
split(key,x,SUBSEP)
SYMBOL=x[1]
ARCH=x[2]
TYPE=x[3]
# (re)initialize a few arrays to have no elements
split("",x)
split("",ntype)
split("",total)
totalsum=0
for (arch in ARCHES)
for (type in TYPES)
if (values[SYMBOL,arch,type]) {
VALUE = values[SYMBOL,arch,type]
values[SYMBOL,arch,type] = ""
ntype[VALUE,type] += 1
total[VALUE] += 1
if (x[VALUE])
x[VALUE] = x[VALUE] " "
x[VALUE] = x[VALUE] arch ":" type
}
ifstr="#if "
for (VALUE in x) {
if (total[VALUE] == NTOTAL) {
# there is only one checksum for this symbol
printf "#define __ver_%s\t_ver_str(%s)\n", SYMBOL, VALUE
printf "#define %s _set_ver(%s)\n", SYMBOL, SYMBOL
break
}
totalsum += total[VALUE]
if (totalsum == NTOTAL && ifstr == "#elif") {
# this is the last unique checksum for this symbol
printf "#else\n#define __ver_%s\t_ver_str(%s)\n", SYMBOL, VALUE
printf "#define %s _set_ver(%s)\n", SYMBOL, SYMBOL
break
}
# there must be more than one checksum still to
# print for this symbol
str=""
split(x[VALUE],y)
for (type in TYPES)
if (ntype[VALUE,type] == NARCHES[type]) {
if (str) str = str " || "
str = str "defined(__module__" type ")"
for (k in y) {
split(y[k], z, ":")
if (z[2] == type)
delete y[k]
}
}
for (arch in ARCHES) {
narch=0
for (k in y) {
split(y[k], z, ":")
if (z[1] == arch)
narch++
}
if (narch == NTYPES[arch]) {
if (str) str = str " || "
str = str "defined(__module__" arch ")"
for (k in y) {
split(y[k], z, ":")
if (z[1] == arch)
delete y[k]
}
}
}
for (k in y) {
split(y[k], z, ":")
if (str) str = str " || "
str = str "defined(__module__" z[1] "_" z[2] ")"
}
printf "%s %s\n#define __ver_%s\t_ver_str(%s)\n", ifstr, str, SYMBOL, VALUE
printf "#define %s _set_ver(%s)\n", SYMBOL, SYMBOL
ifstr="#elif "
}
if (ifstr == "#elif ")
printf "#endif\n"
}
if (!count)
printf "\n"
}