From 46f663529320ad7c23ba0c7e0238596ab296624e Mon Sep 17 00:00:00 2001 From: AlaskanEmily Date: Sat, 2 May 2020 13:54:58 -0700 Subject: [PATCH] Fix compiling on OpenBSD for OSS rather than OpenAL --- src/GNUmakefile | 5 +++++ src/gcc.mk | 4 ++-- src/makefile | 5 +++++ src/oss/cin_oss.c | 4 ---- src/oss/cin_oss_driver.c | 9 ++++++++- src/oss/makefile | 2 +- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/GNUmakefile b/src/GNUmakefile index 8e7716a..044fee7 100755 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -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 diff --git a/src/gcc.mk b/src/gcc.mk index 9ba1716..773cba4 100755 --- a/src/gcc.mk +++ b/src/gcc.mk @@ -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) diff --git a/src/makefile b/src/makefile index 1db1299..d565826 100755 --- a/src/makefile +++ b/src/makefile @@ -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" diff --git a/src/oss/cin_oss.c b/src/oss/cin_oss.c index 21a63eb..730cf97 100644 --- a/src/oss/cin_oss.c +++ b/src/oss/cin_oss.c @@ -14,10 +14,6 @@ #define _DEFAULT_SOURCE #define _BSD_SOURCE -#if defined __GNUC__ -#include -#endif - #include #include #include diff --git a/src/oss/cin_oss_driver.c b/src/oss/cin_oss_driver.c index 23fac52..c7cba5c 100644 --- a/src/oss/cin_oss_driver.c +++ b/src/oss/cin_oss_driver.c @@ -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; diff --git a/src/oss/makefile b/src/oss/makefile index c8008ac..6b379c4 100644 --- a/src/oss/makefile +++ b/src/oss/makefile @@ -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 -- 2.11.0