Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slouken committed Jun 2, 2013
1 parent 4884155 commit d085222
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 27 deletions.
50 changes: 28 additions & 22 deletions Xcode/SDL_mixer.xcodeproj/project.pbxproj
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
00938E1C108A36520009CF19 /* mikmod.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00938E1B108A36520009CF19 /* mikmod.framework */; };
00938E33108A37800009CF19 /* load_flac.c in Sources */ = {isa = PBXBuildFile; fileRef = 00938E2B108A37800009CF19 /* load_flac.c */; };
00938E34108A37800009CF19 /* load_flac.h in Headers */ = {isa = PBXBuildFile; fileRef = 00938E2C108A37800009CF19 /* load_flac.h */; };
00938E35108A37800009CF19 /* music_flac.c in Sources */ = {isa = PBXBuildFile; fileRef = 00938E2D108A37800009CF19 /* music_flac.c */; };
Expand All @@ -32,11 +31,10 @@
04A8FCA70A19CAEC0046373F /* dynamic_mp3.c in Sources */ = {isa = PBXBuildFile; fileRef = 04A8FCA40A19CAEC0046373F /* dynamic_mp3.c */; };
04A8FCAB0A19CB070046373F /* dynamic_ogg.c in Sources */ = {isa = PBXBuildFile; fileRef = 04A8FCA90A19CB070046373F /* dynamic_ogg.c */; };
04A8FCAC0A19CB070046373F /* dynamic_ogg.c in Sources */ = {isa = PBXBuildFile; fileRef = 04A8FCA90A19CB070046373F /* dynamic_ogg.c */; };
AA64428F175AA7A500A2125A /* smpeg2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA64428E175AA7A500A2125A /* smpeg2.framework */; };
AA644290175AA7C900A2125A /* smpeg2.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = AA64428E175AA7A500A2125A /* smpeg2.framework */; };
AA9F7DB514B15ADC00278D1E /* Ogg.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA9F7DB314B15ADC00278D1E /* Ogg.framework */; };
AA9F7DB614B15ADC00278D1E /* Vorbis.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA9F7DB414B15ADC00278D1E /* Vorbis.framework */; };
AA9F7DB814B15AE700278D1E /* FLAC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA9F7DB714B15AE700278D1E /* FLAC.framework */; };
AA6442D1175B181300A2125A /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA6442D0175B181300A2125A /* AudioToolbox.framework */; };
AA6442D3175B181D00A2125A /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA6442D2175B181D00A2125A /* AudioUnit.framework */; };
AA6442D5175B185800A2125A /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA6442D4175B185800A2125A /* CoreServices.framework */; };
AA9F7DB914B15D3300278D1E /* FLAC.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = AA9F7DB714B15AE700278D1E /* FLAC.framework */; };
AA9F7DBA14B15D4100278D1E /* mikmod.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 00938E1B108A36520009CF19 /* mikmod.framework */; };
AA9F7DBB14B15D4400278D1E /* Ogg.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = AA9F7DB314B15ADC00278D1E /* Ogg.framework */; };
Expand Down Expand Up @@ -212,6 +210,9 @@
5CC1B89B012FB8CD7F000001 /* wavestream.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = wavestream.c; path = ../wavestream.c; sourceTree = "<group>"; };
5CC1B89C012FB8CD7F000001 /* wavestream.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = wavestream.h; path = ../wavestream.h; sourceTree = "<group>"; };
AA64428E175AA7A500A2125A /* smpeg2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = smpeg2.framework; path = Frameworks/smpeg2.framework; sourceTree = "<group>"; };
AA6442D0175B181300A2125A /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
AA6442D2175B181D00A2125A /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; };
AA6442D4175B185800A2125A /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
AA9F7DB314B15ADC00278D1E /* Ogg.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Ogg.framework; path = Frameworks/Ogg.framework; sourceTree = "<group>"; };
AA9F7DB414B15ADC00278D1E /* Vorbis.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Vorbis.framework; path = Frameworks/Vorbis.framework; sourceTree = "<group>"; };
AA9F7DB714B15AE700278D1E /* FLAC.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FLAC.framework; path = Frameworks/FLAC.framework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -241,12 +242,10 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
AA6442D3175B181D00A2125A /* AudioUnit.framework in Frameworks */,
AA6442D1175B181300A2125A /* AudioToolbox.framework in Frameworks */,
AA6442D5175B185800A2125A /* CoreServices.framework in Frameworks */,
BE1FA90207AF96B2004B6283 /* SDL2.framework in Frameworks */,
00938E1C108A36520009CF19 /* mikmod.framework in Frameworks */,
AA9F7DB514B15ADC00278D1E /* Ogg.framework in Frameworks */,
AA9F7DB614B15ADC00278D1E /* Vorbis.framework in Frameworks */,
AA9F7DB814B15AE700278D1E /* FLAC.framework in Frameworks */,
AA64428F175AA7A500A2125A /* smpeg2.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -385,6 +384,9 @@
BE1FA8AD07AF95DC004B6283 /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
AA6442D0175B181300A2125A /* AudioToolbox.framework */,
AA6442D2175B181D00A2125A /* AudioUnit.framework */,
AA6442D4175B185800A2125A /* CoreServices.framework */,
AA9F7DB714B15AE700278D1E /* FLAC.framework */,
00938E1B108A36520009CF19 /* mikmod.framework */,
AA9F7DB314B15ADC00278D1E /* Ogg.framework */,
Expand Down Expand Up @@ -747,12 +749,14 @@
INSTALL_PATH = "@executable_path/../Frameworks";
LD_RUNPATH_SEARCH_PATHS = "@loader_path/Frameworks";
OTHER_LDFLAGS = (
"-framework",
AudioToolbox,
"-framework",
AudioUnit,
"-framework",
CoreServices,
"-weak_framework",
FLAC,
"-weak_framework",
mikmod,
"-weak_framework",
smpeg2,
"-weak_framework",
Vorbis,
);
WRAPPER_EXTENSION = framework;
};
Expand All @@ -771,12 +775,14 @@
INSTALL_PATH = "@executable_path/../Frameworks";
LD_RUNPATH_SEARCH_PATHS = "@loader_path/Frameworks";
OTHER_LDFLAGS = (
"-framework",
AudioToolbox,
"-framework",
AudioUnit,
"-framework",
CoreServices,
"-weak_framework",
FLAC,
"-weak_framework",
mikmod,
"-weak_framework",
smpeg2,
"-weak_framework",
Vorbis,
);
WRAPPER_EXTENSION = framework;
};
Expand Down
12 changes: 11 additions & 1 deletion dynamic_flac.c
Expand Up @@ -25,7 +25,7 @@
#ifdef FLAC_MUSIC

#include "SDL_loadso.h"

#include "SDL_mixer.h"
#include "dynamic_flac.h"

flac_loader flac = {
Expand Down Expand Up @@ -142,6 +142,16 @@ void Mix_QuitFLAC()
int Mix_InitFLAC()
{
if ( flac.loaded == 0 ) {
#ifdef __MACOSX__
extern FLAC__StreamDecoder *FLAC__stream_decoder_new(void) __attribute__((weak_import));
if ( FLAC__stream_decoder_new == NULL )
{
/* Missing weakly linked framework */
Mix_SetError("Missing FLAC.framework");
return -1;
}
#endif // __MACOSX__

flac.FLAC__stream_decoder_new = FLAC__stream_decoder_new;
flac.FLAC__stream_decoder_delete = FLAC__stream_decoder_delete;
flac.FLAC__stream_decoder_init_stream =
Expand Down
12 changes: 11 additions & 1 deletion dynamic_mod.c
Expand Up @@ -22,7 +22,7 @@
#ifdef MOD_MUSIC

#include "SDL_loadso.h"

#include "SDL_mixer.h"
#include "dynamic_mod.h"

mikmod_loader mikmod = {
Expand Down Expand Up @@ -238,6 +238,16 @@ void Mix_QuitMOD()
int Mix_InitMOD()
{
if ( mikmod.loaded == 0 ) {
#ifdef __MACOSX__
extern void Player_Start(MODULE*) __attribute__((weak_import));
if ( Player_Start == NULL )
{
/* Missing weakly linked framework */
Mix_SetError("Missing mikmod.framework");
return -1;
}
#endif // __MACOSX__

mikmod.MikMod_Exit = MikMod_Exit;
mikmod.MikMod_InfoDriver = MikMod_InfoDriver;
mikmod.MikMod_InfoLoader = MikMod_InfoLoader;
Expand Down
12 changes: 11 additions & 1 deletion dynamic_mp3.c
Expand Up @@ -22,7 +22,7 @@
#ifdef MP3_MUSIC

#include "SDL_loadso.h"

#include "SDL_mixer.h"
#include "dynamic_mp3.h"

smpeg_loader smpeg = {
Expand Down Expand Up @@ -140,6 +140,16 @@ void Mix_QuitMP3()
int Mix_InitMP3()
{
if ( smpeg.loaded == 0 ) {
#ifdef __MACOSX__
extern SMPEG* SMPEG_new_rwops(SDL_RWops*, SMPEG_Info*, int, int) __attribute__((weak_import));
if ( SMPEG_new_rwops == NULL )
{
/* Missing weakly linked framework */
Mix_SetError("Missing smpeg2.framework");
return -1;
}
#endif // __MACOSX__

smpeg.SMPEG_actualSpec = SMPEG_actualSpec;
smpeg.SMPEG_delete = SMPEG_delete;
smpeg.SMPEG_enableaudio = SMPEG_enableaudio;
Expand Down
12 changes: 11 additions & 1 deletion dynamic_ogg.c
Expand Up @@ -22,7 +22,7 @@
#ifdef OGG_MUSIC

#include "SDL_loadso.h"

#include "SDL_mixer.h"
#include "dynamic_ogg.h"

vorbis_loader vorbis = {
Expand Down Expand Up @@ -106,6 +106,16 @@ void Mix_QuitOgg()
int Mix_InitOgg()
{
if ( vorbis.loaded == 0 ) {
#ifdef __MACOSX__
extern int ov_open_callbacks(void*, OggVorbis_File*, const char*, long, ov_callbacks) __attribute__((weak_import));
if ( ov_open_callbacks == NULL )
{
/* Missing weakly linked framework */
Mix_SetError("Missing Vorbis.framework");
return -1;
}
#endif // __MACOSX__

vorbis.ov_clear = ov_clear;
vorbis.ov_info = ov_info;
vorbis.ov_open_callbacks = ov_open_callbacks;
Expand Down
2 changes: 1 addition & 1 deletion music.c
Expand Up @@ -575,7 +575,7 @@ Mix_Music *Mix_LoadMUS(const char *file)
Mix_SetError("");
music = Mix_LoadMUSType_RW(src, type, SDL_TRUE);
if ( music == NULL && Mix_GetError()[0] == '\0' ) {
Mix_SetError("Couldn't open '%s'", file);
Mix_SetError("Unrecognized music format");
}
return music;
}
Expand Down

0 comments on commit d085222

Please sign in to comment.