~ubuntu-branches/ubuntu/saucy/clamav/saucy-backports

« back to all changes in this revision

Viewing changes to m4/reorganization/code_checks/compiler_attribs.m4

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-07-15 01:08:10 UTC
  • mfrom: (0.35.47 sid)
  • Revision ID: package-import@ubuntu.com-20140715010810-ru66ek4fun2iseba
Tags: 0.98.4+dfsg-2~ubuntu13.10.1
No-change backport to saucy (LP: #1341962)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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],[
 
6
        AC_TRY_COMPILE(,
 
7
                [#ifdef __GNUC__
 
8
                 struct { int i __attribute__((packed)); } s;
 
9
                 #else
 
10
                 #error Only checking for packed attribute on gcc-like compilers
 
11
                 #endif],
 
12
                [have_cv_attrib_packed=yes],
 
13
                [have_cv_attrib_packed=no])
 
14
        ])
 
15
AC_MSG_RESULT([$have_cv_attrib_packed])
 
16
 
 
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],[
 
20
                AC_TRY_RUN([
 
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])
 
27
                ])
 
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")
 
31
        else
 
32
                AC_MSG_CHECKING([for structure packing via hppa/hp-ux pragma])
 
33
                AC_CACHE_VAL([have_cv_pragma_pack_hpux],[
 
34
                        AC_TRY_RUN([
 
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])
 
42
                ])
 
43
                AC_MSG_RESULT([$have_cv_pragma_pack_hpux])
 
44
                AC_DEFINE([HAVE_PRAGMA_PACK_HPPA], 1, "pragma pack hppa/hp-ux style")
 
45
        fi
 
46
fi
 
47
 
 
48
dnl check for __attribute__((aligned))
 
49
AC_MSG_CHECKING([for type aligning via __attribute__((aligned))])
 
50
AC_CACHE_VAL([have_cv_attrib_aligned],[
 
51
        AC_TRY_COMPILE(,
 
52
                [typedef int cl_aligned_int __attribute__((aligned));],
 
53
                [have_cv_attrib_aligned=yes],
 
54
                [have_cv_attrib_aligned=no])
 
55
        ])
 
56
AC_MSG_RESULT([$have_cv_attrib_aligned])
 
57
 
 
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)
 
60
fi
 
61
 
 
62
if test "$have_cv_attrib_packed" = yes; then
 
63
        AC_DEFINE([HAVE_ATTRIB_PACKED], 1, [attrib packed])
 
64
fi
 
65
 
 
66
if test "$have_cv_attrib_aligned" = yes; then
 
67
        AC_DEFINE([HAVE_ATTRIB_ALIGNED], 1, [attrib aligned])
 
68
fi
 
69
 
 
70
dnl Sanity check that struct packing works
 
71
AC_MSG_CHECKING([that structure packing works])
 
72
AC_CACHE_VAL([have_cv_struct_pack],[
 
73
    AC_TRY_RUN([
 
74
#ifndef HAVE_ATTRIB_PACKED
 
75
#define __attribute__(x)
 
76
#endif
 
77
#ifdef HAVE_PRAGMA_PACK
 
78
#pragma pack(1) /* has to be in column 1 ! */
 
79
#endif
 
80
#ifdef HAVE_PRAGMA_PACK_HPPA
 
81
#pragma pack 1 /* has to be in column 1 ! */
 
82
#endif
 
83
 
 
84
struct { char c __attribute__((packed)); long l __attribute__((packed)); } s;
 
85
 
 
86
#ifdef HAVE_PRAGMA_PACK
 
87
#pragma pack()
 
88
#endif
 
89
#ifdef HAVE_PRAGMA_PACK_HPPA
 
90
#pragma pack
 
91
#endif
 
92
 
 
93
struct { char c; long l;} s2;
 
94
 
 
95
#ifdef HAVE_PRAGMA_PACK
 
96
#pragma pack(1) /* has to be in column 1 ! */
 
97
#endif
 
98
#ifdef HAVE_PRAGMA_PACK_HPPA
 
99
#pragma pack 1 /* has to be in column 1 ! */
 
100
#endif
 
101
 
 
102
struct { char c; long l; } __attribute__((packed)) s3;
 
103
 
 
104
#ifdef HAVE_PRAGMA_PACK
 
105
#pragma pack()
 
106
#endif
 
107
#ifdef HAVE_PRAGMA_PACK_HPPA
 
108
#pragma pack
 
109
#endif
 
110
 
 
111
    int main(int argc, char **argv) {
 
112
        if (sizeof(s)!=sizeof(s.c)+sizeof(s.l))
 
113
            return 1;
 
114
        if (sizeof(s) != sizeof(s3))
 
115
            return 2;
 
116
        return (sizeof(s2) >= sizeof(s)) ? 0 : 3;
 
117
    }],
 
118
    [have_cv_struct_pack=yes],
 
119
    [have_cv_struct_pack=no],
 
120
    [have_cv_struct_pack=yes])
 
121
])
 
122
AC_MSG_RESULT([$have_cv_struct_pack])
 
123
 
 
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])
 
126
fi