From: Daniel Elstner Date: Sun, 23 Aug 2015 19:08:54 +0000 (+0200) Subject: Build: Check for accepted compiler flags X-Git-Tag: libsigrok-0.4.0~409 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b84a733105eea68cbc568850eba20bd571debad7;p=libsigrok.git Build: Check for accepted compiler flags Introduce the SR_CHECK_COMPILE_FLAGS macro and use it to check for additional compiler flags. Put the accepted flags into the separate substitution variable SR_EXTRA_CFLAGS. With this and the preceding changes, bug #578 should now be fixed. --- diff --git a/Makefile.am b/Makefile.am index 82d66f78..6be59dee 100644 --- a/Makefile.am +++ b/Makefile.am @@ -29,7 +29,7 @@ AM_CPPFLAGS = $(local_includes) -DFIRMWARE_DIR='"$(FIRMWARE_DIR)"' # 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 diff --git a/configure.ac b/configure.ac index 3aa73d48..c155611b 100644 --- a/configure.ac +++ b/configure.ac @@ -37,12 +37,6 @@ AH_TOP([#ifndef SR_CONFIG_H #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 @@ -112,6 +106,13 @@ SR_PKG_CHECK([check], [SR_PKGLIBS_CHECK], [check >= 0.9.4]) 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. @@ -429,6 +430,7 @@ libsigrok configuration summary: - 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 diff --git a/m4/sigrok.m4 b/m4/sigrok.m4 index 6bf00840..875bd163 100644 --- a/m4/sigrok.m4 +++ b/m4/sigrok.m4 @@ -237,6 +237,31 @@ _SR_ARG_OPT_PKG(m4_expand([AS_TR_SH([$1])]), $@)[]dnl ]) +## SR_CHECK_COMPILE_FLAGS(flags-var, description, flags) +## +## Find a compiler flag for . For each flag in , check +## if the compiler for the current language accepts it. On success, stop the +## search and append the last tested flag to . Calls AC_SUBST +## on . +## +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