Add 'libosxutil' which gives us functions to locate paths within bundles, for

now this is used by libass to load fontconfig's fonts.conf.

Originally committed to SVN as r2585.
This commit is contained in:
Amar Takhar 2008-12-31 09:20:50 +00:00
parent b262b3016b
commit 1fd3ffc313
5 changed files with 122 additions and 3 deletions

View file

@ -2,14 +2,20 @@ AUTOMAKE_OPTIONS = foreign
SUFFIXES = .c .cpp .rc
noinst_LIBRARIES=
SUBDIRS = bitmaps posix
if BUILD_DARWIN
libosxutil_subdir = libosxutil
libosxutil_lib = libosxutil/libosxutil.a
libosxutil_ldflags = -framwork CoreFoundation
endif
SUBDIRS = bitmaps posix $(libosxutil_subdir)
AM_CXXFLAGS = -DAEGISUB -Iposix -include posix/defines.h -Iinclude @WX_CPPFLAGS@ @OPENMP_CXXFLAGS@
bin_PROGRAMS = aegisub
aegisub_LDADD = posix/libposix.a
aegisub_LDADD = posix/libposix.a $(libosxutil_lib)
aegisub_CPPFLAGS = @FREETYPE_CFLAGS@
aegisub_LDFLAGS = @GL_LIBS@ @PTHREAD_LIBS@ @WX_LIBS@ @ICONV_LDFLAGS@
aegisub_LDFLAGS = @GL_LIBS@ @PTHREAD_LIBS@ @WX_LIBS@ @ICONV_LDFLAGS@ $(libosxutil_ldflags)
LIBS += @FREETYPE_LIBS@ @FONTCONFIG_LIBS@
if BUILD_DARWIN

View file

@ -0,0 +1,7 @@
noinst_LIBRARIES = libosxutil.a
libosxutil_a_SOURCES = bundledirs.c
noinst_HEADERS = libosxutil.h
EXTRA_DIST= callables.c

View file

@ -0,0 +1,96 @@
#include <string.h>
#include <sys/param.h>
#include <CoreFoundation/CFBundle.h>
#include <CoreFoundation/CFURL.h>
#include <CoreFoundation/CFString.h>
#include "libosxutil.h"
typedef CFURLRef (*GetURLFunc)(CFBundleRef);
static char * GetDir(GetURLFunc GetURL)
{
CFBundleRef bundle;
CFURLRef res_dir_url;
char res_dir_str[MAXPATHLEN];
Boolean res;
bundle = CFBundleGetMainBundle();
if (!bundle) return NULL;
res_dir_url = (*GetURL)(bundle);
// we do not own 'bundle' so don't release it
if (!res_dir_url) return NULL;
res = CFURLGetFileSystemRepresentation(res_dir_url, true, (UInt8*)res_dir_str, MAXPATHLEN);
CFRelease(res_dir_url);
if (res == false)
return NULL;
else
return strdup(res_dir_str);
}
char * OSX_GetBundleResourcesDirectory()
{
return GetDir(CFBundleCopyResourcesDirectoryURL);
}
char * OSX_GetBundleExecutablePath()
{
return GetDir(CFBundleCopyExecutableURL);
}
char * OSX_GetBundleBuiltInPlugInsDirectory()
{
return GetDir(CFBundleCopyBuiltInPlugInsURL);
}
char * OSX_GetBundlePrivateFrameworksDirectory()
{
return GetDir(CFBundleCopyPrivateFrameworksURL);
}
char * OSX_GetSharedFrameworksDirectory()
{
return GetDir(CFBundleCopySharedFrameworksURL);
}
char * OSX_GetSharedSupportDirectory()
{
return GetDir(CFBundleCopySharedSupportURL);
}
char * OSX_GetSupportFilesDirectory()
{
return GetDir(CFBundleCopySupportFilesDirectoryURL);
}
char * OSX_GetAuxillaryExecutablePath(const char *executableName)
{
CFStringRef exename_str;
CFBundleRef bundle;
CFURLRef res_dir_url;
char res_dir_str[MAXPATHLEN];
Boolean res;
exename_str = CFStringCreateWithCString(NULL, executableName, kCFStringEncodingUTF8);
if (!exename_str) return NULL;
bundle = CFBundleGetMainBundle();
if (!bundle) return NULL;
res_dir_url = CFBundleCopyAuxiliaryExecutableURL(bundle, exename_str);
CFRelease(exename_str);
if (!res_dir_url) return NULL;
res = CFURLGetFileSystemRepresentation(res_dir_url, true, (UInt8*)res_dir_str, MAXPATHLEN);
CFRelease(res_dir_url);
if (res == false)
return NULL;
else
return strdup(res_dir_str);
}

View file

@ -0,0 +1,9 @@
char * OSX_GetBundleResourcesDirectory();
char * OSX_GetBundleBuiltInPlugInsDirectory();
char * OSX_GetBundlePrivateFrameworksDirectory();
char * OSX_GetSharedFrameworksDirectory();
char * OSX_GetSharedSupportDirectory();
char * OSX_GetSupportFilesDirectory();
char * OSX_GetBundleExecutablePath();
char * OSX_GetAuxillaryExecutablePath(const char *executableName);

View file

@ -925,6 +925,7 @@ Makefile
aegisub/Makefile
aegisub/bitmaps/Makefile
aegisub/posix/Makefile
aegisub/libosxutil/Makefile
universalchardet/Makefile
FFmpegSource2/Makefile
auto3/Makefile