[vlc-devel] [PATCH 1/6] m4: add attributes.m4

Filip Roséen filip at atch.se
Sun Feb 26 20:13:11 CET 2017


---
 m4/Makefile.am   |  1 +
 m4/attributes.m4 | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 m4/attributes.m4

diff --git a/m4/Makefile.am b/m4/Makefile.am
index 1c71cd1903..bc9592a3f9 100644
--- a/m4/Makefile.am
+++ b/m4/Makefile.am
@@ -3,6 +3,7 @@ NULL =
 EXTRA_DIST = \
 	codeset.m4 \
 	extern-inline.m4 \
+	attributes.m4 \
 	flags.m4 \
 	gettext.m4 \
 	glibc21.m4 \
diff --git a/m4/attributes.m4 b/m4/attributes.m4
new file mode 100644
index 0000000000..e277c5e49b
--- /dev/null
+++ b/m4/attributes.m4
@@ -0,0 +1,41 @@
+# Copyright © 2017 Filip Roséen <filip at atch.se>
+# This file (attributes.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([PROG_CC_ATTRIBUTE_IFELSE], [
+  CFLAGS_save="${CFLAGS}"
+  CFLAGS="${CFLAGS} -Werror"
+
+  AS_VAR_PUSHDEF([ac_var], translit([[ac_cv_check_attr_$1_$2]],[("')]))
+
+  AC_CACHE_CHECK([if $CC supports __attribute__(($1))], [ac_var], [
+    AC_COMPILE_IFELSE( [AC_LANG_PROGRAM([$2 __attribute__(($1)) $3;])],
+      [AS_VAR_SET([ac_var],[yes])],
+      [AS_VAR_SET([ac_var],[no])] ) ])
+
+  AS_IF([test AS_VAR_GET([ac_var]) = "yes"], [$4], [$5])
+  AS_VAR_POPDEF([ac_var])
+
+  CFLAGS="${CFLAGS_save}" ])
+
+AC_DEFUN([AM_ATTRIBUTE_FN_IFELSE], [
+  PROG_CC_ATTRIBUTE_IFELSE(
+    [$1], [int], [f()], [$2], [$3]) ])
+
+AC_DEFUN([AM_ATTRIBUTE_STRUCT_IFELSE], [
+  PROG_CC_ATTRIBUTE_IFELSE(
+    [$1], [struct], [X{ char c;}], [$2], [$3]) ])
+
+AC_DEFUN([AM_ATTRIBUTE_FN_COND_DEFINE], [
+  AM_ATTRIBUTE_FN_IFELSE( [$1], [
+    AC_DEFINE([$2], [1], [__attribute__(($1)) is supported]) ]) ])
+
+AC_DEFUN([AM_ATTRIBUTE_STRUCT_COND_DEFINE], [
+  AM_ATTRIBUTE_STRUCT_IFELSE( [$1], [
+    AC_DEFINE([$2], [1], [__attribute__(($1)) is supported]) ]) ])
-- 
2.11.1



More information about the vlc-devel mailing list