There is no mention of a AC_PROG_CC_C11
analogue to AC_PROG_CC_C99
.
How can I get my autotools project to put --std=c11
into CFLAGS
?
Most simply by putting
CFLAGS+=" -std=c11"
into your configure.ac
(in addition to AC_PROG_CC
). configure.ac
is a template for a shell script, so you can simply put shell code in it. In fact, all the AC_FOO_BAR
m4 macros expand to shell code themselves.
Caveat: This will not check whether your compiler actually supports the -std=c11
flag. If you want to check for that, you can use use AX_CHECK_COMPILE_FLAG
from the autoconf archive:
AX_CHECK_COMPILE_FLAG([-std=c11], [
CFLAGS+=" -std=c11"
], [
echo "C compiler cannot compile C11 code"
exit -1
])
...although simply waiting until something fails in the compilation also works, I suppose. The error message will be nicer this way, though.
AC_DEFUN([AX_CHECK_STDC],
[AX_CHECK_COMPILE_FLAG([-std=gnu11],
[AX_APPEND_FLAG([-std=gnu11])],
[AX_CHECK_COMPILE_FLAG([-std=c11],
[AX_APPEND_FLAG([-std=c11])],
[AX_CHECK_COMPILE_FLAG([-std=c99],
[AX_APPEND_FLAG([-std=c99])],
[AC_MSG_ERROR([C compiled does not support at least C99!])])
])
])
])
Output:
checking whether C compiler accepts -std=gnu11... no
checking whether C compiler accepts -std=c11... no
checking whether C compiler accepts -std=c99... yes
(when building using shit Microchip xc16 PIC compiler)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With