v1.1.14 update
[musl-tables] / makedecls.sh
1 #!/bin/sh
2
3 set -eu
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 or1k
17 powerpc
18 sh
19 x32
20 x86_64
21 '
22
23 ARCH="${ARCH:-$ALL}"
24
25 # install headers to /tmp/T.$arch
26 for arch in $ARCH
27 do
28 [ -e T.$arch ] && continue
29 make -f "$MUSL"/Makefile install-headers srcdir="$MUSL" prefix=/tmp/T.$arch ARCH=$arch
30 rm -rf obj/include/bits
31 done
32 rm -rf obj lib
33
34 # run ctags on headers
35 for arch in $ARCH
36 do
37 [ -e /tmp/T.$arch/musl.tags ] && continue
38 (
39 cd /tmp/T.$arch/include
40 ctags -f ../musl.tags -R -n -u --language-force=c --c-kinds=pxdstuve --fields=k .
41 # fix wchar_t bug of ctags (not ok for c++)
42 awk '/typedef.* wchar_t/{print "wchar_t\tbits/alltypes.h\t" NR ";\"\tt"}' bits/alltypes.h >>../musl.tags
43 )
44 done
45
46 # add declarations (slow)
47 for arch in $ARCH
48 do
49 [ -e /tmp/T.$arch/musl.decls ] && continue
50 (
51 cd /tmp/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         # without line number
80         print $1 "\t" $2 "\t" $4 "\t" decl($4,$2,$3)
81 }' ../musl.tags >../musl.decls.raw
82
83 # fix ups
84 awk '
85 BEGIN { FS="\t" }
86 $3=="d" && $4 ~ /^#undef/ {next}
87 $3=="x" && $4 ~ /^(struct|union) [_0-9a-zA-Z]*;$/ {
88         a = ($4 ~ /^struct/) ? "struct " : "union "
89         b = ($4 ~ /^struct/) ? "S" : "U"
90         print a $1 "\t" $2 "\t" b "\t" $4
91         next
92 }
93 $1~/^(FILE|DIR)$/ {
94         print $1 "\t" $2 "\tT\t" $4
95         next
96 }
97 { print $0 }' ../musl.decls.raw | sort >../musl.decls
98 )
99 done
100
101 # add decls to data/
102 for arch in $ARCH
103 do
104 grep '  bits/' /tmp/T.$arch/musl.decls >data/musl.$arch.decls
105 done
106 for arch in $ARCH
107 do
108 grep -v '       bits/' /tmp/T.$arch/musl.decls >data/musl.generic.decls
109 break
110 done