update makefile
[musl-tables] / abi_type.sh
1 #!/bin/sh
2
3 export LC_ALL=C
4
5 ALL='
6 aarch64
7 arm
8 i386
9 m68k
10 microblaze
11 mips
12 mips64
13 mipsn32
14 or1k
15 powerpc
16 powerpc64
17 sh
18 x32
19 x86_64
20 '
21 ARCH="${ARCH:-$ALL}"
22
23 # install headers to T.$arch
24 for arch in $ARCH
25 do
26
27 {
28 awk -F'\t' '$3 ~ /^[sutSUT]$/ {
29         print $1
30 }' data/musl.generic.decls data/musl.$arch.decls
31 echo 'function_pointer
32 object_pointer
33 char
34 short
35 int
36 long
37 long_long
38 float
39 double
40 long_double
41 wchar_t
42 bool'
43 } |sort |uniq >/tmp/m.$arch.type
44
45 awk -F'\t' '{print $2}' data/musl.generic.decls |sort |uniq >/tmp/m.header
46
47 echo '
48 #define _GNU_SOURCE 1
49 #define _FILE_OFFSET_BITS 64
50 #define SYSLOG_NAMES 1
51 #include <stddef.h>
52 #include <sys/types.h>
53 ' >abi_type.$arch.cc
54
55 awk '
56 /^sys\/(cachectl|fantotify|errno|fcntl|io|kd|poll|reg|signal|soundcard|termios|vt)\.h$/ { printf "//" }
57 /^(wait)\.h$/ { printf "//" }
58 { w=0 }
59 /^(stdalign|stdnoreturn|threads)\.h$/ { w=1 }
60 {
61         if(w) print "#ifndef __GLIBC__"
62         print "#include <" $0 ">"
63         if(w) print "#endif"
64 }' /tmp/m.header >>abi_type.$arch.cc
65
66 echo '
67 typedef long long long_long;
68 typedef long double long_double;
69 typedef void *object_pointer;
70 typedef void (*function_pointer)();
71 struct size {char c;};
72 struct align {char c;};
73 struct incomplete {char c;};
74 #define T(s,t) void x_##t(s t x, s t* ptr, size(*y)[sizeof(s t)], align(*z)[__alignof__(s t)]){}
75 #define P(s,t) void x_##t(incomplete x, s t* ptr, incomplete y, incomplete z){}
76 #ifdef __GLIBC__
77 #define M(x)
78 #else
79 #define M(x) x
80 #endif
81 ' >>abi_type.$arch.cc
82
83 awk '
84 /^(struct|union) __(CODE|ptcb|siginfo|ucontext|sigjmp_buf|double_repr|float_repr|sigset_t|mbstate_t|fsid_t|locale_struct)$/ ||
85 /^(elf_fpxregset_t|struct user_fpxregs_struct|Sg_io_vec|struct ih_.*|struct ip6_hdrctl|tcp_seq|union _G_fpos64_t|struct cpu_set_t|__isoc_va_list|ns_tcp_tsig.*|ns_tsig_.*|struct ptrace_peeksiginfo_.*)$/ { printf "//" }
86 { if (!sub(/ /,",")) sub(/^/,",") }
87 /,(once_flag|mtx_t|cnd_t|thrd_start_t|thrd_t|tss_dtor_t|tss_t)$/ { print "M(T(" $0 "))"; next}
88 /,(DIR|FILE)$/ { print "P(" $0 ")"; next }
89 { print "T(" $0 ")" }' /tmp/m.$arch.type >>abi_type.$arch.cc
90 done
91
92 #$CXX -S -o - abi_type.cc |sed -n 's/^\(_Z.*\):/\1/p' |$CXXFILT |sed '
93 #s/^x_\([^(]*\)(\(.*\))/\1: \2/
94 #s/floatcomplex /float _Complex/g
95 #s/doublecomplex /double _Complex/g
96 #' >data/musl.abi_type