Switched Mac OS X framework to use weak linking on external libraries.
authorSam Lantinga <slouken@libsdl.org>
Sun, 02 Jun 2013 00:35:46 -0700
changeset 62987c536d57d92
parent 628 461e2724372b
child 630 39fbc5a85070
Switched Mac OS X framework to use weak linking on external libraries.
This allows someone to just remove the smpeg2.framework if they don't want MP3 support, for example.
The weak import attribute is necessary to prevent the optimizer from eliminating the symbol NULL check.
Xcode/SDL_mixer.xcodeproj/project.pbxproj
dynamic_flac.c
dynamic_mod.c
dynamic_mp3.c
dynamic_ogg.c
music.c
     1.1 --- a/Xcode/SDL_mixer.xcodeproj/project.pbxproj	Sat Jun 01 23:42:48 2013 -0700
     1.2 +++ b/Xcode/SDL_mixer.xcodeproj/project.pbxproj	Sun Jun 02 00:35:46 2013 -0700
     1.3 @@ -7,7 +7,6 @@
     1.4  	objects = {
     1.5  
     1.6  /* Begin PBXBuildFile section */
     1.7 -		00938E1C108A36520009CF19 /* mikmod.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00938E1B108A36520009CF19 /* mikmod.framework */; };
     1.8  		00938E33108A37800009CF19 /* load_flac.c in Sources */ = {isa = PBXBuildFile; fileRef = 00938E2B108A37800009CF19 /* load_flac.c */; };
     1.9  		00938E34108A37800009CF19 /* load_flac.h in Headers */ = {isa = PBXBuildFile; fileRef = 00938E2C108A37800009CF19 /* load_flac.h */; };
    1.10  		00938E35108A37800009CF19 /* music_flac.c in Sources */ = {isa = PBXBuildFile; fileRef = 00938E2D108A37800009CF19 /* music_flac.c */; };
    1.11 @@ -32,11 +31,10 @@
    1.12  		04A8FCA70A19CAEC0046373F /* dynamic_mp3.c in Sources */ = {isa = PBXBuildFile; fileRef = 04A8FCA40A19CAEC0046373F /* dynamic_mp3.c */; };
    1.13  		04A8FCAB0A19CB070046373F /* dynamic_ogg.c in Sources */ = {isa = PBXBuildFile; fileRef = 04A8FCA90A19CB070046373F /* dynamic_ogg.c */; };
    1.14  		04A8FCAC0A19CB070046373F /* dynamic_ogg.c in Sources */ = {isa = PBXBuildFile; fileRef = 04A8FCA90A19CB070046373F /* dynamic_ogg.c */; };
    1.15 -		AA64428F175AA7A500A2125A /* smpeg2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA64428E175AA7A500A2125A /* smpeg2.framework */; };
    1.16  		AA644290175AA7C900A2125A /* smpeg2.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = AA64428E175AA7A500A2125A /* smpeg2.framework */; };
    1.17 -		AA9F7DB514B15ADC00278D1E /* Ogg.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA9F7DB314B15ADC00278D1E /* Ogg.framework */; };
    1.18 -		AA9F7DB614B15ADC00278D1E /* Vorbis.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA9F7DB414B15ADC00278D1E /* Vorbis.framework */; };
    1.19 -		AA9F7DB814B15AE700278D1E /* FLAC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA9F7DB714B15AE700278D1E /* FLAC.framework */; };
    1.20 +		AA6442D1175B181300A2125A /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA6442D0175B181300A2125A /* AudioToolbox.framework */; };
    1.21 +		AA6442D3175B181D00A2125A /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA6442D2175B181D00A2125A /* AudioUnit.framework */; };
    1.22 +		AA6442D5175B185800A2125A /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA6442D4175B185800A2125A /* CoreServices.framework */; };
    1.23  		AA9F7DB914B15D3300278D1E /* FLAC.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = AA9F7DB714B15AE700278D1E /* FLAC.framework */; };
    1.24  		AA9F7DBA14B15D4100278D1E /* mikmod.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 00938E1B108A36520009CF19 /* mikmod.framework */; };
    1.25  		AA9F7DBB14B15D4400278D1E /* Ogg.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = AA9F7DB314B15ADC00278D1E /* Ogg.framework */; };
    1.26 @@ -212,6 +210,9 @@
    1.27  		5CC1B89B012FB8CD7F000001 /* wavestream.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = wavestream.c; path = ../wavestream.c; sourceTree = "<group>"; };
    1.28  		5CC1B89C012FB8CD7F000001 /* wavestream.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = wavestream.h; path = ../wavestream.h; sourceTree = "<group>"; };
    1.29  		AA64428E175AA7A500A2125A /* smpeg2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = smpeg2.framework; path = Frameworks/smpeg2.framework; sourceTree = "<group>"; };
    1.30 +		AA6442D0175B181300A2125A /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
    1.31 +		AA6442D2175B181D00A2125A /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; };
    1.32 +		AA6442D4175B185800A2125A /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
    1.33  		AA9F7DB314B15ADC00278D1E /* Ogg.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Ogg.framework; path = Frameworks/Ogg.framework; sourceTree = "<group>"; };
    1.34  		AA9F7DB414B15ADC00278D1E /* Vorbis.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Vorbis.framework; path = Frameworks/Vorbis.framework; sourceTree = "<group>"; };
    1.35  		AA9F7DB714B15AE700278D1E /* FLAC.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FLAC.framework; path = Frameworks/FLAC.framework; sourceTree = "<group>"; };
    1.36 @@ -241,12 +242,10 @@
    1.37  			isa = PBXFrameworksBuildPhase;
    1.38  			buildActionMask = 2147483647;
    1.39  			files = (
    1.40 +				AA6442D3175B181D00A2125A /* AudioUnit.framework in Frameworks */,
    1.41 +				AA6442D1175B181300A2125A /* AudioToolbox.framework in Frameworks */,
    1.42 +				AA6442D5175B185800A2125A /* CoreServices.framework in Frameworks */,
    1.43  				BE1FA90207AF96B2004B6283 /* SDL2.framework in Frameworks */,
    1.44 -				00938E1C108A36520009CF19 /* mikmod.framework in Frameworks */,
    1.45 -				AA9F7DB514B15ADC00278D1E /* Ogg.framework in Frameworks */,
    1.46 -				AA9F7DB614B15ADC00278D1E /* Vorbis.framework in Frameworks */,
    1.47 -				AA9F7DB814B15AE700278D1E /* FLAC.framework in Frameworks */,
    1.48 -				AA64428F175AA7A500A2125A /* smpeg2.framework in Frameworks */,
    1.49  			);
    1.50  			runOnlyForDeploymentPostprocessing = 0;
    1.51  		};
    1.52 @@ -385,6 +384,9 @@
    1.53  		BE1FA8AD07AF95DC004B6283 /* Linked Frameworks */ = {
    1.54  			isa = PBXGroup;
    1.55  			children = (
    1.56 +				AA6442D0175B181300A2125A /* AudioToolbox.framework */,
    1.57 +				AA6442D2175B181D00A2125A /* AudioUnit.framework */,
    1.58 +				AA6442D4175B185800A2125A /* CoreServices.framework */,
    1.59  				AA9F7DB714B15AE700278D1E /* FLAC.framework */,
    1.60  				00938E1B108A36520009CF19 /* mikmod.framework */,
    1.61  				AA9F7DB314B15ADC00278D1E /* Ogg.framework */,
    1.62 @@ -747,12 +749,14 @@
    1.63  				INSTALL_PATH = "@executable_path/../Frameworks";
    1.64  				LD_RUNPATH_SEARCH_PATHS = "@loader_path/Frameworks";
    1.65  				OTHER_LDFLAGS = (
    1.66 -					"-framework",
    1.67 -					AudioToolbox,
    1.68 -					"-framework",
    1.69 -					AudioUnit,
    1.70 -					"-framework",
    1.71 -					CoreServices,
    1.72 +					"-weak_framework",
    1.73 +					FLAC,
    1.74 +					"-weak_framework",
    1.75 +					mikmod,
    1.76 +					"-weak_framework",
    1.77 +					smpeg2,
    1.78 +					"-weak_framework",
    1.79 +					Vorbis,
    1.80  				);
    1.81  				WRAPPER_EXTENSION = framework;
    1.82  			};
    1.83 @@ -771,12 +775,14 @@
    1.84  				INSTALL_PATH = "@executable_path/../Frameworks";
    1.85  				LD_RUNPATH_SEARCH_PATHS = "@loader_path/Frameworks";
    1.86  				OTHER_LDFLAGS = (
    1.87 -					"-framework",
    1.88 -					AudioToolbox,
    1.89 -					"-framework",
    1.90 -					AudioUnit,
    1.91 -					"-framework",
    1.92 -					CoreServices,
    1.93 +					"-weak_framework",
    1.94 +					FLAC,
    1.95 +					"-weak_framework",
    1.96 +					mikmod,
    1.97 +					"-weak_framework",
    1.98 +					smpeg2,
    1.99 +					"-weak_framework",
   1.100 +					Vorbis,
   1.101  				);
   1.102  				WRAPPER_EXTENSION = framework;
   1.103  			};
     2.1 --- a/dynamic_flac.c	Sat Jun 01 23:42:48 2013 -0700
     2.2 +++ b/dynamic_flac.c	Sun Jun 02 00:35:46 2013 -0700
     2.3 @@ -25,7 +25,7 @@
     2.4  #ifdef FLAC_MUSIC
     2.5  
     2.6  #include "SDL_loadso.h"
     2.7 -
     2.8 +#include "SDL_mixer.h"
     2.9  #include "dynamic_flac.h"
    2.10  
    2.11  flac_loader flac = {
    2.12 @@ -142,6 +142,16 @@
    2.13  int Mix_InitFLAC()
    2.14  {
    2.15      if ( flac.loaded == 0 ) {
    2.16 +#ifdef __MACOSX__
    2.17 +        extern FLAC__StreamDecoder *FLAC__stream_decoder_new(void) __attribute__((weak_import));
    2.18 +        if ( FLAC__stream_decoder_new == NULL )
    2.19 +        {
    2.20 +            /* Missing weakly linked framework */
    2.21 +            Mix_SetError("Missing FLAC.framework");
    2.22 +            return -1;
    2.23 +        }
    2.24 +#endif // __MACOSX__
    2.25 +
    2.26          flac.FLAC__stream_decoder_new = FLAC__stream_decoder_new;
    2.27          flac.FLAC__stream_decoder_delete = FLAC__stream_decoder_delete;
    2.28          flac.FLAC__stream_decoder_init_stream =
     3.1 --- a/dynamic_mod.c	Sat Jun 01 23:42:48 2013 -0700
     3.2 +++ b/dynamic_mod.c	Sun Jun 02 00:35:46 2013 -0700
     3.3 @@ -22,7 +22,7 @@
     3.4  #ifdef MOD_MUSIC
     3.5  
     3.6  #include "SDL_loadso.h"
     3.7 -
     3.8 +#include "SDL_mixer.h"
     3.9  #include "dynamic_mod.h"
    3.10  
    3.11  mikmod_loader mikmod = {
    3.12 @@ -238,6 +238,16 @@
    3.13  int Mix_InitMOD()
    3.14  {
    3.15      if ( mikmod.loaded == 0 ) {
    3.16 +#ifdef __MACOSX__
    3.17 +        extern void Player_Start(MODULE*) __attribute__((weak_import));
    3.18 +        if ( Player_Start == NULL )
    3.19 +        {
    3.20 +            /* Missing weakly linked framework */
    3.21 +            Mix_SetError("Missing mikmod.framework");
    3.22 +            return -1;
    3.23 +        }
    3.24 +#endif // __MACOSX__
    3.25 +
    3.26          mikmod.MikMod_Exit = MikMod_Exit;
    3.27          mikmod.MikMod_InfoDriver = MikMod_InfoDriver;
    3.28          mikmod.MikMod_InfoLoader = MikMod_InfoLoader;
     4.1 --- a/dynamic_mp3.c	Sat Jun 01 23:42:48 2013 -0700
     4.2 +++ b/dynamic_mp3.c	Sun Jun 02 00:35:46 2013 -0700
     4.3 @@ -22,7 +22,7 @@
     4.4  #ifdef MP3_MUSIC
     4.5  
     4.6  #include "SDL_loadso.h"
     4.7 -
     4.8 +#include "SDL_mixer.h"
     4.9  #include "dynamic_mp3.h"
    4.10  
    4.11  smpeg_loader smpeg = {
    4.12 @@ -140,6 +140,16 @@
    4.13  int Mix_InitMP3()
    4.14  {
    4.15      if ( smpeg.loaded == 0 ) {
    4.16 +#ifdef __MACOSX__
    4.17 +        extern SMPEG* SMPEG_new_rwops(SDL_RWops*, SMPEG_Info*, int, int) __attribute__((weak_import));
    4.18 +        if ( SMPEG_new_rwops == NULL )
    4.19 +        {
    4.20 +            /* Missing weakly linked framework */
    4.21 +            Mix_SetError("Missing smpeg2.framework");
    4.22 +            return -1;
    4.23 +        }
    4.24 +#endif // __MACOSX__
    4.25 +
    4.26          smpeg.SMPEG_actualSpec = SMPEG_actualSpec;
    4.27          smpeg.SMPEG_delete = SMPEG_delete;
    4.28          smpeg.SMPEG_enableaudio = SMPEG_enableaudio;
     5.1 --- a/dynamic_ogg.c	Sat Jun 01 23:42:48 2013 -0700
     5.2 +++ b/dynamic_ogg.c	Sun Jun 02 00:35:46 2013 -0700
     5.3 @@ -22,7 +22,7 @@
     5.4  #ifdef OGG_MUSIC
     5.5  
     5.6  #include "SDL_loadso.h"
     5.7 -
     5.8 +#include "SDL_mixer.h"
     5.9  #include "dynamic_ogg.h"
    5.10  
    5.11  vorbis_loader vorbis = {
    5.12 @@ -106,6 +106,16 @@
    5.13  int Mix_InitOgg()
    5.14  {
    5.15      if ( vorbis.loaded == 0 ) {
    5.16 +#ifdef __MACOSX__
    5.17 +        extern int ov_open_callbacks(void*, OggVorbis_File*, const char*, long, ov_callbacks) __attribute__((weak_import));
    5.18 +        if ( ov_open_callbacks == NULL )
    5.19 +        {
    5.20 +            /* Missing weakly linked framework */
    5.21 +            Mix_SetError("Missing Vorbis.framework");
    5.22 +            return -1;
    5.23 +        }
    5.24 +#endif // __MACOSX__
    5.25 +
    5.26          vorbis.ov_clear = ov_clear;
    5.27          vorbis.ov_info = ov_info;
    5.28          vorbis.ov_open_callbacks = ov_open_callbacks;
     6.1 --- a/music.c	Sat Jun 01 23:42:48 2013 -0700
     6.2 +++ b/music.c	Sun Jun 02 00:35:46 2013 -0700
     6.3 @@ -575,7 +575,7 @@
     6.4      Mix_SetError("");
     6.5      music = Mix_LoadMUSType_RW(src, type, SDL_TRUE);
     6.6      if ( music == NULL && Mix_GetError()[0] == '\0' ) {
     6.7 -        Mix_SetError("Couldn't open '%s'", file);
     6.8 +        Mix_SetError("Unrecognized music format");
     6.9      }
    6.10      return music;
    6.11  }