drgn/libdrgn/m4/my_c_auto.m4
Omar Sandoval ca810eec66 libdrgn: define auto to __auto_type via autoconf
Let's pretend we live in the C23 future.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-08-16 10:32:39 -07:00

22 lines
827 B
Plaintext

# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: LGPL-2.1-or-later
# Check whether C23 auto is supported by the current compiler and compilation
# flags. If not, but the GNU __auto_type extension is supported, define auto to
# __auto_type. Otherwise, fail.
AC_DEFUN([MY_C_AUTO],
[AC_CACHE_CHECK([for auto], [my_cv_c_auto],
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[auto x = 1;]])],
[my_cv_c_auto=yes], [my_cv_c_auto=no])])
if test "x$my_cv_c_auto" != xyes; then
AC_CACHE_CHECK([for __auto_type], [my_cv_c___auto_type],
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[__auto_type x = 1;]])],
[my_cv_c___auto_type=yes], [my_cv_c___auto_type=no])])
if test "x$my_cv_c___auto_type" == xyes; then
AC_DEFINE([auto], [__auto_type])
else
AC_MSG_ERROR([no auto or __auto_type])
fi
fi
])