From aa02e1654bcdfa0677e19ab9bb27b44dc8bf26b9 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 17 Feb 2016 19:47:05 +0530 Subject: [PATCH] build-sys: Move to compiling with C11 support This is needed for building with anonymous unions. A bunch of calls to fail() that used to mysteriously work need fixing -- fail() is a macro that takes a printf-style message as an argument. Not passing this somehow worked with the previous compiler flags, but breaks with -std=c11. --- configure.ac | 6 +++- m4/ax_check_compile_flag.m4 | 74 ++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 2 +- src/tests/connect-stress.c | 6 ++-- src/tests/cpu-mix-test.c | 2 +- src/tests/cpu-remap-test.c | 4 +-- src/tests/cpu-sconv-test.c | 4 +-- src/tests/cpu-volume-test.c | 2 +- src/tests/cpulimit-test.c | 4 +-- src/tests/extended-test.c | 4 +-- src/tests/get-binary-name-test.c | 2 +- src/tests/interpol-test.c | 2 +- src/tests/mult-s16-test.c | 2 +- src/tests/sync-playback.c | 4 +-- 14 files changed, 98 insertions(+), 20 deletions(-) create mode 100644 m4/ax_check_compile_flag.m4 diff --git a/configure.ac b/configure.ac index 4553d71..8454e4c 100644 --- a/configure.ac +++ b/configure.ac @@ -80,7 +80,6 @@ AC_PROG_LN_S # CC AC_PROG_CC -AC_PROG_CC_C99 AM_PROG_CC_C_O # Only required if you want the WebRTC canceller -- no runtime dep on # libstdc++ otherwise @@ -177,6 +176,11 @@ esac #### Compiler flags #### +AX_CHECK_COMPILE_FLAG([-std=c11], + [], + [AC_MSG_ERROR([*** Compiler does not support -std=c11])], + [-pedantic -Werror]) + AX_APPEND_COMPILE_FLAGS( [-Wall -W -Wextra -pipe -Wno-long-long -Wno-overlength-strings -Wunsafe-loop-optimizations -Wundef -Wformat=2 -Wlogical-op -Wsign-compare -Wformat-security -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Winit-self -Wdeclaration-after-statement -Wfloat-equal -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wmissing-declarations -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-align -Wstrict-aliasing -Wwrite-strings -Wno-unused-parameter -ffast-math -fno-common -fdiagnostics-show-option -fdiagnostics-color=auto], [], [-pedantic -Werror]) diff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4 new file mode 100644 index 0000000..ca36397 --- /dev/null +++ b/m4/ax_check_compile_flag.m4 @@ -0,0 +1,74 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the current language's compiler +# or gives an error. (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 4 + +AC_DEFUN([AX_CHECK_COMPILE_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ + ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" + AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_COMPILE_FLAGS diff --git a/src/Makefile.am b/src/Makefile.am index 432d9c2..aa96999 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,7 +48,7 @@ AM_CPPFLAGS = \ -DPA_SRCDIR=\"$(abs_srcdir)\" \ -DPA_BUILDDIR=\"$(abs_builddir)\" \ -DPULSE_LOCALEDIR=\"$(localedir)\" -AM_CFLAGS = \ +AM_CFLAGS = -std=c11 \ $(PTHREAD_CFLAGS) AM_CXXFLAGS = -std=c++11 \ $(PTHREAD_CFLAGS) diff --git a/src/tests/connect-stress.c b/src/tests/connect-stress.c index 7c755e9..055ef13 100644 --- a/src/tests/connect-stress.c +++ b/src/tests/connect-stress.c @@ -80,7 +80,7 @@ static void connect(const char *name, int *try) { /* Connect the context */ if (pa_context_connect(context, NULL, 0, NULL) < 0) { fprintf(stderr, "pa_context_connect() failed.\n"); - fail(); + ck_abort(); } ret = pa_threaded_mainloop_start(mainloop); @@ -144,7 +144,7 @@ static void stream_state_callback(pa_stream *s, void *userdata) { default: case PA_STREAM_FAILED: fprintf(stderr, "Stream error: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s)))); - fail(); + ck_abort(); } } @@ -190,7 +190,7 @@ static void context_state_callback(pa_context *c, void *userdata) { case PA_CONTEXT_FAILED: default: fprintf(stderr, "Context error: %s\n", pa_strerror(pa_context_errno(c))); - fail(); + ck_abort(); } } diff --git a/src/tests/cpu-mix-test.c b/src/tests/cpu-mix-test.c index f3bc0cc..f42530d 100644 --- a/src/tests/cpu-mix-test.c +++ b/src/tests/cpu-mix-test.c @@ -118,7 +118,7 @@ static void run_mix_test( i, samples[i], samples_ref[i], samples0[i], samples1[i]); - fail(); + ck_abort(); } } } diff --git a/src/tests/cpu-remap-test.c b/src/tests/cpu-remap-test.c index cfe8647..7af5e29 100644 --- a/src/tests/cpu-remap-test.c +++ b/src/tests/cpu-remap-test.c @@ -70,7 +70,7 @@ static void run_remap_test_float( pa_log_debug("Correctness test failed: align=%d", align); pa_log_debug("%d: %.24f != %.24f\n", i, out[i], out_ref[i]); - fail(); + ck_abort(); } } } @@ -123,7 +123,7 @@ static void run_remap_test_s16( if (abs(out[i] - out_ref[i]) > 3) { pa_log_debug("Correctness test failed: align=%d", align); pa_log_debug("%d: %d != %d\n", i, out[i], out_ref[i]); - fail(); + ck_abort(); } } } diff --git a/src/tests/cpu-sconv-test.c b/src/tests/cpu-sconv-test.c index 2eb51de..3f189d1 100644 --- a/src/tests/cpu-sconv-test.c +++ b/src/tests/cpu-sconv-test.c @@ -65,7 +65,7 @@ static void run_conv_test_float_to_s16( if (abs(samples[i] - samples_ref[i]) > 1) { pa_log_debug("Correctness test failed: align=%d", align); pa_log_debug("%d: %04hx != %04hx (%.24f)\n", i, samples[i], samples_ref[i], floats[i]); - fail(); + ck_abort(); } } } @@ -115,7 +115,7 @@ static void run_conv_test_s16_to_float( if (fabsf(floats[i] - floats_ref[i]) > 0.0001f) { pa_log_debug("Correctness test failed: align=%d", align); pa_log_debug("%d: %.24f != %.24f (%d)\n", i, floats[i], floats_ref[i], samples[i]); - fail(); + ck_abort(); } } } diff --git a/src/tests/cpu-volume-test.c b/src/tests/cpu-volume-test.c index 01ac2fc..15f0658 100644 --- a/src/tests/cpu-volume-test.c +++ b/src/tests/cpu-volume-test.c @@ -78,7 +78,7 @@ static void run_volume_test( pa_log_debug("Correctness test failed: align=%d, channels=%d", align, channels); pa_log_debug("%d: %04hx != %04hx (%04hx * %08x)\n", i, samples[i], samples_ref[i], samples_orig[i], volumes[i % channels]); - fail(); + ck_abort(); } } } diff --git a/src/tests/cpulimit-test.c b/src/tests/cpulimit-test.c index 3a8124f..e01a5b8 100644 --- a/src/tests/cpulimit-test.c +++ b/src/tests/cpulimit-test.c @@ -48,7 +48,7 @@ static void func(pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata if ((now - start) >= 30) { m->quit(m, 1); fprintf(stderr, "Test failed\n"); - fail(); + ck_abort(); } else raise(SIGUSR1); } @@ -78,7 +78,7 @@ START_TEST (cpulimit_test) { if ((now - start) >= 30) { fprintf(stderr, "Test failed\n"); - fail(); + ck_abort(); break; } } diff --git a/src/tests/extended-test.c b/src/tests/extended-test.c index ee766b8..0d08fac 100644 --- a/src/tests/extended-test.c +++ b/src/tests/extended-test.c @@ -100,7 +100,7 @@ static void stream_state_callback(pa_stream *s, void *userdata) { default: case PA_STREAM_FAILED: fprintf(stderr, "Stream error: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s)))); - fail(); + ck_abort(); } } @@ -151,7 +151,7 @@ static void context_state_callback(pa_context *c, void *userdata) { case PA_CONTEXT_FAILED: default: fprintf(stderr, "Context error: %s\n", pa_strerror(pa_context_errno(c))); - fail(); + ck_abort(); } } diff --git a/src/tests/get-binary-name-test.c b/src/tests/get-binary-name-test.c index 4c855bb..cd53bde 100644 --- a/src/tests/get-binary-name-test.c +++ b/src/tests/get-binary-name-test.c @@ -39,7 +39,7 @@ START_TEST (getbinaryname_test) { if (!pa_get_binary_name(exename, allocated)) { pa_log_error("failed to read binary name"); pa_xfree(exename); - fail(); + ck_abort(); } if (strlen(exename) < allocated - 1) { diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 7a7bffc..b4cf18c 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -144,7 +144,7 @@ static void context_state_callback(pa_context *c, void *userdata) { case PA_CONTEXT_FAILED: default: pa_log_error("Context error: %s", pa_strerror(pa_context_errno(c))); - fail(); + ck_abort(); } } diff --git a/src/tests/mult-s16-test.c b/src/tests/mult-s16-test.c index 7340d85..91740c2 100644 --- a/src/tests/mult-s16-test.c +++ b/src/tests/mult-s16-test.c @@ -65,7 +65,7 @@ START_TEST (mult_s16_test) { if (a != b) { pa_log_debug("%d: %d != %d", i, a, b); - fail(); + ck_abort(); } } diff --git a/src/tests/sync-playback.c b/src/tests/sync-playback.c index f06b459..9ef038c 100644 --- a/src/tests/sync-playback.c +++ b/src/tests/sync-playback.c @@ -106,7 +106,7 @@ static void stream_state_callback(pa_stream *s, void *userdata) { default: case PA_STREAM_FAILED: fprintf(stderr, "Stream error: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s)))); - fail(); + ck_abort(); } } @@ -148,7 +148,7 @@ static void context_state_callback(pa_context *c, void *userdata) { case PA_CONTEXT_FAILED: default: fprintf(stderr, "Context error: %s\n", pa_strerror(pa_context_errno(c))); - fail(); + ck_abort(); } } -- 2.7.4