在Autoconf项目中强制执行严格的C99

Joh*_*n X 10 c autoconf gcc autotools c99

我有一个用C编写的程序,它使用Autoconf.它使用AC_PROG_CC_C99configure.ac用gcc使用时转换到-std=gnu99编译器选项.该程序严格按照C99规范编写,不使用任何GNU扩展.

我们应该如何设置Autoconf以使编译器强制执行该操作?

uml*_*ute 7

我通常使用m4-macro来检查给定的编译器是否接受某个CFLAG.

将以下内容放入aclocal.m4(我通常使用m4/ax_check_cflags.m4代替):

# AX_CHECK_CFLAGS(ADDITIONAL-CFLAGS, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
#
# checks whether the $(CC) compiler accepts the ADDITIONAL-CFLAGS
# if so, they are added to the CXXFLAGS
AC_DEFUN([AX_CHECK_CFLAGS],
[
  AC_MSG_CHECKING([whether compiler accepts "$1"])
  cat > conftest.c++ << EOF
  int main(){
    return 0;
  }
  EOF
  if $CC $CPPFLAGS $CFLAGS -o conftest.o conftest.c++ [$1] > /dev/null 2>&1
  then
    AC_MSG_RESULT([yes])
    CFLAGS="${CFLAGS} [$1]"
    [$2]
  else
    AC_MSG_RESULT([no])
   [$3]
  fi
])dnl AX_CHECK_CFLAGS
Run Code Online (Sandbox Code Playgroud)

并使用类似的方法从configure.ac中调用它

AX_CHECK_CFLAGS([-std=c99 -pedantic])
Run Code Online (Sandbox Code Playgroud)