Enforce strict C99 in Autoconf project
Asked Answered
S

1

10

I have a program written in C and it uses Autoconf. It uses AC_PROG_CC_C99 in configure.ac which when used with gcc translates to the -std=gnu99 compiler option. The program is written somewhat strictly according to the C99 specification and does not use any GNU extensions.

How should we set up Autoconf in order to make the compiler enforce that?

Sheeree answered 5/5, 2012 at 21:20 Comment(2)
the flags you're looking for are -std=c99 -pedantic, which need to end up in CFLAGS; no idea how to best go about this, though :(Hindrance
Thanks. I assume that I can add them manually but if it's possible I would prefer that Autoconf did it. I don't know if it supports it.Sheeree
B
7

i usually use an m4-macro that checks whether a given compiler accepts a certain CFLAG.

put the following into your aclocal.m4 (i usually use m4/ax_check_cflags.m4 instead):

# 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

AX_CHECK_CFLAGS([-std=c99 -pedantic])
Borlow answered 21/5, 2012 at 9:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.