11 ARCHTYPES[ARCH ":" TYPE] = 1
13 if (NARCHES[TYPE] == 1)
16 if (NTYPES[ARCH] == 1)
20 while ((getline < FILE) > 0) {
21 if ($0 ~ /^\/\*/ || $0 ~ /^ \*\// || $0 ~ /^[ ]*$/)
24 SECTION = gensub(/^ \* /,"",$0)
25 if (!(SECTION in sectno)) {
26 sectno[SECTION] = nsects
29 } else if (cursects && cursects != nsects) {
31 diff = nsects - cursects
33 if (sectno[s] >= cursects)
34 sectno[s] = sectno[s] - cursects + no
35 else if (sectno[s] >= no)
40 cursym[SECTION] = counts[SECTION]
43 if ($1 != "#define" && $1 != "#undef")
46 n = index($0,SYMBOL)+length(SYMBOL)
47 if ($1 == "#define") {
48 n = index($0,SYMBOL)+length(SYMBOL)
49 VALUE = gensub(/^[ ]*/,"","",substr($0,n))
50 if (VALUE == "") VALUE = "__novalue__"
52 VALUE = "__undefined__"
54 if (present[SYMBOL,ARCH,TYPE]) continue
55 present[SYMBOL,ARCH,TYPE] = 1
56 values[SYMBOL] = values[SYMBOL] SUBSEP ARCH ":" TYPE ":" VALUE
57 if (SECTION == sections[SYMBOL] && cursym[SECTION] && cursym[SECTION] != counts[SECTION]) {
59 diff = counts[SECTION]-cursym[SECTION]
61 if (sections[s] == SECTION) {
62 if (pos[s] >= cursym[SECTION])
63 pos[s] = pos[s] - cursym[SECTION] + no
64 else if (pos[s] >= no)
67 cursym[SECTION] = counts[SECTION]
70 present[SYMBOL,ARCH,TYPE] = 1
71 values[SYMBOL] = ARCH ":" TYPE ":" VALUE
72 sections[SYMBOL] = SECTION
73 pos[SYMBOL] = counts[SECTION]
80 for (SECTION in sectno)
81 x[sectno[SECTION]] = SECTION
82 for (i = 0; i < nsects; i++) {
86 printf "/*\n * %s\n */\n", SECTION
89 for (SYMBOL in sections)
90 if (sections[SYMBOL] == SECTION)
91 y[pos[SYMBOL]] = SYMBOL
92 for (j = 0; j < counts[SECTION]; j++) {
96 split(values[SYMBOL],z,SUBSEP)
103 VALUE = substr(z[k],length(ARCH)+length(TYPE)+3)
105 val[VALUE] = val[VALUE] " "
106 val[VALUE] = val[VALUE] ARCH ":" TYPE
107 ntype[VALUE,TYPE] += 1
114 if (total[VALUE] == NTOTAL) {
115 if (VALUE == "__undefined__")
116 curlines["1"] = "#undef " SYMBOL "\n"
117 else if (VALUE == "__novalue__")
118 curlines["1"] = "#define " SYMBOL "\n"
120 curlines["1"] = "#define " SYMBOL " " VALUE "\n"
127 for (m = 0; m < 4; m++) {
130 if (total[VALUE] > 1 && total[VALUE] == NTOTAL - 1) {
132 for (arch in ARCHES) {
133 for (type in TYPES) {
134 archtype = arch ":" type
135 if (ARCHTYPES [archtype] == 1) {
137 if (yy[n] == archtype)
139 if (yy[n] != archtype) {
148 if (NARCHES[type] > 1 && NTYPES[arch] > 1) {
149 str = "!defined(__module__" arch "_" type ")"
154 if (m == 0 || m == 2) {
158 if (ntype[VALUE,type] == NARCHES[type]) {
159 if (str) str = str " || "
160 str = str "defined(__module__" type ")"
171 if (m < 2 && nfull > 1 && nfull == NTOTALTYPES - 1) {
172 str = "!defined(__module__" NOTYPE ")"
185 for (arch in ARCHES) {
192 if (narch == NTYPES[arch]) {
193 if (str) str = str " || "
194 str = str "defined(__module__" arch ")"
206 if (m < 2 && nfull > 1 && nfull == NTOTALARCHES - 1) {
210 if (str) str = str " || "
211 str = str "!defined(__module__" NOARCH ")"
218 if (m == 1 || m == 3) {
222 for (type in TYPES) {
229 if (ntypex == NARCHES[type]) {
230 if (str) str = str " || "
231 str = str "defined(__module__" type ")"
243 if (m < 2 && nfull > 1 && nfull == NTOTALTYPES - 1) {
247 if (str) str = str " || "
248 str = "!defined(__module__" NOTYPE ")"
258 if (str) str = str " || "
259 str = str "defined(__module__" z[1] "_" z[2] ")"
261 if (m == 0 || length(str) < length(shorteststr))
265 if (VALUE == "__undefined__")
266 curlines[str] = "#undef " SYMBOL "\n"
267 else if (VALUE == "__novalue__")
268 curlines[str] = "#define " SYMBOL "\n"
270 curlines[str] = "#define " SYMBOL " " VALUE "\n"
275 for (str in curlines)
277 lines[str] = lines[str] curlines[str]
280 printf "%s", lines["1"]
284 if (lines[str] && str != lastelse) {
285 printf "%s %s\n%s", ifstr, str, lines[str]
289 printf "#else\n%s", lines[lastelse]
294 for (str in curlines)
296 lines[str] = curlines[str]
297 if (totalsum == NTOTAL && length(str) > length(lastelse)) {
304 printf "%s", lines["1"]
308 if (lines[str] && str != lastelse) {
309 printf "%s %s\n%s", ifstr, str, lines[str]
313 printf "#else\n%s", lines[lastelse]