Skip to content

Commit 37322df

Browse files
committed
Add CoreAudio check
1 parent f911e18 commit 37322df

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

Makefile

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ endif
5555

5656
# virtio-snd
5757
ENABLE_VIRTIOSND ?= 1
58-
ifneq ($(UNAME_S),$(filter $(UNAME_S),Linux))
58+
ifneq ($(UNAME_S),$(filter $(UNAME_S),Linux Darwin))
5959
ENABLE_VIRTIOSND := 0
6060
endif
6161

@@ -66,19 +66,34 @@ ifeq ($(UNAME_S),Linux)
6666
ENABLE_VIRTIOSND := 0
6767
endif
6868
endif
69+
ifeq ($(UNAME_S),Darwin)
70+
ifeq (0, $(call check-ca))
71+
$(warning No CoreAudio installed Check AudioToolbox in advance.)
72+
ENABLE_VIRTIOSND := 0
73+
endif
74+
endif
6975
$(call set-feature, VIRTIOSND)
7076
ifeq ($(call has, VIRTIOSND), 1)
7177
OBJS_EXTRA += virtio-snd.o
7278

7379
PORTAUDIOLIB := portaudio/lib/.libs/libportaudio.a
80+
LDFLAGS += $(PORTAUDIOLIB)
81+
82+
ifeq ($(UNAME_S),Linux)
83+
LDFLAGS += -lasound -lrt
84+
ifeq (1, $(call check-pa))
85+
LDFLAGS += -lpulse
86+
endif
87+
endif
88+
ifeq ($(UNAME_S),Darwin)
89+
LDFLAGS += -framework AudioToolbox
90+
endif
91+
92+
CFLAGS += -Iportaudio/include
7493
# PortAudio requires libm, yet we set -lm in the end of LDFLAGS
7594
# so that the other libraries will be benefited for no need to set
7695
# -lm separately.
77-
LDFLAGS += $(PORTAUDIOLIB) -lasound -lpthread -lrt
78-
ifeq (1, $(call check-pa))
79-
LDFLAGS += -lpulse
80-
endif
81-
CFLAGS += -Iportaudio/include
96+
LDFLAGS += -lpthread
8297

8398
portaudio/Makefile:
8499
git submodule update --init portaudio

mk/check-libs.mk

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ int main(){\n\
2121
}\n'
2222
endef
2323

24+
# Create a mininal CoreAudio program
25+
define create-ca-prog
26+
echo '\
27+
#include <CoreAudio/CoreAudio.h>\n\
28+
#include <AudioToolbox/AudioQueue.h>
29+
int main(){\n\
30+
AudioQueueRef queue;\n\
31+
AudioQueueDispose(queue, TRUE);\n\
32+
return 0;\n\
33+
}\n'
34+
endef
35+
2436
# Check ALSA installation
2537
define check-alsa
2638
$(shell $(call create-alsa-prog) | $(CC) -x c -lasound -o /dev/null > /dev/null 2> /dev/null -
@@ -32,3 +44,9 @@ define check-pa
3244
$(shell $(call create-pa-prog) | $(CC) -x c -lpulse -o /dev/null > /dev/null 2> /dev/null -
3345
&& echo $$?)
3446
endef
47+
48+
# Check CoreAudio installation
49+
define check-ca
50+
$(shell $(call create-ca-prog) | $(CC) -x c -framework AudioToolbox -o /dev/null > /dev/null 2> /dev/null -
51+
&& echo $$?)
52+
endef

0 commit comments

Comments
 (0)