diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-09-09 15:47:51 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2020-09-09 15:47:51 -0700 |
commit | 42977fb0776f8907435d65de7c6b348c45e1a3e9 (patch) | |
tree | d1c3a4999cb35e9177416096289d1eca774c8e5a | |
parent | 24ff328c9ce7255dc6f7ff2d3496003f9382c8c3 (diff) |
configure: implement --with-audio=(no|yes)
This adds the ability to turn off the audio/music parts of the
API, removing the SDL2_Mixer dependency when disabled.
It will also automatically disable the audio/music parts of the
API when SDL2_Mixer isn't detected @ configure time and
--with-audio was unspecified.
It's a bit ugly with a bunch of #ifdef's in play.c, oh well.
-rw-r--r-- | configure.ac | 20 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/play.c | 15 |
3 files changed, 34 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index 3855060..539fa19 100644 --- a/configure.ac +++ b/configure.ac @@ -14,8 +14,24 @@ PKG_CHECK_MODULES(SDL2, sdl2) CFLAGS="$CFLAGS $SDL2_CFLAGS" LIBS="$LIBS $SDL2_LIBS" -dnl Check for SDL2_mixer -PKG_CHECK_MODULES(SDL2_MIXER, SDL2_mixer) +dnl Check for SDL2_mixer unless --with-audio=no, fails when missing and --with-audio=yes +AC_ARG_WITH( + [audio], + [AS_HELP_STRING([--with-audio], [Enable audio/music API via SDL2_mixer @<:@default=check@:>@])], + [], + [with_audio=check]) + +AS_CASE( + ["$with_audio"], + [yes], [PKG_CHECK_MODULES(SDL2_MIXER, SDL2_mixer, [HAVE_MIXER=1])], + [no], [HAVE_MIXER=0], + [PKG_CHECK_MODULES(SDL2_MIXER, SDL2_mixer, [HAVE_MIXER=1], [HAVE_MIXER=0])]) + +dnl this gets the define for compilation +AS_IF([test "x$HAVE_MIXER" = x1], [AC_DEFINE([WITH_AUDIO],[],[Enable audio/music API])]) +dnl this gets the define for Makefile.am +AM_CONDITIONAL([WITH_AUDIO], [test "x$HAVE_MIXER" = x1]) + LIBS="$SDL2_MIXER_LIBS $LIBS" CFLAGS="$SDL2_MIXER_CFLAGS $CFLAGS" diff --git a/src/Makefile.am b/src/Makefile.am index aff4573..6d5fc80 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,2 +1,2 @@ noinst_LIBRARIES = libplay.a -libplay_a_SOURCES = play.c play.h +libplay_a_SOURCES = macros.h play.c play.h @@ -29,9 +29,11 @@ /* libplay: SDL2 and SDL2_Mixer glued together a bit */ typedef struct play_t { +#ifdef WITH_AUDIO Mix_Music *music; char *music_file, *queued_music_file; unsigned music_flags, queued_music_flags; +#endif Uint32 tick_offsets[PLAY_TICKS_CNT]; Uint32 ticks_paused_at; unsigned ticks_paused:1; @@ -46,6 +48,7 @@ typedef struct play_t { void play_music_set(play_t *play, unsigned flags, const char *fmt, ...) { +#ifdef WITH_AUDIO int fade = (flags & PLAY_MUSIC_FLAG_FADEIN); int optional = (flags & PLAY_MUSIC_FLAG_OPTIONAL); int queue = (flags & PLAY_MUSIC_FLAG_QUEUE); @@ -53,10 +56,12 @@ void play_music_set(play_t *play, unsigned flags, const char *fmt, ...) char file[256] = {}; Mix_Music *new; va_list ap; +#endif assert(play); assert(play->has_audio); +#ifdef WITH_AUDIO va_start(ap, fmt); vsnprintf(file, sizeof(file), fmt, ap); va_end(ap); @@ -141,6 +146,7 @@ static void music_finished(void) if (!Mix_PlayingMusic() && (play->music_flags & PLAY_MUSIC_FLAG_LOOP)) fatal_if(Mix_PlayMusic(play->music, 0), "Unable to loop music"); +#endif } @@ -149,7 +155,9 @@ void play_music_pause(play_t *play) assert(play); assert(play->has_audio); +#ifdef WITH_AUDIO Mix_PauseMusic(); +#endif } @@ -158,7 +166,9 @@ void play_music_resume(play_t *play) assert(play); assert(play->has_audio); +#ifdef WITH_AUDIO Mix_ResumeMusic(); +#endif } @@ -308,6 +318,9 @@ play_t * play_startup(int argc, char *argv[], unsigned flags, const play_ops_t * * they don't want. */ if (!(flags & PLAY_FLAG_NOAUDIO)) { +#ifndef WITH_AUDIO + fatal_if(1, "libplay built without audio support, audio/music API unavailable"); +#endif sdl_flags |= SDL_INIT_AUDIO; play->has_audio = 1; } @@ -324,6 +337,7 @@ play_t * play_startup(int argc, char *argv[], unsigned flags, const play_ops_t * fatal_if(atexit(SDL_Quit), "Unable to set exit handler"); +#ifdef WITH_AUDIO if (play->has_audio) { fatal_if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) == -1, "Unable to open audio"); @@ -332,6 +346,7 @@ play_t * play_startup(int argc, char *argv[], unsigned flags, const play_ops_t * Mix_HookMusicFinished(music_finished); Mix_AllocateChannels(32); } +#endif if (!(flags & PLAY_FLAG_NOGAMEPAD)) { /* Just in case the user has dropped a game controller mapping */ |