Subject: Re: bug#64698: 29.0.92; on netbsd 9.3, gmake and "gmake bootstrap" fail to proceed

From: Valtteri Vuorikoski <[email-masked]>
Date: Sat, 22 Jul 2023 20:08:42 +0300

On Fri, Jul 21, 2023 at 02:03:41PM +0300, Eli Zaretskii wrote:
> > If you want to apply it for -30, this basically implements the
> > suggestion that was already dnl'd in configure.ac. Emacs will end up
> > using ossaudio even if the alsa-lib pkgsrc package is installed.
> 
> Thanks.  The comments say "NetBSD", but I don't quite see where this
> change affects only the *BSD systems, let alone NetBSD alone.  Maybe
> we should add that condition explicitly?  I'd hate to break some other
> system while fixing NetBSD.

Based on an investigation of source trees, libossaudio exists on
NetBSD and OpenBSD. Comments (diff below) have been updated to reflect
this. FreeBSD (going back from current to 4.x) and DragonflyBSD (from
current to 1.2) don't have it.

configure.ac --with-sound=yes cannot have picked bsd-ossaudio if
-lossaudio is not found, so this change should not have any effect on
FreeBSD/DragonflyBSD: LIBSOUND has always ended up empty on those and
hence the LIBSOUND=-lossaudio test will always fail.

Meanwhile OpenBSD appears to have behaved the same as NetBSD: use ALSA
if it exists, otherwise ossaudio. OpenBSD binary packages seem to be
built with --without-sound
(https://github.com/openbsd/ports/blob/master/editors/emacs/Makefile)
so this change won't affect their package builds in any case.

Updated diff (comment update only):

--- configure.ac.old     2023-07-22 16:27:51.312652423 +0000
+++ configure.ac        2023-07-22 16:30:58.860198891 +0000
@@ -1793,12 +1793,14 @@
     AC_MSG_ERROR([OSS sound support requested but not found.])

   if test "${with_sound}" = "bsd-ossaudio" || test "${with_sound}" = "yes"; then
-    # Emulation library used on NetBSD.
+    # OSS emulation library used on NetBSD and OpenBSD.
     AC_CHECK_LIB([ossaudio], [_oss_ioctl], [LIBSOUND=-lossaudio], [LIBSOUND=])
     test "${with_sound}" = "bsd-ossaudio" && test -z "$LIBSOUND" && \
       AC_MSG_ERROR([bsd-ossaudio sound support requested but not found.])
-    dnl FIXME?  If we did find ossaudio, should we set with_sound=bsd-ossaudio?
-    dnl Traditionally, we go on to check for alsa too.  Does that make sense?
+    # On {Net,Open}BSD use the system audio library instead of potentially switching
+    # to ALSA below, as ALSA on these appears to just wrap system libraries.
+    test "${with_sound}" = "yes" && test "$LIBSOUND" = "-lossaudio" && \
+      with_sound="bsd-ossaudio"
   fi
   AC_SUBST([LIBSOUND])

> > People who want alsa should be able to still get it with
> > --with-sound=alsa.
> 
> This should probably be mentioned in NEWS, then.

How about this for a NEWS entry:

  ** Emacs now always uses the ossaudio library for sound output on
  NetBSD and OpenBSD.
  Previously configure used ALSA libraries if installed on the
  system when --with-sound was set to "yes" (the default), with fallback to
  libossaudio. The libossaudio library included with the base system is now used even if
  ALSA is found to avoid relying on external packages and to resolve
  potential incompatibilities between Linux and BSD versions of ALSA.
  Set --with-sound=alsa to build with ALSA on these operating systems
  instead.

re Van's comment on the native sound API: it's true that ossaudio(3)
recommends using the native (lower-level?) API for new development,
but someone would have to implement support for it. Since there have
apparently been few complains wrt ossaudio, while ALSA on BSD on the
other hand seems slightly problematic (and is not the native API
either, but a wrapper similar to libossaudio), carrying on with
ossaudio seems reasonable from a development-effort perspective. But
I can't speak about the end-user perspective, since I don't have any
BSD boxen that are likely to output audio.

 -Valtteri