简体   繁体   English

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

[英]Enforce strict C99 in Autoconf project

I have a program written in C and it uses Autoconf. 我有一个用C编写的程序,它使用Autoconf。 It uses AC_PROG_CC_C99 in configure.ac which when used with gcc translates to the -std=gnu99 compiler option. 它在configure.ac中使用AC_PROG_CC_C99 ,当与gcc一起使用时,它将转换为-std=gnu99编译器选项。 The program is written somewhat strictly according to the C99 specification and does not use any GNU extensions. 该程序是严格按照C99规范编写的,并且不使用任何GNU扩展。

How should we set up Autoconf in order to make the compiler enforce that? 我们应该如何设置Autoconf,以使编译器强制执行该任务?

i usually use an m4-macro that checks whether a given compiler accepts a certain CFLAG. 我通常使用m4宏来检查给定的编译器是否接受特定的CFLAG。

put the following into your aclocal.m4 (i usually use m4/ax_check_cflags.m4 instead): 将以下内容放入您的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

and call it from configure.ac with something like 并从configure.ac调用它,例如

AX_CHECK_CFLAGS([-std=c99 -pedantic])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM