[vlc-commits] configure: test and enable C11 where available

Rémi Denis-Courmont git at videolan.org
Sun Jun 21 23:13:12 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jun 22 00:08:59 2015 +0300| [ce150f3849cebe97bc7fc028674d3c7f8c73f64d] | committer: Rémi Denis-Courmont

configure: test and enable C11 where available

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ce150f3849cebe97bc7fc028674d3c7f8c73f64d
---

 configure.ac |    1 +
 m4/c11.m4    |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/configure.ac b/configure.ac
index 4aba1af..05eb82a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,6 +45,7 @@ dnl Check for tools
 dnl
 AC_PROG_CC_C99
 AC_USE_SYSTEM_EXTENSIONS
+VLC_PROG_CC_C11
 AC_DEFINE([_FORTIFY_SOURCE], 2, [Define to 2 to get glibc warnings.])
 AC_DEFINE([_FILE_OFFSET_BITS], 64, [Define to 64 for large files support.])
 AH_TOP([
diff --git a/m4/c11.m4 b/m4/c11.m4
new file mode 100644
index 0000000..2288602
--- /dev/null
+++ b/m4/c11.m4
@@ -0,0 +1,44 @@
+# Copyright © 2015 Rémi Denis-Courmont
+# This file (c11.m4) is free software; unlimited permission to
+# copy and/or distribute it , with or without modifications, as long
+# as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+
+AC_DEFUN([VLC_PROG_CC_C11], [
+  AC_LANG_ASSERT(C)
+
+    for opt in "" -std=gnu11 -std=c11 -c11
+    do
+      cachevar=AS_TR_SH([ax_cv_c_compile_c11_$opt])
+      AC_CACHE_CHECK([whether $CC $opt supports C11], [$cachevar], [
+        CFLAGS_save="$CFLAGS"
+        CFLAGS="$CFLAGS $opt"
+        dnl PREPROC is not enough due to CFLAGS usage
+        AC_COMPILE_IFELSE([AC_LANG_SOURCE([
+[#ifndef __STDC_VERSION__
+# error Not a C compiler!
+#endif
+#if (__STDC_VERSION__ < 201112L)
+# error Too old C compiler!
+#endif
+_Static_assert(1, "Not C11!");
+const int varname = _Generic(1, int: 1, default: 0);
+]])], [
+          eval $cachevar="yes"
+        ], [
+          eval $cachevar="no"
+        ])
+        CFLAGS="$CFLAGS_save"
+      ])
+      if eval test "\$$cachevar" = "yes"
+      then
+        CFLAGS="$CFLAGS $opt"
+        break
+      fi
+    done
+])



More information about the vlc-commits mailing list