From: Takashi Iwai
Subject: Re: Static build of alsa-lib
Date: Fri, 16 Mar 2007 15:18:04 +0100
Message-ID:
References: <217312.5363.qm@web31004.mail.mud.yahoo.com>
Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka")
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Return-path:
In-Reply-To: <217312.5363.qm@web31004.mail.mud.yahoo.com>
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Sender: alsa-devel-bounces@lists.sourceforge.net
Errors-To: alsa-devel-bounces@lists.sourceforge.net
To: Ciaccia
Cc: alsa-devel@lists.sourceforge.net
List-Id: alsa-devel@alsa-project.org
At Fri, 16 Mar 2007 06:17:00 -0700 (PDT),
Ciaccia wrote:
>
> Hi there,
> I would like to compile an alsa application for an
> embedded system with no shared-libraries support. My
> application just needs PCM, with no plug-ins, no mixer
> and no midi and the application should be a standalone
> executable with no external dependencies, otherwise it
> will not work.
>
> I tried to compile alsa-lib with static support, but
> without luck (-ldl is always needed in the gcc line
> and gcc always prints some weird warnings). Since I
> don't need external plugins nor ladspa, I think there
> should be a way to compile an application in a 100%
> static manner, but I still have to figure out how.
>
> I also found this thread with a similar problem with
> uClinux
> http://www.mail-archive.com/alsa-user@lists.sourceforge.net/msg18253.html
> but at the end I did not understand how/if the problem
> was solved.
>
> Do you think it should be possible to compile alsa-lib
> with no dependencies on dl? How?
>
> Otherwise, would it be possible to write an alsa
> application that does not rely on alsa-lib (i.e.,
> by using the alsa kernel APIs directly)? Has someone
> already tried it? Some hints?
>
> Every hint is extremely welcome
I worked on this sometime ago, and made a patch to build alsa-lib
without pthread and libdl. I don't remember why this wasn't applied.
IIRC, ulibc has the wrappers for pthread and libdl, so this wasn't
needed at that time in the end.
Otherwise, it should work. Build with --enable-static
--disable-shared, --disble-mixer, --disable-hwdep, etc.
Takashi
diff -r f1203eb7eb48 configure.in
--- a/configure.in Tue Mar 13 10:44:28 2007 +0100
+++ b/configure.in Fri Mar 16 15:07:51 2007 +0100
@@ -148,6 +148,23 @@ else
else
AC_MSG_RESULT(no)
fi
+
+AC_CHECK_LIB([dl], [dlsym], [HAVE_LIBDL="yes"])
+AC_CHECK_LIB([pthread], [pthread_join], [HAVE_LIBPTHREAD="yes"])
+
+ALSA_DEPLIBS=""
+if test "$softfloat" != "yes"; then
+ ALSA_DEPLIBS="-lm"
+fi
+if test "$HAVE_LIBDL" = "yes"; then
+ ALSA_DEPLIBS="$ALSA_DEPLIBS -ldl"
+ AC_DEFINE([HAVE_LIBDL], 1, [Have libdl])
+fi
+if test "$HAVE_LIBPTHREAD" = "yes"; then
+ ALSA_DEPLIBS="$ALSA_DEPLIBS -lpthread"
+ AC_DEFINE([HAVE_LIBPTHREAD], 1, [Have libpthread])
+fi
+AC_SUBST(ALSA_DEPLIBS)
dnl Check for architecture
AC_MSG_CHECKING(for architecture)
diff -r f1203eb7eb48 include/local.h
--- a/include/local.h Tue Mar 13 10:44:28 2007 +0100
+++ b/include/local.h Fri Mar 16 15:07:51 2007 +0100
@@ -36,6 +36,11 @@
#include "config.h"
#ifdef SUPPORT_RESMGR
#include
+#endif
+#ifdef HAVE_LIBDL
+#include
+#else
+#define RTLD_NOW 0
#endif
#define _snd_config_iterator list_head
diff -r f1203eb7eb48 src/Makefile.am
--- a/src/Makefile.am Tue Mar 13 10:44:28 2007 +0100
+++ b/src/Makefile.am Fri Mar 16 15:07:51 2007 +0100
@@ -41,7 +41,7 @@ libasound_la_LIBADD += alisp/libalisp.la
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 -r f1203eb7eb48 src/async.c
--- a/src/async.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/async.c Fri Mar 16 15:07:51 2007 +0100
@@ -151,9 +151,11 @@ int snd_async_del_handler(snd_async_hand
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 -r f1203eb7eb48 src/conf.c
--- a/src/conf.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/conf.c Fri Mar 16 15:07:51 2007 +0100
@@ -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 **_
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_up
*/
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 -r f1203eb7eb48 src/confmisc.c
--- a/src/confmisc.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/confmisc.c Fri Mar 16 15:07:51 2007 +0100
@@ -946,6 +946,8 @@ SND_DLSYM_BUILD_VERSION(snd_func_card_na
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
@@ -1198,6 +1200,8 @@ int snd_func_private_pcm_subdevice(snd_c
#ifndef DOC_HIDDEN
SND_DLSYM_BUILD_VERSION(snd_func_private_pcm_subdevice, SND_CONFIG_DLSYM_VERSION_EVALUATE);
#endif
+
+#endif /* BUILD_PCM */
/**
* \brief Copies the specified configuration node.
diff -r f1203eb7eb48 src/control/control.c
--- a/src/control/control.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/control/control.c Fri Mar 16 15:07:51 2007 +0100
@@ -47,7 +47,6 @@ and IEC958 structure.
#include
#include
#include
-#include
#include
#include "control_local.h"
diff -r f1203eb7eb48 src/control/hcontrol.c
--- a/src/control/hcontrol.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/control/hcontrol.c Fri Mar 16 15:07:51 2007 +0100
@@ -48,11 +48,13 @@ to reduce overhead accessing the real co
#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 void snd_hctl_sort(snd_hctl_t *hc
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 -r f1203eb7eb48 src/dlmisc.c
--- a/src/dlmisc.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/dlmisc.c Fri Mar 16 15:07:51 2007 +0100
@@ -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 m
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
if (res < 0)
SNDERR("unable to verify version for symbol %s", name);
return res;
+#else
+ return 0;
+#endif
}
/**
@@ -139,10 +152,14 @@ void *snd_dlsym(void *handle, const char
return NULL;
}
#endif
+#ifdef HAVE_LIBDL
err = snd_dlsym_verify(handle, name, version);
if (err < 0)
return NULL;
return dlsym(handle, name);
+#else
+ return NULL;
+#endif
}
/*
diff -r f1203eb7eb48 src/hwdep/hwdep.c
--- a/src/hwdep/hwdep.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/hwdep/hwdep.c Fri Mar 16 15:07:52 2007 +0100
@@ -33,7 +33,6 @@
#include
#include
#include
-#include
#include
#include "hwdep_local.h"
diff -r f1203eb7eb48 src/pcm/pcm.c
--- a/src/pcm/pcm.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/pcm/pcm.c Fri Mar 16 15:07:52 2007 +0100
@@ -634,7 +634,6 @@ playback devices.
#include
#include
#include
-#include
#include
#include
#include
diff -r f1203eb7eb48 src/pcm/pcm_hooks.c
--- a/src/pcm/pcm_hooks.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/pcm/pcm_hooks.c Fri Mar 16 15:07:52 2007 +0100
@@ -27,7 +27,6 @@
*
*/
-#include
#include "pcm_local.h"
#include "pcm_generic.h"
diff -r f1203eb7eb48 src/pcm/pcm_ladspa.c
--- a/src/pcm/pcm_ladspa.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/pcm/pcm_ladspa.c Fri Mar 16 15:07:52 2007 +0100
@@ -33,7 +33,6 @@
*/
#include
-#include
#include
#include
#include "pcm_local.h"
diff -r f1203eb7eb48 src/pcm/pcm_meter.c
--- a/src/pcm/pcm_meter.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/pcm/pcm_meter.c Fri Mar 16 15:07:52 2007 +0100
@@ -29,11 +29,12 @@
#include
#include
-#include
-#include
#include "pcm_local.h"
#include "pcm_plugin.h"
#include "iatomic.h"
+#ifdef HAVE_LIBPTHREAD
+#include
+#endif
#ifndef PIC
/* entry for static linking */
@@ -42,6 +43,20 @@ const char *_snd_module_pcm_meter = "";
#ifndef DOC_HIDDEN
#define FREQUENCY 50
+
+#ifndef HAVE_LIBPTHREAD
+#define pthread_mutex_trylock(x) 1
+#define pthread_mutex_lock(x)
+#define pthread_mutex_unlock(x)
+#define pthread_mutex_init(x, y)
+#define pthread_mutex_destroy(x)
+#define pthread_cond_init(x, y)
+#define pthread_cond_destroy(x)
+#define pthread_cond_wait(x, y)
+#define pthread_cond_signal(x)
+#define pthread_create(a, b, c, d)
+#define pthread_join(a, b)
+#endif
struct _snd_pcm_scope {
int enabled;
@@ -62,10 +77,12 @@ typedef struct _snd_pcm_meter {
int closed;
int running;
atomic_t reset;
+#ifdef HAVE_LIBPTHREAD
pthread_t thread;
pthread_mutex_t update_mutex;
pthread_mutex_t running_mutex;
pthread_cond_t running_cond;
+#endif
struct timespec delay;
void *dl_handle;
} snd_pcm_meter_t;
diff -r f1203eb7eb48 src/pcm/pcm_rate.c
--- a/src/pcm/pcm_rate.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/pcm/pcm_rate.c Fri Mar 16 15:07:52 2007 +0100
@@ -29,7 +29,6 @@
*/
#include
#include
-#include
#include "pcm_local.h"
#include "pcm_plugin.h"
#include "pcm_rate.h"
diff -r f1203eb7eb48 src/pcm/pcm_share.c
--- a/src/pcm/pcm_share.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/pcm/pcm_share.c Fri Mar 16 15:07:52 2007 +0100
@@ -36,8 +36,10 @@
#include
#include
#include
+#include "pcm_local.h"
+#ifdef HAVE_LIBPTHREAD
#include
-#include "pcm_local.h"
+#endif
#ifndef PIC
/* entry for static linking */
@@ -47,8 +49,11 @@ const char *_snd_module_pcm_share = "";
#ifndef DOC_HIDDEN
static LIST_HEAD(snd_pcm_share_slaves);
+#ifdef HAVE_LIBPTHREAD
static pthread_mutex_t snd_pcm_share_slaves_mutex = PTHREAD_MUTEX_INITIALIZER;
-
+#endif
+
+#ifdef HAVE_LIBPTHREAD
#ifdef MUTEX_DEBUG
#define Pthread_mutex_lock(mutex) \
char *snd_pcm_share_slaves_mutex_holder;
@@ -71,6 +76,18 @@ do { \
#define Pthread_mutex_lock(mutex) pthread_mutex_lock(mutex)
#define Pthread_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
#endif
+#else /* !HAVE_LIBPTHREAD */
+#define Pthread_mutex_lock(mutex)
+#define Pthread_mutex_unlock(mutex)
+#define pthread_create(a, b, c, d)
+#define pthread_join(a, b)
+#define pthread_mutex_init(a, b)
+#define pthread_mutex_destroy(a)
+#define pthread_cond_init(a, b)
+#define pthread_cond_destroy(a)
+#define pthread_cond_wait(a, b)
+#define pthread_cond_signal(a)
+#endif /* HAVE_LIBPTHREAD */
typedef struct {
struct list_head clients;
@@ -91,12 +108,14 @@ typedef struct {
snd_pcm_uframes_t hw_ptr;
int poll[2];
int polling;
+#ifdef HAVE_LIBPTHREAD
pthread_t thread;
pthread_mutex_t mutex;
#ifdef MUTEX_DEBUG
char *mutex_holder;
#endif
pthread_cond_t poll_cond;
+#endif
} snd_pcm_share_slave_t;
typedef struct {
diff -r f1203eb7eb48 src/rawmidi/rawmidi.c
--- a/src/rawmidi/rawmidi.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/rawmidi/rawmidi.c Fri Mar 16 15:07:52 2007 +0100
@@ -139,7 +139,6 @@ This example shows open and read/write r
#include
#include
#include
-#include
#include "rawmidi_local.h"
/**
diff -r f1203eb7eb48 src/seq/seq.c
--- a/src/seq/seq.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/seq/seq.c Fri Mar 16 15:07:52 2007 +0100
@@ -777,7 +777,6 @@ void event_filter(snd_seq_t *seq, snd_se
*/
-#include
#include
#include "seq_local.h"
diff -r f1203eb7eb48 src/timer/timer.c
--- a/src/timer/timer.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/timer/timer.c Fri Mar 16 15:07:52 2007 +0100
@@ -72,7 +72,6 @@ This example shows opening a timer devic
#include
#include
#include
-#include
#include
#include
#include "timer_local.h"
diff -r f1203eb7eb48 src/timer/timer_query.c
--- a/src/timer/timer_query.c Tue Mar 13 10:44:28 2007 +0100
+++ b/src/timer/timer_query.c Fri Mar 16 15:07:52 2007 +0100
@@ -31,7 +31,6 @@
#include
#include
#include
-#include
#include
#include "timer_local.h"
diff -r f1203eb7eb48 utils/alsa.pc.in
--- a/utils/alsa.pc.in Tue Mar 13 10:44:28 2007 +0100
+++ b/utils/alsa.pc.in Fri Mar 16 15:07:52 2007 +0100
@@ -8,7 +8,7 @@ Version: @VERSION@
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
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV