From 1fd3ffc31392681382f8e0cb0b038cd46a19a9e2 Mon Sep 17 00:00:00 2001 From: Amar Takhar Date: Wed, 31 Dec 2008 09:20:50 +0000 Subject: [PATCH] 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. --- aegisub/Makefile.am | 12 +++-- aegisub/libosxutil/Makefile.am | 7 +++ aegisub/libosxutil/bundledirs.c | 96 +++++++++++++++++++++++++++++++++ aegisub/libosxutil/libosxutil.h | 9 ++++ configure.in | 1 + 5 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 aegisub/libosxutil/Makefile.am create mode 100644 aegisub/libosxutil/bundledirs.c create mode 100644 aegisub/libosxutil/libosxutil.h diff --git a/aegisub/Makefile.am b/aegisub/Makefile.am index f32b7b5af..2b1d9d8c1 100644 --- a/aegisub/Makefile.am +++ b/aegisub/Makefile.am @@ -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 diff --git a/aegisub/libosxutil/Makefile.am b/aegisub/libosxutil/Makefile.am new file mode 100644 index 000000000..a17e8a633 --- /dev/null +++ b/aegisub/libosxutil/Makefile.am @@ -0,0 +1,7 @@ +noinst_LIBRARIES = libosxutil.a + +libosxutil_a_SOURCES = bundledirs.c + +noinst_HEADERS = libosxutil.h + +EXTRA_DIST= callables.c diff --git a/aegisub/libosxutil/bundledirs.c b/aegisub/libosxutil/bundledirs.c new file mode 100644 index 000000000..73f7e5674 --- /dev/null +++ b/aegisub/libosxutil/bundledirs.c @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include + +#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); +} + diff --git a/aegisub/libosxutil/libosxutil.h b/aegisub/libosxutil/libosxutil.h new file mode 100644 index 000000000..4a482e4e3 --- /dev/null +++ b/aegisub/libosxutil/libosxutil.h @@ -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); diff --git a/configure.in b/configure.in index eb4ccc111..2b4ead1a4 100644 --- a/configure.in +++ b/configure.in @@ -925,6 +925,7 @@ Makefile aegisub/Makefile aegisub/bitmaps/Makefile aegisub/posix/Makefile +aegisub/libosxutil/Makefile universalchardet/Makefile FFmpegSource2/Makefile auto3/Makefile