summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorM Joonas Pihlaja <jpihlaja@cc.helsinki.fi>2010-03-11 02:50:25 +0200
committerJulien Danjou <julien@danjou.info>2010-05-05 11:02:37 +0200
commit26010a37d1196ada662c239f33eef41396b9b353 (patch)
treefc5dfd67d82ef31c10e3ac9b5cfb99de13bd0823
parentbe486b72eb0695684307e1c169b7a76337d12581 (diff)
Generate stubs.c at autogen time from a template file.
It's easier to add a line to a list of functions in a template file than copy-pasting five lines of template from other entries and editing configure.ac. Reviewed-by: Jamey Sharp <jamey@minilop.net>
-rw-r--r--.gitignore1
-rwxr-xr-xautogen.sh2
-rw-r--r--configure.ac11
-rw-r--r--list.m415
-rw-r--r--stubs.c192
-rw-r--r--stubs.c.m480
6 files changed, 107 insertions, 194 deletions
diff --git a/.gitignore b/.gitignore
index 9e32f24..fc5db88 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,3 +29,4 @@ stamp-h1
*.pc
*.tar.bz2
*.tar.gz
+stubs.c
diff --git a/autogen.sh b/autogen.sh
index 904cd67..44e664c 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -6,6 +6,8 @@ test -z "$srcdir" && srcdir=.
ORIGDIR=`pwd`
cd $srcdir
+m4 -P stubs.c.m4 >stubs.c
+
autoreconf -v --install || exit 1
cd $ORIGDIR || exit $?
diff --git a/configure.ac b/configure.ac
index 3a12a1a..ef300ad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,10 +29,17 @@ if test "x$cc_cv_attribute_alias" = "xyes"; then
AC_DEFINE([SUPPORT_ATTRIBUTE_ALIAS], 1, [Define this if the compiler supports the alias attribute])
fi
+dnl Grab the list of functions to test for from our template file.
+m4_define([funclist], [])
+m4_define([alias], [m4_if([$1],[na],[], [m4_append([funclist], [$3 ])])])
+m4_divert_push([KILL])
+m4_include([list.m4])
+m4_divert_pop([KILL])
+dnl Check which functions we need to provide aliases for.
PKG_CONFIG_LIBS=
-AC_CHECK_FUNCS([pthread_self pthread_mutex_init pthread_mutex_destroy pthread_mutex_lock pthread_mutex_unlock pthread_cond_init pthread_cond_destroy pthread_condattr_init pthread_condattr_destroy pthread_cond_wait pthread_cond_timedwait pthread_cond_signal pthread_cond_broadcast pthread_equal pthread_exit],
- [], [PKG_CONFIG_LIBS='-L${libdir} -lpthread-stubs'])
+AC_CHECK_FUNCS(funclist, [], [PKG_CONFIG_LIBS='-L${libdir} -lpthread-stubs'])
+
AC_SUBST([PKG_CONFIG_LIBS])
AM_CONDITIONAL(BUILD_LIB, test "x$PKG_CONFIG_LIBS" != x)
diff --git a/list.m4 b/list.m4
new file mode 100644
index 0000000..7d23c3c
--- /dev/null
+++ b/list.m4
@@ -0,0 +1,15 @@
+alias(zero, int, pthread_self)
+alias(zero, int, pthread_mutex_init)
+alias(zero, int, pthread_mutex_destroy)
+alias(zero, int, pthread_mutex_lock)
+alias(zero, int, pthread_mutex_unlock)
+alias(zero, int, pthread_cond_init)
+alias(zero, int, pthread_cond_destroy)
+alias(zero, int, pthread_condattr_init)
+alias(zero, int, pthread_condattr_destroy)
+alias(abort, int, pthread_cond_wait)
+alias(abort, int, pthread_cond_timedwait)
+alias(zero, int, pthread_cond_signal)
+alias(zero, int, pthread_cond_broadcast)
+alias(equal, int, pthread_equal)
+alias(exit, void, pthread_exit)
diff --git a/stubs.c b/stubs.c
deleted file mode 100644
index 962833d..0000000
--- a/stubs.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/* Copyright (C) 2006 Diego Pettenò
- * Inspired by libX11 code copyright (c) 1995 David E. Wexelblat.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the names of the authors or their
- * institutions shall not be used in advertising or otherwise to promote the
- * sale, use or other dealings in this Software without prior written
- * authorization from the authors.
- */
-
-#include <pthread.h>
-#include <stdlib.h>
-#include "config.h"
-
-#ifndef HAVE_PTHREAD_SELF
-#define NEED_ZERO_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_self() __attribute__ ((weak, alias ("__pthread_zero_stub")));
-# else
-# pragma weak pthread_self = __pthread_zero_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_MUTEX_INIT
-#define NEED_ZERO_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_mutex_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
-# else
-# pragma weak pthread_mutex_init = __pthread_zero_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_MUTEX_DESTROY
-#define NEED_ZERO_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_mutex_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
-# else
-# pragma weak pthread_mutex_destroy = __pthread_zero_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_MUTEX_LOCK
-#define NEED_ZERO_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_mutex_lock() __attribute__ ((weak, alias ("__pthread_zero_stub")));
-# else
-# pragma weak pthread_mutex_lock = __pthread_zero_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_MUTEX_UNLOCK
-#define NEED_ZERO_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_mutex_unlock() __attribute__ ((weak, alias ("__pthread_zero_stub")));
-# else
-# pragma weak pthread_mutex_unlock = __pthread_zero_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_COND_INIT
-#define NEED_ZERO_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_cond_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
-# else
-# pragma weak pthread_cond_init = __pthread_zero_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_COND_DESTROY
-#define NEED_ZERO_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_cond_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
-# else
-# pragma weak pthread_cond_destroy = __pthread_zero_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_CONDATTR_INIT
-#define NEED_ZERO_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_condattr_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
-# else
-# pragma weak pthread_condattr_init = __pthread_zero_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_CONDATTR_DESTROY
-#define NEED_ZERO_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_condattr_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
-# else
-# pragma weak pthread_condattr_destroy = __pthread_zero_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_COND_WAIT
-#define NEED_ABORT_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_cond_wait() __attribute__ ((weak, alias ("__pthread_abort_stub")));
-# else
-# pragma weak pthread_cond_wait = __pthread_abort_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_COND_TIMEDWAIT
-#define NEED_ABORT_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_cond_timedwait() __attribute__ ((weak, alias ("__pthread_abort_stub")));
-# else
-# pragma weak pthread_cond_timedwait = __pthread_abort_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_COND_SIGNAL
-#define NEED_ZERO_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_cond_signal() __attribute__ ((weak, alias ("__pthread_zero_stub")));
-# else
-# pragma weak pthread_cond_signal = __pthread_zero_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_COND_BROADCAST
-#define NEED_ZERO_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_cond_broadcast() __attribute__ ((weak, alias ("__pthread_zero_stub")));
-# else
-# pragma weak pthread_cond_broadcast = __pthread_zero_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_EQUAL
-#define NEED_EQUAL_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-int pthread_equal() __attribute__ ((weak, alias ("__pthread_equal_stub")));
-# else
-# pragma weak pthread_equal = __pthread_equal_stub
-# endif
-#endif
-
-#ifndef HAVE_PTHREAD_EXIT
-#define NEED_EXIT_STUB
-# ifdef SUPPORT_ATTRIBUTE_ALIAS
-void pthread_exit() __attribute__ ((weak, alias ("__pthread_exit_stub")));
-# else
-# pragma weak pthread_exit = __pthread_exit_stub
-# endif
-#endif
-
-#ifdef NEED_ZERO_STUB
-static int __pthread_zero_stub()
-{
- return 0;
-}
-#endif
-
-#ifdef NEED_ABORT_STUB
-static int __pthread_abort_stub()
-{
- abort();
-}
-#endif
-
-#ifdef NEED_EQUAL_STUB
-static int __pthread_equal_stub(pthread_t t1, pthread_t t2)
-{
- return (t1 == t2);
-}
-#endif
-
-#ifdef NEED_EXIT_STUB
-static void __pthread_exit_stub(void *ret)
-{
- exit(EXIT_SUCCESS);
-}
-#endif
diff --git a/stubs.c.m4 b/stubs.c.m4
new file mode 100644
index 0000000..1616c0a
--- /dev/null
+++ b/stubs.c.m4
@@ -0,0 +1,80 @@
+m4_divert(-1)m4_dnl -*- c -*-
+m4_changequote(`[',`]')
+m4_changecom()
+
+m4_define([upcase], [m4_translit([$*], [a-z], [A-Z])])
+
+m4_define([alias], [m4_dnl
+#ifndef upcase(HAVE_[$3])
+#define upcase(NEED_[$1]_STUB)
+# ifdef SUPPORT_ATTRIBUTE_ALIAS
+[$2] [$3]() __attribute__ ((weak, [alias] ("__pthread_[$1]_stub")));
+# else
+# pragma weak [$3] = __pthread_[$1]_stub
+# endif
+#endif
+])
+
+m4_divert(0)m4_dnl
+/* Copyright (C) 2006 Diego Pettenò
+ * Copyright (C) 2010 M Joonas Pihlaja
+ * Inspired by libX11 code copyright (c) 1995 David E. Wexelblat.
+ *
+ * This is an automatically created file from stubs.c.m4. Do not edit.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the authors or their
+ * institutions shall not be used in advertising or otherwise to promote the
+ * sale, use or other dealings in this Software without prior written
+ * authorization from the authors.
+ */
+
+#include <pthread.h>
+#include <stdlib.h>
+#include "config.h"
+
+m4_include([list.m4])
+
+#ifdef NEED_ZERO_STUB
+static int __pthread_zero_stub()
+{
+ return 0;
+}
+#endif
+
+#ifdef NEED_ABORT_STUB
+static int __pthread_abort_stub()
+{
+ abort();
+}
+#endif
+
+#ifdef NEED_EQUAL_STUB
+static int __pthread_equal_stub(pthread_t t1, pthread_t t2)
+{
+ return (t1 == t2);
+}
+#endif
+
+#ifdef NEED_EXIT_STUB
+static void __pthread_exit_stub(void *ret)
+{
+ exit(EXIT_SUCCESS);
+}
+#endif