summaryrefslogtreecommitdiff
path: root/config/parse-types.sh
blob: d7cb9cc1be910da443988896022e90e091bd3592 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh

cat > sed.script << "EOF"
/^#/d
/^$/d
s/__extension__ //
s/typedef \(.*\) __u\([1-9]*\);/#define __U\2_TYPEDEF \1/
s/typedef \(.*\) __s\([1-9]*\);/#define __S\2_TYPEDEF \1/
EOF

if test -z "$CC"; then
    CC=gcc
fi

if test -z "$CPP"; then
    CPP="$CC -E"
fi

echo '#include <asm/types.h>' | $CPP - | \
    sed -f sed.script | grep '^#' > asm_types.h

rm sed.script

cp asm_types.h asm_types.c

cat >> asm_types.c <<EOF
#include <stdio.h>
#include <stdlib.h>
main(int argc, char **argv)
{
#ifdef __U8_TYPEDEF
	if (sizeof(__U8_TYPEDEF) != 1) {
		printf("Sizeof(__U8__TYPEDEF) is %d should be 1\n", 
		       sizeof(__U8_TYPEDEF));
		exit(1);
	}
#else
#warning __U8_TYPEDEF not defined
#endif
#ifdef __S8_TYPEDEF
	if (sizeof(__S8_TYPEDEF) != 1) {
		printf("Sizeof(_S8__TYPEDEF) is %d should be 1\n", 
		       sizeof(__S8_TYPEDEF));
		exit(1);
	}
#else
#warning __S8_TYPEDEF not defined
#endif
#ifdef __U16_TYPEDEF
	if (sizeof(__U16_TYPEDEF) != 2) {
		printf("Sizeof(__U16__TYPEDEF) is %d should be 2\n", 
		       sizeof(__U16_TYPEDEF));
		exit(1);
	}
#else
#warning __U16_TYPEDEF not defined
#endif
#ifdef __S16_TYPEDEF
	if (sizeof(__S16_TYPEDEF) != 2) {
		printf("Sizeof(__S16__TYPEDEF) is %d should be 2\n", 
		       sizeof(__S16_TYPEDEF));
		exit(1);
	}
#else
#warning __S16_TYPEDEF not defined
#endif

#ifdef __U32_TYPEDEF
	if (sizeof(__U32_TYPEDEF) != 4) {
		printf("Sizeof(__U32__TYPEDEF) is %d should be 4\n", 
		       sizeof(__U32_TYPEDEF));
		exit(1);
	}
#else
#warning __U32_TYPEDEF not defined
#endif
#ifdef __S32_TYPEDEF
	if (sizeof(__S32_TYPEDEF) != 4) {
		printf("Sizeof(__S32__TYPEDEF) is %d should be 4\n", 
		       sizeof(__S32_TYPEDEF));
		exit(1);
	}
#else
#warning __S32_TYPEDEF not defined
#endif

#ifdef __U64_TYPEDEF
	if (sizeof(__U64_TYPEDEF) != 8) {
		printf("Sizeof(__U64__TYPEDEF) is %d should be 8\n", 
		       sizeof(__U64_TYPEDEF));
		exit(1);
	}
#else
#warning __U64_TYPEDEF not defined
#endif
#ifdef __S64_TYPEDEF
	if (sizeof(__S64_TYPEDEF) != 8) {
		printf("Sizeof(__S64__TYPEDEF) is %d should be 8\n", 
		       sizeof(__S64_TYPEDEF));
		exit(1);
	}
#else
#warning __S64_TYPEDEF not defined
#endif
	exit(0);
}
EOF

${BUILD_CC-${CC-gcc}} -o asm_types asm_types.c
if ./asm_types
then
    true
else
    echo "Problem detected with asm_types.h"
    echo "" > asm_types.h
fi
rm asm_types.c asm_types