update makefile
[musl-tools.git] / makedecls.sh
blobca99085dd3c8ad6d649cadf540230af98cdc0857
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 m68k
15 microblaze
16 mips
17 mips64
18 mipsn32
19 or1k
20 powerpc
21 powerpc64
23 x32
24 x86_64
27 ARCH="${ARCH:-$ALL}"
29 # install headers to /tmp/T.$arch
30 for arch in $ARCH
32 [ -e T.$arch ] && continue
33 make -f "$MUSL"/Makefile install-headers srcdir="$MUSL" prefix=/tmp/T.$arch ARCH=$arch
34 rm -rf obj/include/bits
35 done
36 rm -rf obj lib
38 # run ctags on headers
39 for arch in $ARCH
41 [ -e /tmp/T.$arch/musl.tags ] && continue
43 cd /tmp/T.$arch/include
44 ctags -f ../musl.tags -R -n -u --language-force=c --c-kinds=pxdstuve --fields=k .
45 # fix wchar_t bug of ctags (not ok for c++)
46 awk '/typedef.* wchar_t/{print "wchar_t\tbits/alltypes.h\t" NR ";\"\tt"}' bits/alltypes.h >>../musl.tags
48 done
50 # add declarations (slow)
51 for arch in $ARCH
53 [ -e /tmp/T.$arch/musl.decls ] && continue
55 cd /tmp/T.$arch/include
56 awk '
57 BEGIN { FS="\t" }
59 function decl(t,h,n) {
60 cmd = "awk '\''NR==" n
61 if (t ~ /[pxt]/)
62 cmd = cmd "{s=$0; if(s!~/;/){getline; s=s \" \" $0} print s; exit}"
63 else if (t == "d")
64 cmd = cmd "{s=$0; while(gsub(/\\\\$/,\"\",s)){getline; s=s $0} print s; exit}"
65 else
66 return ""
67 cmd = cmd "'\'' " h
68 cmd | getline s
69 close(cmd)
70 gsub(/\t/, " ", s)
71 gsub(/ +/, " ", s)
72 if (t == "p")
73 gsub(/ \(/, "(", s)
74 return s
76 /^[^!]/ {
77 gsub(/[^0-9]*/,"",$3)
78 if ($4 == "s")
79 $1 = "struct " $1
80 if ($4 == "u")
81 $1 = "union " $1
82 # print $1 "\t" $2 "\t" $4 "\t" $3 "\t" decl($4,$2,$3)
83 # without line number
84 print $1 "\t" $2 "\t" $4 "\t" decl($4,$2,$3)
85 }' ../musl.tags >../musl.decls.raw
87 # fix ups
88 awk '
89 BEGIN { FS="\t" }
90 $3=="d" && $4 ~ /^#undef/ {next}
91 $3=="x" && $4 ~ /^(struct|union) [_0-9a-zA-Z]*;$/ {
92 a = ($4 ~ /^struct/) ? "struct " : "union "
93 b = ($4 ~ /^struct/) ? "S" : "U"
94 print a $1 "\t" $2 "\t" b "\t" $4
95 next
97 $1~/^(FILE|DIR)$/ {
98 print $1 "\t" $2 "\tT\t" $4
99 next
101 { print $0 }' ../musl.decls.raw | sort >../musl.decls
103 done
105 # add decls to data/
106 for arch in $ARCH
108 grep ' bits/' /tmp/T.$arch/musl.decls >data/musl.$arch.decls
109 done
110 for arch in $ARCH
112 grep -v ' bits/' /tmp/T.$arch/musl.decls >data/musl.generic.decls
113 break
114 done