OSDN Git Service

Fix compiling on OpenBSD for OSS rather than OpenAL
authorAlaskanEmily <emily@alaskanemily.net>
Sat, 2 May 2020 20:54:58 +0000 (13:54 -0700)
committerAlaskanEmily <emily@alaskanemily.net>
Sat, 2 May 2020 20:54:58 +0000 (13:54 -0700)
src/GNUmakefile
src/gcc.mk
src/makefile
src/oss/cin_oss.c
src/oss/cin_oss_driver.c
src/oss/makefile

index 8e7716a..044fee7 100755 (executable)
@@ -7,10 +7,15 @@ include gcc.mk
 
 BACKEND?=openal
 
+CURDIR=$(shell pwd)
 ifeq "$(BACKEND)" "dsound"
 LINK?=$(CXX)
 else ifeq "$(BACKEND)" "oss"
+
 EXTRALIBS=-lpthread
+# Get OSS emulation on BSD's
+EXTRALIBS+=$(if $(findstring $(shell uname),"BSD"),-lossaudio,)
+
 LINK?="$(CC)"
 else ifeq "$(BACKEND)" "openal"
 EXTRALIBS=-lopenal
index 9ba1716..773cba4 100755 (executable)
@@ -8,8 +8,8 @@ CIN_DEBUGFLAGS?= -g
 CC?=gcc
 CXX?=g++
 CCFLAGS?=-Wall -Wextra -pedantic -Wshadow -Wenum-compare -Wno-switch $(CIN_DEBUGFLAGS) $(CIN_FPICFLAGS)
-CFLAGS?=$(CCFLAGS) -ansi
-CXXFLAGS?=$(CCFLAGS) -std=c++98 -fno-rtti -fno-exceptions
+CFLAGS=$(CCFLAGS) -ansi
+CXXFLAGS=$(CCFLAGS) -std=c++98 -fno-rtti -fno-exceptions
 AR?=ar
 RANLIB?=ranlib
 LINKFLAGS?=$(CIN_DEBUGFLAGS) $(CIN_FPICFLAGS)
index 1db1299..d565826 100755 (executable)
@@ -7,10 +7,15 @@
 
 BACKEND?=oss
 
+CURDIR=${PWD}
 .if "${BACKEND}" == "dsound"
 LINK?=$(CXX)
 .else
 LINK=$(CC)
 .endif
 
+.if ${BACKEND} == oss
+EXTRALIBS=-lossaudio -lpthread
+.endif
+
 .include "unix.mk"
index 21a63eb..730cf97 100644 (file)
 #define _DEFAULT_SOURCE
 #define _BSD_SOURCE
 
-#if defined __GNUC__
-#include <alloca.h>
-#endif
-
 #include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
index 23fac52..c7cba5c 100644 (file)
@@ -323,7 +323,8 @@ enum Cin_DriverError Cin_CreateDriver(struct Cin_Driver *drv){
     drv->id_counter = 0;
     
     {
-        int dev = -1, val = 0;
+        int dev = -1, val;
+        char buffer[] = "/dev/audio\0";
         const char *const devname = getenv("AUDIODEV");
         if(devname != NULL)
             dev = open(devname, O_WRONLY);
@@ -331,6 +332,12 @@ enum Cin_DriverError Cin_CreateDriver(struct Cin_Driver *drv){
         if(dev == -1 && devname == NULL)
             dev = open("/dev/dsp", O_WRONLY);
         
+        /* Some BSD systems have /dev/audio* instead. */
+        for(val = 0; dev == -1 && val <= 10; val++){
+            dev = open(buffer, O_WRONLY);
+            buffer[sizeof(buffer)-2] = '0' + val;
+        }
+
         if(dev == -1){
             ret = Cin_eDriverNoDevice;
             goto fail_mutex;
index c8008ac..6b379c4 100644 (file)
@@ -16,7 +16,7 @@ libcin_oss_x.a: $(OBJECTS)
 
 libcin_oss.a: $(CIN_COMMONLIB) $(CIN_MIXERLIB) libcin_oss_x.a
        if [ -f libcin_oss2.a ] ; then rm libcin_oss2.a ; fi
-       echo 'create libcin_oss2.a\naddlib libcin_oss_x.a\naddlib $(CIN_COMMONLIB)\naddlib $(CIN_MIXERLIB)\nsave\nend\n' | $(AR) M
+       echo 'create libcin_oss2.a\naddlib libcin_oss_x.a\naddlib $(CIN_COMMONLIB)\naddlib $(CIN_MIXERLIB)\nsave\nend\n' | $(AR) -M
        $(RANLIB) libcin_oss2.a
        mv libcin_oss2.a libcin_oss.a