1
dnl check for __attribute__((packed))
2
dnl but only on compilers claiming to be gcc compatible
3
dnl because for example Sun's compiler silently ignores the packed attribute.
4
AC_MSG_CHECKING([for structure packing via __attribute__((packed))])
5
AC_CACHE_VAL([have_cv_attrib_packed],[
8
struct { int i __attribute__((packed)); } s;
10
#error Only checking for packed attribute on gcc-like compilers
12
[have_cv_attrib_packed=yes],
13
[have_cv_attrib_packed=no])
15
AC_MSG_RESULT([$have_cv_attrib_packed])
17
if test "$have_cv_attrib_packed" = no; then
18
AC_MSG_CHECKING([for structure packing via pragma])
19
AC_CACHE_VAL([have_cv_pragma_pack],[
21
int main(int argc, char **argv) {
22
#pragma pack(1) /* has to be in column 1 ! */
23
struct { char c; long l; } s;
24
return sizeof(s)==sizeof(s.c)+sizeof(s.l) ? 0:1; } ],
25
[have_cv_pragma_pack=yes],
26
[have_cv_pragma_pack=no])
28
AC_MSG_RESULT([$have_cv_pragma_pack])
29
if test "$have_cv_pragma_pack" = yes; then
30
AC_DEFINE([HAVE_PRAGMA_PACK], 1, "pragma pack")
32
AC_MSG_CHECKING([for structure packing via hppa/hp-ux pragma])
33
AC_CACHE_VAL([have_cv_pragma_pack_hpux],[
35
/* hppa/hp-ux wants pragma outside of function */
36
#pragma pack 1 /* has to be in column 1 ! */
37
struct { char c; long l; } s;
38
int main(int argc, char **argv) {
39
return sizeof(s)==sizeof(s.c)+sizeof(s.l) ? 0:1; } ],
40
[have_cv_pragma_pack_hpux=yes],
41
[have_cv_pragma_pack_hpux=no])
43
AC_MSG_RESULT([$have_cv_pragma_pack_hpux])
44
AC_DEFINE([HAVE_PRAGMA_PACK_HPPA], 1, "pragma pack hppa/hp-ux style")
48
dnl check for __attribute__((aligned))
49
AC_MSG_CHECKING([for type aligning via __attribute__((aligned))])
50
AC_CACHE_VAL([have_cv_attrib_aligned],[
52
[typedef int cl_aligned_int __attribute__((aligned));],
53
[have_cv_attrib_aligned=yes],
54
[have_cv_attrib_aligned=no])
56
AC_MSG_RESULT([$have_cv_attrib_aligned])
58
if test "$have_cv_attrib_packed" = no -a "$have_cv_pragma_pack" = no -a "$have_cv_pragma_pack_hpux" = no; then
59
AC_MSG_ERROR(Need to know how to pack structures with this compiler)
62
if test "$have_cv_attrib_packed" = yes; then
63
AC_DEFINE([HAVE_ATTRIB_PACKED], 1, [attrib packed])
66
if test "$have_cv_attrib_aligned" = yes; then
67
AC_DEFINE([HAVE_ATTRIB_ALIGNED], 1, [attrib aligned])
70
dnl Sanity check that struct packing works
71
AC_MSG_CHECKING([that structure packing works])
72
AC_CACHE_VAL([have_cv_struct_pack],[
74
#ifndef HAVE_ATTRIB_PACKED
75
#define __attribute__(x)
77
#ifdef HAVE_PRAGMA_PACK
78
#pragma pack(1) /* has to be in column 1 ! */
80
#ifdef HAVE_PRAGMA_PACK_HPPA
81
#pragma pack 1 /* has to be in column 1 ! */
84
struct { char c __attribute__((packed)); long l __attribute__((packed)); } s;
86
#ifdef HAVE_PRAGMA_PACK
89
#ifdef HAVE_PRAGMA_PACK_HPPA
93
struct { char c; long l;} s2;
95
#ifdef HAVE_PRAGMA_PACK
96
#pragma pack(1) /* has to be in column 1 ! */
98
#ifdef HAVE_PRAGMA_PACK_HPPA
99
#pragma pack 1 /* has to be in column 1 ! */
102
struct { char c; long l; } __attribute__((packed)) s3;
104
#ifdef HAVE_PRAGMA_PACK
107
#ifdef HAVE_PRAGMA_PACK_HPPA
111
int main(int argc, char **argv) {
112
if (sizeof(s)!=sizeof(s.c)+sizeof(s.l))
114
if (sizeof(s) != sizeof(s3))
116
return (sizeof(s2) >= sizeof(s)) ? 0 : 3;
118
[have_cv_struct_pack=yes],
119
[have_cv_struct_pack=no],
120
[have_cv_struct_pack=yes])
122
AC_MSG_RESULT([$have_cv_struct_pack])
124
if test "$have_cv_struct_pack" = "no"; then
125
AC_MSG_ERROR([Structure packing seems to be available, but is not working with this compiler])