@@ -14,17 +14,18 @@ dnl Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
1414dnl Copyright (c) 2014-2015 Intel, Inc. All rights reserved.
1515dnl Copyright (c) 2015 Research Organization for Information Science
1616dnl and Technology (RIST). All rights reserved.
17+ dnl Copyright (c) 2021 Cisco Systems, Inc. All rights reserved.
1718dnl $COPYRIGHT $
1819dnl
1920dnl Additional copyrights may follow
2021dnl
2122dnl $HEADER $
2223dnl
2324
24- # OPAL_C_GET_ALIGN(type, config_var )
25+ # OPAL_C_GET_ALIGNMENT(c_type, c_macro_name )
2526# ----------------------------------
2627# Determine datatype alignment.
27- # First arg is type, 2nd arg is config var to define.
28+ # First arg is type, 2nd arg is macro name to define.
2829# Now that we require C99 compilers, we include stdbool.h
2930# in the alignment test so that we can find the definition
3031# of "bool" when we test for its alignment. We might be able
3334# what we use. Yes, they should be the same - but "should" and
3435# "are" frequently differ
3536AC_DEFUN([OPAL_C_GET_ALIGNMENT],[
36- AC_CACHE_CHECK([alignment of $1 ],
37- [AS_TR_SH([opal_cv_c_align_$1 ])],
38- [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
39- # include <stdbool.h> ],
40- [[
41- struct foo { char c; $1 x; };
42- struct foo * p = (struct foo * ) malloc(sizeof(struct foo));
43- int diff;
44- FILE * f= fopen(" conftestval" , " w" );
45- if (! f) exit(1);
46- diff = (( char * )& p-> x) - ((char * )& p-> c);
47- free(p);
48- fprintf(f, "%d\n", (diff >= 0 ) ? diff : -diff);
49- ]])], [AS_TR_SH([opal_cv_c_align_$1 ])=`cat conftestval`],
50- [AC_MSG_WARN([*** Problem running configure test!])
51- AC_MSG_WARN([*** See config.log for details.])
52- AC_MSG_ERROR([*** Cannot continue.])],
53- [ # cross compile - do a non-executable test. Trick
54- # taken from the Autoconf 2 .59 c. Switch to using
55- # AC_CHECK_ALIGNOF when we can require Autoconf 2 .60 .
56- _AC_COMPUTE_INT([(long int) offsetof (opal__type_alignof_, y)],
57- [AS_TR_SH([opal_cv_c_align_$1 ])],
58- [AC_INCLUDES_DEFAULT
59- #include <stdbool.h>
37+ OPAL_VAR_SCOPE_PUSH([opal_align_value])
38+ AC_LANG_PUSH([C])
6039
61- #ifndef offsetof
62- # define offsetof(type, member) ((char *) &((type *) 0 )->member - (char *) 0 )
63- #endif
64- typedef struct { char x; $1 y; } opal__type_alignof_;
65- ],
66- [AC_MSG_WARN([*** Problem running configure test!])
67- AC_MSG_WARN([*** See config.log for details.])
68- AC_MSG_ERROR([*** Cannot continue.])])])])
40+ AC_CHECK_ALIGNOF([$1 ], [AC_INCLUDES_DEFAULT
41+ # include <stdbool.h>
42+ ])
6943
70- AC_DEFINE_UNQUOTED([$2 ], [$AS_TR_SH ([opal_cv_c_align_$1 ])], [Alignment of type $1 ])
71- eval "$2 =$AS_TR_SH ([opal_cv_c_align_$1 ])"
44+ # Put the value determined from AC CHECK_ALIGNOF into an
45+ # easy-to-access shell variable.
46+ AS_VAR_COPY([opal_align_value],
47+ [ac_cv_alignof_]AS_TR_SH([$1 ]))
7248
73- rm -rf conftest* ]) dnl
49+ # This $opal_cv_c_align_* shell variable is used elsewhere in
50+ # configure.ac
51+ AS_VAR_COPY([opal_cv_c_align_]AS_TR_SH([$1 ]),
52+ [opal_align_value])
53+
54+ # This #define is used in C code.
55+ AC_DEFINE_UNQUOTED([$2 ], [$opal_align_value ], [Alignment of $1 ])
56+
57+ AC_LANG_POP([C])
58+ OPAL_VAR_SCOPE_POP
59+ ])
0 commit comments