From 70e4ec9d08ca7c162dce873d82b5610c700cf707 Mon Sep 17 00:00:00 2001
From: Takashi Iwai
Date: Thu, 22 Mar 2007 00:48:18 +0100
Subject: [PATCH] Allow build without libdl and libpthread
Allow building alsa-lib without libdl and libpthread.
Added new options to configure, --with-libdl and --with-pthread.
---
Makefile.am | 5 +++-
configure.in | 53 +++++++++++++++++++++++++++++++++++++++++
include/local.h | 5 ++++
src/Makefile.am | 2 +-
src/async.c | 2 ++
src/conf.c | 16 ++++++++++---
src/confmisc.c | 4 ++++
src/control/control.c | 1 -
src/control/hcontrol.c | 11 +++++++--
src/dlmisc.c | 27 +++++++++++++++++----
src/hwdep/hwdep.c | 1 -
src/mixer/simple_abst.c | 4 ++--
src/pcm/pcm.c | 1 -
src/pcm/pcm_hooks.c | 1 -
src/pcm/pcm_ladspa.c | 1 -
src/pcm/pcm_rate.c | 3 +--
src/rawmidi/rawmidi.c | 1 -
src/seq/seq.c | 1 -
src/timer/timer.c | 1 -
src/timer/timer_query.c | 1 -
utils/alsa.pc.in | 2 +-
21 files changed, 118 insertions(+), 25 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index d6779060..6eb91fb6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,7 @@
-SUBDIRS=doc include src modules
+SUBDIRS=doc include src
+if BUILD_MODULES
+SUBDIRS += modules
+endif
if BUILD_PCM_PLUGIN_SHM
SUBDIRS += aserver
endif
diff --git a/configure.in b/configure.in
index 74ce2826..9aba9c90 100644
--- a/configure.in
+++ b/configure.in
@@ -149,6 +149,44 @@ else
AC_MSG_RESULT(no)
fi
+ALSA_DEPLIBS=""
+if test "$softfloat" != "yes"; then
+ ALSA_DEPLIBS="-lm"
+fi
+
+dnl Check for libdl
+AC_MSG_CHECKING(for libdl)
+AC_ARG_WITH(libdl,
+ [ --with-libdl Use libdl for plugins (default = yes)],
+ [ have_libdl="$withval" ], [ have_libdl="yes" ])
+if test "$have_libdl" = "yes"; then
+ AC_CHECK_LIB([dl], [dlsym], [HAVE_LIBDL="yes"])
+ if test "$HAVE_LIBDL" = "yes" ; then
+ ALSA_DEPLIBS="$ALSA_DEPLIBS -ldl"
+ AC_DEFINE([HAVE_LIBDL], 1, [Have libdl])
+ fi
+else
+ AC_MSG_RESULT(no)
+fi
+AM_CONDITIONAL(BUILD_MODULES, test "$HAVE_LIBDL"="yes")
+
+dnl Check for pthread
+AC_MSG_CHECKING(for pthread)
+AC_ARG_WITH(pthread,
+ [ --with-pthread Use pthread (default = yes)],
+ [ have_pthread="$withval" ], [ have_pthread="yes" ])
+if test "$have_pthread" = "yes"; then
+ AC_CHECK_LIB([pthread], [pthread_join], [HAVE_LIBPTHREAD="yes"])
+ if test "$HAVE_LIBPTHREAD" = "yes"; then
+ ALSA_DEPLIBS="$ALSA_DEPLIBS -lpthread"
+ AC_DEFINE([HAVE_LIBPTHREAD], 1, [Have libpthread])
+ fi
+else
+ AC_MSG_RESULT(no)
+fi
+
+AC_SUBST(ALSA_DEPLIBS)
+
dnl Check for architecture
AC_MSG_CHECKING(for architecture)
case "$target" in
@@ -320,6 +358,21 @@ if test "$build_pcm_ioplug" = "yes"; then
build_pcm_extplug="yes"
fi
+if test "$HAVE_LIBDL" != "yes"; then
+ build_pcm_meter="no"
+ build_pcm_ladspa="no"
+ build_pcm_pcm_ioplug="no"
+ build_pcm_pcm_extplug="no"
+fi
+
+if test "$HAVE_LIBPTHREAD" != "yes"; then
+ build_pcm_share="no"
+fi
+
+if test "$softfloat" != "yes"; then
+ build_pcm_lfloat="no"
+fi
+
AM_CONDITIONAL(BUILD_PCM_PLUGIN, test x$build_pcm_plugin = xyes)
AM_CONDITIONAL(BUILD_PCM_PLUGIN_COPY, test x$build_pcm_copy = xyes)
AM_CONDITIONAL(BUILD_PCM_PLUGIN_LINEAR, test x$build_pcm_linear = xyes)
diff --git a/include/local.h b/include/local.h
index 7d1b63e6..9f98f929 100644
--- a/include/local.h
+++ b/include/local.h
@@ -37,6 +37,11 @@
#ifdef SUPPORT_RESMGR
#include
#endif
+#ifdef HAVE_LIBDL
+#include
+#else
+#define RTLD_NOW 0
+#endif
#define _snd_config_iterator list_head
#define _snd_interval sndrv_interval
diff --git a/src/Makefile.am b/src/Makefile.am
index bcdebf1f..32ac8ad2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -41,7 +41,7 @@ SUBDIRS += alisp
libasound_la_LIBADD += alisp/libalisp.la
endif
SUBDIRS += compat conf
-libasound_la_LIBADD += compat/libcompat.la -lm -ldl -lpthread
+libasound_la_LIBADD += compat/libcompat.la @ALSA_DEPLIBS@
libasound_la_LDFLAGS = -version-info $(COMPATNUM) $(VSYMS)
diff --git a/src/async.c b/src/async.c
index 27718102..f6c6e63c 100644
--- a/src/async.c
+++ b/src/async.c
@@ -151,9 +151,11 @@ int snd_async_del_handler(snd_async_handler_t *handler)
if (!list_empty(&handler->hlist))
goto _end;
switch (handler->type) {
+#ifdef BUILD_PCM
case SND_ASYNC_HANDLER_PCM:
err = snd_pcm_async(handler->u.pcm, -1, 1);
break;
+#endif
case SND_ASYNC_HANDLER_CTL:
err = snd_ctl_async(handler->u.ctl, -1, 1);
break;
diff --git a/src/conf.c b/src/conf.c
index ed772bb8..030b6291 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -415,12 +415,13 @@ beginning:
#include
-#include
#include
#include
-#include
#include
#include "local.h"
+#ifdef HAVE_LIBPTHREAD
+#include
+#endif
#ifndef DOC_HIDDEN
@@ -3080,7 +3081,9 @@ int snd_config_update_r(snd_config_t **_top, snd_config_update_t **_update, cons
return 1;
}
+#ifdef HAVE_LIBPTHREAD
static pthread_mutex_t snd_config_update_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
/**
* \brief Updates #snd_config by rereading the global configuration files (if needed).
@@ -3099,9 +3102,13 @@ int snd_config_update(void)
{
int err;
+#ifdef HAVE_LIBPTHREAD
pthread_mutex_lock(&snd_config_update_mutex);
+#endif
err = snd_config_update_r(&snd_config, &snd_config_global_update, NULL);
+#ifdef HAVE_LIBPTHREAD
pthread_mutex_unlock(&snd_config_update_mutex);
+#endif
return err;
}
@@ -3128,15 +3135,18 @@ int snd_config_update_free(snd_config_update_t *update)
*/
int snd_config_update_free_global(void)
{
+#ifdef HAVE_LIBPTHREAD
pthread_mutex_lock(&snd_config_update_mutex);
+#endif
if (snd_config)
snd_config_delete(snd_config);
snd_config = NULL;
if (snd_config_global_update)
snd_config_update_free(snd_config_global_update);
snd_config_global_update = NULL;
+#ifdef HAVE_LIBPTHREAD
pthread_mutex_unlock(&snd_config_update_mutex);
-
+#endif
/* FIXME: better to place this in another place... */
snd_dlobj_cache_cleanup();
diff --git a/src/confmisc.c b/src/confmisc.c
index ff22d189..86b8de9c 100644
--- a/src/confmisc.c
+++ b/src/confmisc.c
@@ -946,6 +946,8 @@ int snd_func_card_name(snd_config_t **dst, snd_config_t *root,
SND_DLSYM_BUILD_VERSION(snd_func_card_name, SND_CONFIG_DLSYM_VERSION_EVALUATE);
#endif
+#ifdef BUILD_PCM
+
/**
* \brief Returns the pcm identification of a device.
* \param dst The function puts the handle to the result configuration node
@@ -1199,6 +1201,8 @@ int snd_func_private_pcm_subdevice(snd_config_t **dst, snd_config_t *root ATTRIB
SND_DLSYM_BUILD_VERSION(snd_func_private_pcm_subdevice, SND_CONFIG_DLSYM_VERSION_EVALUATE);
#endif
+#endif /* BUILD_PCM */
+
/**
* \brief Copies the specified configuration node.
* \param dst The function puts the handle to the result configuration node
diff --git a/src/control/control.c b/src/control/control.c
index 1880eeff..785bb94d 100644
--- a/src/control/control.c
+++ b/src/control/control.c
@@ -47,7 +47,6 @@ and IEC958 structure.
#include
#include
#include
-#include
#include
#include "control_local.h"
diff --git a/src/control/hcontrol.c b/src/control/hcontrol.c
index ede08870..051aaca6 100644
--- a/src/control/hcontrol.c
+++ b/src/control/hcontrol.c
@@ -48,11 +48,13 @@ to reduce overhead accessing the real controls in kernel drivers.
#include
#include
#include
-#include
#ifndef DOC_HIDDEN
#define __USE_GNU
#endif
#include "control_local.h"
+#ifdef HAVE_LIBPTHREAD
+#include
+#endif
#ifndef DOC_HIDDEN
#define NOT_FOUND 1000000000
@@ -420,17 +422,22 @@ static int hctl_compare(const void *a, const void *b) {
static void snd_hctl_sort(snd_hctl_t *hctl)
{
unsigned int k;
+#ifdef HAVE_LIBPTHREAD
static pthread_mutex_t sync_lock = PTHREAD_MUTEX_INITIALIZER;
+#endif
assert(hctl);
assert(hctl->compare);
INIT_LIST_HEAD(&hctl->elems);
+#ifdef HAVE_LIBPTHREAD
pthread_mutex_lock(&sync_lock);
+#endif
compare_hctl = hctl;
qsort(hctl->pelems, hctl->count, sizeof(*hctl->pelems), hctl_compare);
+#ifdef HAVE_LIBPTHREAD
pthread_mutex_unlock(&sync_lock);
-
+#endif
for (k = 0; k < hctl->count; k++)
list_add_tail(&hctl->pelems[k]->list, &hctl->elems);
}
diff --git a/src/dlmisc.c b/src/dlmisc.c
index 908a4125..48d89d7d 100644
--- a/src/dlmisc.c
+++ b/src/dlmisc.c
@@ -28,7 +28,6 @@
*/
#define _GNU_SOURCE
-#include
#include "list.h"
#include "local.h"
@@ -53,13 +52,19 @@ void *snd_dlopen(const char *name, int mode)
if (name == NULL)
return &snd_dlsym_start;
#else
+#ifdef HAVE_LIBDL
if (name == NULL) {
Dl_info dlinfo;
if (dladdr(snd_dlopen, &dlinfo) > 0)
name = dlinfo.dli_fname;
}
#endif
+#endif
+#ifdef HAVE_LIBDL
return dlopen(name, mode);
+#else
+ return NULL;
+#endif
}
/**
@@ -76,7 +81,11 @@ int snd_dlclose(void *handle)
if (handle == &snd_dlsym_start)
return 0;
#endif
+#ifdef HAVE_LIBDL
return dlclose(handle);
+#else
+ return 0;
+#endif
}
/**
@@ -91,6 +100,7 @@ int snd_dlclose(void *handle)
*/
static int snd_dlsym_verify(void *handle, const char *name, const char *version)
{
+#ifdef HAVE_LIBDL
int res;
char *vname;
@@ -107,6 +117,9 @@ static int snd_dlsym_verify(void *handle, const char *name, const char *version)
if (res < 0)
SNDERR("unable to verify version for symbol %s", name);
return res;
+#else
+ return 0;
+#endif
}
/**
@@ -139,10 +152,16 @@ void *snd_dlsym(void *handle, const char *name, const char *version)
return NULL;
}
#endif
- err = snd_dlsym_verify(handle, name, version);
- if (err < 0)
- return NULL;
+#ifdef HAVE_LIBDL
+ if (version) {
+ err = snd_dlsym_verify(handle, name, version);
+ if (err < 0)
+ return NULL;
+ }
return dlsym(handle, name);
+#else
+ return NULL;
+#endif
}
/*
diff --git a/src/hwdep/hwdep.c b/src/hwdep/hwdep.c
index 300c62a5..6e4e7fb7 100644
--- a/src/hwdep/hwdep.c
+++ b/src/hwdep/hwdep.c
@@ -33,7 +33,6 @@
#include
#include
#include
-#include
#include
#include "hwdep_local.h"
diff --git a/src/mixer/simple_abst.c b/src/mixer/simple_abst.c
index 45aedb05..26f620b2 100644
--- a/src/mixer/simple_abst.c
+++ b/src/mixer/simple_abst.c
@@ -82,14 +82,14 @@ static int try_open(snd_mixer_class_t *class, const char *lib)
free(xlib);
return -ENXIO;
}
- event_func = dlsym(h, "alsa_mixer_simple_event");
+ event_func = snd_dlsym(h, "alsa_mixer_simple_event", NULL);
if (event_func == NULL) {
SNDERR("Symbol 'alsa_mixer_simple_event' was not found in '%s'", xlib);
snd_dlclose(h);
free(xlib);
return -ENXIO;
}
- init_func = dlsym(h, "alsa_mixer_simple_init");
+ init_func = snd_dlsym(h, "alsa_mixer_simple_init", NULL);
if (init_func == NULL) {
SNDERR("Symbol 'alsa_mixer_simple_init' was not found in '%s'", xlib);
snd_dlclose(h);
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
index 07c7a005..fa29ceff 100644
--- a/src/pcm/pcm.c
+++ b/src/pcm/pcm.c
@@ -634,7 +634,6 @@ playback devices.
#include
#include
#include
-#include
#include
#include
#include
diff --git a/src/pcm/pcm_hooks.c b/src/pcm/pcm_hooks.c
index ee0f0405..4a368812 100644
--- a/src/pcm/pcm_hooks.c
+++ b/src/pcm/pcm_hooks.c
@@ -27,7 +27,6 @@
*
*/
-#include
#include "pcm_local.h"
#include "pcm_generic.h"
diff --git a/src/pcm/pcm_ladspa.c b/src/pcm/pcm_ladspa.c
index 73061536..a879a962 100644
--- a/src/pcm/pcm_ladspa.c
+++ b/src/pcm/pcm_ladspa.c
@@ -33,7 +33,6 @@
*/
#include
-#include
#include
#include
#include "pcm_local.h"
diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
index 63168407..0c594fd2 100644
--- a/src/pcm/pcm_rate.c
+++ b/src/pcm/pcm_rate.c
@@ -29,7 +29,6 @@
*/
#include
#include
-#include
#include "pcm_local.h"
#include "pcm_plugin.h"
#include "pcm_rate.h"
@@ -1326,7 +1325,7 @@ int snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sform
free(rate);
return -ENOENT;
}
- open_func = dlsym(h, open_name);
+ open_func = snd_dlsym(h, open_name, NULL);
if (! open_func) {
SNDERR("Cannot find function %s", open_name);
snd_dlclose(h);
diff --git a/src/rawmidi/rawmidi.c b/src/rawmidi/rawmidi.c
index 7f45742b..e7b93eba 100644
--- a/src/rawmidi/rawmidi.c
+++ b/src/rawmidi/rawmidi.c
@@ -139,7 +139,6 @@ This example shows open and read/write rawmidi operations.
#include
#include
#include
-#include
#include "rawmidi_local.h"
/**
diff --git a/src/seq/seq.c b/src/seq/seq.c
index 4d39335f..21f21f9c 100644
--- a/src/seq/seq.c
+++ b/src/seq/seq.c
@@ -777,7 +777,6 @@ void event_filter(snd_seq_t *seq, snd_seq_event_t *ev)
*/
-#include
#include
#include "seq_local.h"
diff --git a/src/timer/timer.c b/src/timer/timer.c
index 7776bb1c..b31252b4 100644
--- a/src/timer/timer.c
+++ b/src/timer/timer.c
@@ -72,7 +72,6 @@ This example shows opening a timer device and reading of timer events.
#include
#include
#include
-#include
#include
#include
#include "timer_local.h"
diff --git a/src/timer/timer_query.c b/src/timer/timer_query.c
index d62ee570..8f36e1ca 100644
--- a/src/timer/timer_query.c
+++ b/src/timer/timer_query.c
@@ -31,7 +31,6 @@
#include
#include
#include
-#include
#include
#include "timer_local.h"
diff --git a/utils/alsa.pc.in b/utils/alsa.pc.in
index b64f73a8..8de9859f 100644
--- a/utils/alsa.pc.in
+++ b/utils/alsa.pc.in
@@ -8,7 +8,7 @@ Description: Advanced Linux Sound Architecture (ALSA) - Library
Version: @VERSION@
Requires:
Libs: -L${libdir} -lasound
-Libs.private: -lm -ldl -lpthread
+Libs.private: @ALSA_DEPLIBS@
# -I${includedir}/alsa below is just for backward compatibility
# (it was set so mistakely in the older version)
Cflags: -I${includedir} -I${includedir}/alsa
--
2.47.1