# The check CFLAGS are a superset of the libsigrok CFLAGS, and the
# python bindings CFLAGS are a superset of the C++ bindings CFLAGS.
-AM_CFLAGS = $(SR_WFLAGS) $(CHECK_CFLAGS)
+AM_CFLAGS = $(SR_EXTRA_CFLAGS) $(SR_WFLAGS) $(CHECK_CFLAGS)
AM_CXXFLAGS = $(SR_WXXFLAGS) $(PYSIGROK_CFLAGS)
lib_LTLIBRARIES = libsigrok.la
#define SR_CONFIG_H /* To stop multiple inclusions. */])
AH_BOTTOM([#endif /* SR_CONFIG_H */])
-# Enable more compiler warnings via -Wall and -Wextra. Add -fvisibility=hidden
-# and enforce use of SR_API to explicitly mark all public API functions.
-CFLAGS="$CFLAGS -std=c11"
-CFLAGS="$CFLAGS -fvisibility=hidden"
-CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112L"
-
# Checks for programs.
AC_PROG_CC
AC_PROG_CPP
AM_CONDITIONAL([HAVE_CHECK], [test "x$sr_have_check" = xyes])
AC_LANG([C])
+
+# Enable the C11 standard if possible, and enforce the use
+# of SR_API to explicitly mark all public API functions.
+SR_EXTRA_CFLAGS=
+SR_CHECK_COMPILE_FLAGS([SR_EXTRA_CFLAGS], [C11], [-std=gnu11 -std=c11])
+SR_CHECK_COMPILE_FLAGS([SR_EXTRA_CFLAGS], [visibility], [-fvisibility=hidden])
+
SR_ARG_ENABLE_WARNINGS([SR_WFLAGS], [-Wall], [-Wall -Wextra -Wmissing-prototypes])
# Check host characteristics.
- Prefix.......................... $prefix
- Building on..................... $build
- Building for.................... $host
+ - Additional C compiler flags..... $SR_EXTRA_CFLAGS
- C compiler warnings............. $SR_WFLAGS
- C++ compiler warnings........... $SR_WXXFLAGS
$@)[]dnl
])
+## SR_CHECK_COMPILE_FLAGS(flags-var, description, flags)
+##
+## Find a compiler flag for <description>. For each flag in <flags>, check
+## if the compiler for the current language accepts it. On success, stop the
+## search and append the last tested flag to <flags-var>. Calls AC_SUBST
+## on <flags-var>.
+##
+AC_DEFUN([SR_CHECK_COMPILE_FLAGS],
+[dnl
+m4_assert([$# >= 3])[]dnl
+AC_MSG_CHECKING([compiler flag for $2])
+sr_ccf_result=no
+sr_ccf_save_CPPFLAGS=$CPPFLAGS
+for sr_flag in $3
+do
+ CPPFLAGS="$sr_ccf_save_CPPFLAGS $sr_flag"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [sr_ccf_result=$sr_flag])
+ test "x$sr_ccf_result" = xno || break
+done
+CPPFLAGS=$sr_ccf_save_CPPFLAGS
+SR_APPEND([$1], [$sr_ccf_result])
+AC_MSG_RESULT([$sr_ccf_result])
+AC_SUBST([$1])
+])
+
## _SR_ARG_ENABLE_WARNINGS_ONCE
##
## Implementation helper macro of SR_ARG_ENABLE_WARNINGS. Pulled in