Skip to content

Add sound multiplexer auto-detection when building #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ jobs:
strategy:
matrix:
dependency:
- libpulse-dev
- none
- libpulse-dev
- libjack-jackd2-dev
steps:
- name: checkout code
uses: actions/checkout@v4
Expand All @@ -19,7 +20,9 @@ jobs:
sudo apt-get install libasound2-dev libudev-dev
- name: install sound multiplexer ${{ matrix.dependency }}
if: matrix.dependency != 'none'
run: sudo apt-get install ${{ matrix.dependency }}
run: |
sudo apt-get update
sudo apt-get install ${{ matrix.dependency }}
- name: default build
run: make
shell: bash
Expand Down
31 changes: 24 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,50 @@ $(call set-feature, VIRTIOSND)
ifeq ($(call has, VIRTIOSND), 1)
OBJS_EXTRA += virtio-snd.o

PORTAUDIOLIB := portaudio/lib/.libs/libportaudio.a
LDFLAGS += $(PORTAUDIOLIB)
PA_LIB := portaudio/lib/.libs/libportaudio.a
PA_CFLAGS := -Iportaudio/include
PA_CONFIG_PARAMS :=
LDFLAGS += $(PA_LIB)
CFLAGS += $(PA_CFLAGS)

ifeq ($(UNAME_S),Linux)
LDFLAGS += -lasound -lrt
PA_CONFIG_PARAMS += --with-alsa
# Check PulseAudio installation
ifeq (0, $(call check-pa))
LDFLAGS += -lpulse
PA_CONFIG_PARAMS += --with-pulseaudio
endif
ifeq (0, $(call check-jack2))
LDFLAGS += -ljack
PA_CONFIG_PARAMS += --with-jack
endif
endif
ifeq ($(UNAME_S),Darwin)
LDFLAGS += -framework CoreServices -framework CoreFoundation -framework AudioUnit -framework AudioToolbox -framework CoreAudio
endif

CFLAGS += -Iportaudio/include
# PortAudio requires libm, yet we set -lm in the end of LDFLAGS
# so that the other libraries will be benefited for no need to set
# -lm separately.
LDFLAGS += -lpthread

portaudio/Makefile:
git submodule update --init portaudio
$(PORTAUDIOLIB): portaudio/Makefile
cd $(dir $<) && LDFLAGS="" ./configure --without-sndio
$(PA_LIB): portaudio/Makefile
cd $(dir $<) && git clean -fdx && git reset --hard HEAD
cd $(dir $<) && ./configure \
--enable-static \
--disable-shared \
--without-samples \
--without-tests \
--without-oss \
--without-sndio \
--disable-dependency-tracking \
$(PA_CONFIG_PARAMS)
$(MAKE) -C $(dir $<)
main.o: $(PORTAUDIOLIB)

main.o: $(PA_LIB)
virtio-snd.o: $(PA_LIB)
# suppress warning when compiling PortAudio
virtio-snd.o: CFLAGS += -Wno-unused-parameter
endif
Expand Down
23 changes: 21 additions & 2 deletions mk/check-libs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,27 @@ endef
define create-ca-prog
echo '\
#include <CoreAudio/CoreAudio.h>\n\
#include <AudioToolbox/AudioQueue.h>
#include <AudioToolbox/AudioQueue.h>\n\
int main(){\n\
AudioQueueRef queue;\n\
AudioQueueDispose(queue, TRUE);\n\
return 0;\n\
}\n'
endef

# Create a mininal jack2 program
define create-jack2-prog
echo '\
#include <stdlib.h>\n\
#include <jack/jack.h>\n\
int main(){\n\
jack_default_audio_sample_t *signal;\n\
signal = (jack_default_audio_sample_t *)malloc(1024 * sizeof(jack_default_audio_sample_t));\n\
free(signal);\n\
return 0;\n\
}\n'
endef

# Check ALSA installation
define check-alsa
$(shell $(call create-alsa-prog) | $(CC) -x c - -lasound -o /dev/null > /dev/null 2> /dev/null
Expand All @@ -40,11 +53,17 @@ endef

# Check PulseAudio installation
define check-pa
$(shell $(call create-pa-prog) | $(CC) -x c - -lpulse -o /dev/null && echo 0 || echo 1)
$(shell $(call create-pa-prog) | $(CC) -x c - -lpulse -o /dev/null > /dev/null 2> /dev/null && echo 0 || echo 1)
endef

# Check CoreAudio installation
define check-coreaudio
$(shell $(call create-ca-prog) | $(CC) -x c - -framework AudioToolbox -o /dev/null > /dev/null 2> /dev/null
&& echo 0 || echo 1)
endef

# Check JACK (formally jack2) installation
define check-jack2
$(shell $(call create-jack2-prog) | $(CC) -x c - -ljack -o /dev/null > /dev/null 2> /dev/null
&& echo 0 || echo 1)
endef
Loading