update abi_* scripts
[musl-tables] / makedecls.sh
1 #!/bin/sh
2
3 set -xeu
4
5 export LC_ALL=C
6
7 # musl repo dir
8 MUSL="${MUSL:-../musl}"
9
10 ALL='
11 aarch64
12 arm
13 i386
14 microblaze
15 mips
16 mips64
17 or1k
18 powerpc
19 powerpc64
20 sh
21 x32
22 x86_64
23 '
24
25 ARCH="${ARCH:-$ALL}"
26
27 # install headers to T.$arch
28 for arch in $ARCH
29 do
30 [ -e T.$arch ] && continue
31 make -f "$MUSL"/Makefile install-headers srcdir="$MUSL" prefix=T.$arch ARCH=$arch
32 rm -rf obj/include/bits
33 done
34 rm -rf obj lib
35
36 # run ctags on headers
37 for arch in $ARCH
38 do
39 [ -e T.$arch/musl.tags ] && continue
40 cd T.$arch/include
41 ctags -f ../musl.tags -R -n -u --language-force=c --c-kinds=pxdstuve --fields=k .
42 # fix wchar_t bug of ctags (not ok for c++)
43 awk '/typedef.* wchar_t/{print "wchar_t\tbits/alltypes.h\t" NR ";\"\tt"}' bits/alltypes.h >>../musl.tags
44 cd ../..
45 done
46
47 # add declarations (slow)
48 for arch in $ARCH
49 do
50 [ -e T.$arch/musl.decls ] && continue
51 cd T.$arch/include
52 awk '
53 BEGIN { FS="\t" }
54
55 function decl(t,h,n) {
56         cmd = "awk '\''NR==" n
57         if (t ~ /[pxt]/)
58                 cmd = cmd "{s=$0; if(s!~/;/){getline; s=s \" \" $0} print s; exit}"
59         else if (t == "d")
60                 cmd = cmd "{s=$0; while(gsub(/\\\\$/,\"\",s)){getline; s=s $0} print s; exit}"
61         else
62                 return ""
63         cmd = cmd "'\'' " h
64         cmd | getline s
65         close(cmd)
66         gsub(/\t/, " ", s)
67         gsub(/ +/, " ", s)
68         if (t == "p")
69                 gsub(/ \(/, "(", s)
70         return s
71 }
72 /^[^!]/ {
73         gsub(/[^0-9]*/,"",$3)
74         if ($4 == "s")
75                 $1 = "struct " $1
76         if ($4 == "u")
77                 $1 = "union " $1
78         print $1 "\t" $2 "\t" $4 "\t" $3 "\t" decl($4,$2,$3)
79 }' ../musl.tags >../musl.decls.raw
80
81 # fix ups
82 awk '
83 BEGIN { FS="\t" }
84 $3=="d" && $5 ~ /^#undef/ {next}
85 $3=="x" && $5 ~ /^(struct|union) [_0-9a-zA-Z]*;$/ {
86         a = ($5 ~ /^struct/) ? "struct " : "union "
87         b = ($5 ~ /^struct/) ? "S" : "U"
88         print a $1 "\t" $2 "\t" b "\t" $4 "\t" $5
89         next
90 }
91 $1~/^(FILE|DIR)$/ {
92         print $1 "\t" $2 "\tT\t" $4 "\t" $5
93         next
94 }
95 { print $0 }' ../musl.decls.raw | sort >../musl.decls
96 cd ../..
97 done
98
99 # add decls to data/
100 for arch in $ARCH
101 do
102 grep '  bits/' T.$arch/musl.decls >data/musl.$arch.decls
103 done
104 for arch in $ARCH
105 do
106 grep -v '       bits/' T.$arch/musl.decls >data/musl.generic.decls
107 break
108 done