autofoo: Add __PACKED__ for optional struct packing

This commit is contained in:
Kim Woelders 2023-01-28 11:04:30 +01:00
parent d27354926a
commit 9222dad42d
2 changed files with 25 additions and 0 deletions

View File

@ -259,6 +259,7 @@ AM_CONDITIONAL(BUILD_DOC, test "$enable_doc_build" = "yes")
EC_C_WARNINGS()
EC_C_VISIBILITY(yes)
EC_C_PACKING()
EC_C_ASAN()
VERSION_MAJOR=`echo $VERSION | awk -F. '{print $1}'`
@ -328,6 +329,7 @@ echo
echo "Include filters...........: $enable_filters"
echo "Include text functions....: $enable_text"
echo "Use visibility hiding.....: $enable_visibility_hiding"
echo "Use struct packing........: $enable_packing"
echo
echo "Installation path.........: $prefix"
echo

23
m4/ec_packing.m4 Normal file
View File

@ -0,0 +1,23 @@
dnl Copyright (C) 2023 Kim Woelders
dnl This code is public domain and can be freely used or copied.
dnl Macro to define __PACKED__ if supported and --enable-packing is given
dnl Usage: EC_C_PACKING()
AC_DEFUN([EC_C_PACKING], [
AC_ARG_ENABLE([packing],
[AS_HELP_STRING([--enable-packing],
[enable packing structures for unaligned access @<:@default=no@:>@])],,
[enable_packing=no])
if test "x$enable_packing" = "xyes"; then
if test -n "$GCC"; then
AC_DEFINE(__PACKED__, __attribute__((packed)), [Use struct packing for unaligned access])
else
AC_MSG_ERROR([Struct packing was requested but no method is known])
fi
else
AC_DEFINE(__PACKED__, , [Not using struct packing for unaligned access])
fi
])