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