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.
This commit is contained in:
parent
1bb196e496
commit
b84a733105
|
@ -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
|
||||
|
|
14
configure.ac
14
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
|
||||
|
||||
|
|
25
m4/sigrok.m4
25
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 <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
|
||||
|
|
Loading…
Reference in New Issue