diff --git a/Makefile.am b/Makefile.am index e1e1ec8..12485da 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,5 @@ +ACLOCAL_AMFLAGS = -I . + pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = pthread-stubs.pc diff --git a/check-stub.m4 b/check-stub.m4 new file mode 100644 index 0000000..9478b42 --- /dev/null +++ b/check-stub.m4 @@ -0,0 +1,24 @@ +# CHECK_PTHREAD_STUB(PTHREAD-FUNC,TRYLINK-FUNC-BODY,[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) +AC_DEFUN([CHECK_PTHREAD_STUB], + [_CHECK_STUB([$1],[#include ],m4_shift($@))]) + +# CHECK_SEM_STUB(SEM-FUNC,TRYLINK-FUNC-BODY,[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) +AC_DEFUN([CHECK_SEM_STUB], + [_CHECK_STUB([$1],[#include ],m4_shift($@))]) + +# CHECK_STUB(FUNC,TRYLINK-INCLUDES,TRYLINK-FUNC-BODY,[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) +AC_DEFUN([_CHECK_STUB], +[dnl +AH_TEMPLATE(AS_TR_CPP([HAVE_$1]), [Define to 1 if you have the `$1' function.]) +dnl +AC_CACHE_CHECK([for $1], [ac_cv_func_$1], + [AC_TRY_LINK([$2], [$3], + [ac_cv_func_$1=yes], + [ac_cv_func_$1=no])]) +if test "x$ac_cv_func_$1" = "xyes"; then +AC_DEFINE(AS_TR_CPP([HAVE_$1])) +m4_default([$4], [:]) +else +m4_default([$5], [:]) +fi +]) diff --git a/configure.ac b/configure.ac index ffccea9..4568d01 100644 --- a/configure.ac +++ b/configure.ac @@ -30,11 +30,78 @@ if test "x$cc_cv_attribute_alias" = "xyes"; then fi -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_cond_wait pthread_cond_signal pthread_cond_broadcast pthread_equal sem_init sem_destroy sem_wait sem_trywait], - [], [PKG_CONFIG_LIBS='-L${libdir} -lpthread-stubs']) +lack_stubs= + + +CHECK_PTHREAD_STUB([pthread_self], + [(void)pthread_self();], + [], [lack_stubs=yes]) + +CHECK_PTHREAD_STUB([pthread_equal], + [pthread_t t1,t2; (void)pthread_equal(t1,t2);], + [], [lack_stubs=yes]) + +CHECK_PTHREAD_STUB([pthread_mutex_init], + [pthread_mutex_t m; (void)pthread_mutex_init(&m,(void*)0);], + [], [lack_stubs=yes]) + +CHECK_PTHREAD_STUB([pthread_mutex_destroy], + [pthread_mutex_t m; (void)pthread_mutex_destroy(&m);], + [], [lack_stubs=yes]) + +CHECK_PTHREAD_STUB([pthread_mutex_lock], + [pthread_mutex_t m; (void)pthread_mutex_lock(&m);], + [], [lack_stubs=yes]) + +CHECK_PTHREAD_STUB([pthread_mutex_unlock], + [pthread_mutex_t m; (void)pthread_mutex_unlock(&m);], + [], [lack_stubs=yes]) + +CHECK_PTHREAD_STUB([pthread_cond_init], + [pthread_cond_t c; (void)pthread_cond_init(&c,(void*)0);], + [], [lack_stubs=yes]) + +CHECK_PTHREAD_STUB([pthread_cond_destroy], + [pthread_cond_t c; (void)pthread_cond_destroy(&c);], + [], [lack_stubs=yes]) + +CHECK_PTHREAD_STUB([pthread_cond_wait], + [pthread_cond_t c; pthread_mutex_t m; (void)pthread_cond_wait(&c,&m);], + [], [lack_stubs=yes]) + +CHECK_PTHREAD_STUB([pthread_cond_signal], + [pthread_cond_t c; (void)pthread_cond_signal(&c);], + [], [lack_stubs=yes]) + +CHECK_PTHREAD_STUB([pthread_cond_broadcast], + [pthread_cond_t c; (void)pthread_cond_broadcast(&c);], + [], [lack_stubs=yes]) + + +CHECK_SEM_STUB([sem_init], + [sem_t s; (void)sem_init(&s,0,0);], + [], [lack_stubs=yes]) + +CHECK_SEM_STUB([sem_destory], + [sem_t s; (void)sem_destory(&s);], + [], [lack_stubs=yes]) + +CHECK_SEM_STUB([sem_wait], + [sem_t s; (void)sem_wait(&s);], + [], [lack_stubs=yes]) + +CHECK_SEM_STUB([sem_trywait], + [sem_t s; (void)sem_trywait(&s);], + [], [lack_stubs=yes]) + + +if test "x$lack_stubs" = "xyes"; then + PKG_CONFIG_LIBS='-L${libdir} -lpthread-stubs' +else + PKG_CONFIG_LIBS='' +fi AC_SUBST([PKG_CONFIG_LIBS]) -AM_CONDITIONAL(BUILD_LIB, test "x$PKG_CONFIG_LIBS" != x) +AM_CONDITIONAL(BUILD_LIB, test "x$lack_stubs" = "xyes") AC_CONFIG_FILES([Makefile pthread-stubs.pc]) AC_OUTPUT