From 85afd2710b9d7fd59c98cc29bf589773f689ebbc Mon Sep 17 00:00:00 2001 From: Cuda Chen Date: Wed, 9 Jul 2025 10:32:34 +0800 Subject: [PATCH] Add sound multiplexer auto-detection when building --- .github/workflows/main.yml | 7 +++++-- Makefile | 31 ++++++++++++++++++++++++------- mk/check-libs.mk | 23 +++++++++++++++++++++-- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3cd3f9f..08cd9c9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,8 +8,9 @@ jobs: strategy: matrix: dependency: - - libpulse-dev - none + - libpulse-dev + - libjack-jackd2-dev steps: - name: checkout code uses: actions/checkout@v4 @@ -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 diff --git a/Makefile b/Makefile index da1d5dd..9603028 100644 --- a/Makefile +++ b/Makefile @@ -77,21 +77,29 @@ $(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. @@ -99,11 +107,20 @@ ifeq ($(call has, VIRTIOSND), 1) 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 diff --git a/mk/check-libs.mk b/mk/check-libs.mk index aba2f4a..4e60108 100644 --- a/mk/check-libs.mk +++ b/mk/check-libs.mk @@ -24,7 +24,7 @@ endef define create-ca-prog echo '\ #include \n\ -#include +#include \n\ int main(){\n\ AudioQueueRef queue;\n\ AudioQueueDispose(queue, TRUE);\n\ @@ -32,6 +32,19 @@ int main(){\n\ }\n' endef +# Create a mininal jack2 program +define create-jack2-prog +echo '\ +#include \n\ +#include \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 @@ -40,7 +53,7 @@ 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 @@ -48,3 +61,9 @@ 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