[alsa-devel] alsa on non-linux

Patrick Welche prlw1 at cam.ac.uk
Tue Jan 14 11:17:09 CET 2014


On Mon, Jan 13, 2014 at 01:13:23PM +0100, Takashi Iwai wrote:
> At Fri, 10 Jan 2014 15:37:00 +0000,
> Patrick Welche wrote:
> > 
> > I am currently successfully running alsa-lib 1.0.22 with oss plugins on
> > a non-linux box. The advantage is that programs written to use libasound
> > work.
> > 
> > I just tried to update alsa-lib, and see that now alsa-lib directly
> > includes headers like linux/types.h, and all protection, such as
> > 
> >   #if defined(LINUX) || defined(__LINUX__) || defined(__linux__)
> > 
> > has been removed. This means that compilation on non-linux is
> > essentially impossible.
> > 
> > Is it that there is now a different way of obtaining that alsa lib
> > front end / oss back end layer?
> 
> Feel free to submit a fix patch :)
> 
> The inclusions of linux/*.h are mostly due to laziness.  If a patch is
> confirmed to work on both Linux glibc and others, we'll happily take
> that patch.

I started out, writing the attached patch in November, but then it looked
as though the boundaries of application library interface and linux sound
chip driver had become so blurred that I thought that a decision had been
taken to bin all OSes bar linux, hence the question. Can you give me a
hint on how you think it is supposed to work? (Which bits you know are
meant to be linux only, as they are the actual drivers, which bits you think
should be OS agnositic...)

Cheers,

Patrick
-------------- next part --------------
>From c60287a8c5d3175b6df07757241cb59f3b94edb7 Mon Sep 17 00:00:00 2001
From: Patrick Welche <prlw1 at cam.ac.uk>
Date: Tue, 12 Nov 2013 14:25:05 +0000
Subject: [PATCH] Portability fix: Use SND_LITTLE_ENDIAN / SND_BIG_ENDIAN
 instead of endian.h

The header file which defines __BYTE_ORDER varies wildly between
OSes, so give autoconf the job of detecting endianness. Use the
answer by defining SND_LITTLE_ENDIAN / SND_BIG_ENDIAN and using
them. (This may require teaching alsa-utilities expecting asoundlib.h
to include endian.h for them to use SND_LITTLE_ENDIAN instead.)
---
 configure.in             | 7 ++++++-
 include/asoundlib-head.h | 1 -
 include/local.h          | 9 +++------
 src/pcm/pcm_file.c       | 3 +--
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/configure.in b/configure.in
index 35fd89f..679decd 100644
--- a/configure.in
+++ b/configure.in
@@ -61,6 +61,7 @@ dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
 AC_C_INLINE
 AC_HEADER_TIME
+AC_C_BIGENDIAN
 
 dnl Checks for library functions.
 AC_PROG_GCC_TRADITIONAL
@@ -685,5 +686,9 @@ test "$build_seq" = "yes" && echo "#include <alsa/seq_event.h>" >> include/asoun
 test "$build_seq" = "yes" && echo "#include <alsa/seq.h>" >> include/asoundlib.h
 test "$build_seq" = "yes" && echo "#include <alsa/seqmid.h>" >> include/asoundlib.h
 test "$build_seq" = "yes" && echo "#include <alsa/seq_midi_event.h>" >> include/asoundlib.h
+echo "" >> include/asoundlib.h
+test "$ac_cv_c_bigendian" = "yes" && echo "#define SND_BIG_ENDIAN" >> include/asoundlib.h
+test "$ac_cv_c_bigendian" = "yes" && echo "#define SNDRV_BIG_ENDIAN" >> include/asoundlib.h
+test "$ac_cv_c_bigendian" = "no" && echo "#define SND_LITTLE_ENDIAN" >> include/asoundlib.h
+test "$ac_cv_c_bigendian" = "no" && echo "#define SNDRV_LITTLE_ENDIAN" >> include/asoundlib.h
 cat "$srcdir"/include/asoundlib-tail.h >> include/asoundlib.h
-
diff --git a/include/asoundlib-head.h b/include/asoundlib-head.h
index 71b5c29..31408a4 100644
--- a/include/asoundlib-head.h
+++ b/include/asoundlib-head.h
@@ -35,7 +35,6 @@
 #include <string.h>
 #include <fcntl.h>
 #include <assert.h>
-#include <endian.h>
 #include <sys/poll.h>
 #include <errno.h>
 #include <stdarg.h>
diff --git a/include/local.h b/include/local.h
index 9464efa..1e7c0dc 100644
--- a/include/local.h
+++ b/include/local.h
@@ -28,7 +28,6 @@
 #include <string.h>
 #include <fcntl.h>
 #include <assert.h>
-#include <endian.h>
 #include <stdarg.h>
 #include <sys/poll.h>
 #include <sys/types.h>
@@ -46,14 +45,12 @@
 #define RTLD_NOW	0
 #endif
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define SND_LITTLE_ENDIAN
-#define SNDRV_LITTLE_ENDIAN
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#ifdef WORDS_BIGENDIAN
 #define SND_BIG_ENDIAN
 #define SNDRV_BIG_ENDIAN
 #else
-#error "Unsupported endian..."
+#define SND_LITTLE_ENDIAN
+#define SNDRV_LITTLE_ENDIAN
 #endif
 
 #define _snd_config_iterator list_head
diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c
index 7123025..7ee5c37 100644
--- a/src/pcm/pcm_file.c
+++ b/src/pcm/pcm_file.c
@@ -26,7 +26,6 @@
  *
  */
   
-#include <endian.h>
 #include <byteswap.h>
 #include <ctype.h>
 #include <string.h>
@@ -90,7 +89,7 @@ typedef struct {
 	size_t filelen;
 } snd_pcm_file_t;
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifdef SND_LITTLE_ENDIAN
 #define TO_LE32(x)	(x)
 #define TO_LE16(x)	(x)
 #else
-- 
1.8.5.2



More information about the Alsa-devel mailing list