libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 54c20f65214fd93bf41a3ce542b85d8af13644af
parent 75dd2321fb143271e73addf455e9c192feb5eac8
Author: Heikki Lindholm <holin@iki.fi>
Date:   Sun, 28 Dec 2008 15:48:29 +0000

OS X native i18n for the framework build


Diffstat:
Mconfigure.ac | 18++++++++++++++++++
Mcontrib/macosx/build-osx-framework.sh | 78+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
Msrc/Makefile.am | 6+++++-
Msrc/common/Makefile.am | 2+-
Msrc/include/platform.h | 5+++++
Asrc/intlemu/Makefile.am | 8++++++++
Asrc/intlemu/intlemu.c | 136+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/intlemu/libintlemu.h | 18++++++++++++++++++
Msrc/main/Makefile.am | 2+-
Msrc/plugins/Makefile-plugins.am | 2+-
10 files changed, 258 insertions(+), 17 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -516,8 +516,23 @@ AC_ARG_WITH(ffmpeg-arch, [ffmpegarch=$withval]) +LE_INTLINCL="" +LE_LIBINTL="$LTLIBINTL" +AC_ARG_ENABLE(framework, [ --enable-framework enable Mac OS X framework build helpers],enable_framework_build=$enableval) +AM_CONDITIONAL(WANT_FRAMEWORK, test x$enable_framework_build = xyes) +if test x$enable_framework_build = xyes +then + AC_DEFINE([FRAMEWORK_BUILD], 1, [Build a Mac OS X Framework]) + LE_INTLINCL='-I$(top_srcdir)/src/intlemu' + LE_LIBINTL='$(top_builddir)/src/intlemu/libintlemu.la -framework CoreFoundation' + AC_LIB_APPENDTOVAR([CPPFLAGS], [$LE_INTLINCL]) +fi + + LE_LIB_LDFLAGS="-export-dynamic -no-undefined" LE_PLUGIN_LDFLAGS="-export-dynamic -avoid-version -module -no-undefined" + + dnl TODO insert a proper check here AC_CACHE_CHECK([whether -export-symbols-regex works], gn_cv_export_symbols_regex_works, @@ -534,6 +549,8 @@ then fi AC_SUBST(LE_LIB_LDFLAGS) AC_SUBST(LE_PLUGIN_LDFLAGS) +AC_SUBST(LE_INTLINCL) +AC_SUBST(LE_LIBINTL) AC_SUBST(CPPFLAGS) AC_SUBST(LDFLAGS) @@ -547,6 +564,7 @@ contrib/macosx/Info.plist doc/Makefile src/Makefile src/include/Makefile +src/intlemu/Makefile src/common/Makefile src/main/Makefile src/plugins/Makefile diff --git a/contrib/macosx/build-osx-framework.sh b/contrib/macosx/build-osx-framework.sh @@ -313,17 +313,17 @@ build_package() # build_dependencies() { - prepare_package "${GETTEXT_NAME}" - build_package "${GETTEXT_NAME}" \ - "${ARCH_HOSTSETTING} \ - --prefix="${FW_DIR}" \ - --with-pic \ - --disable-shared \ - --enable-static \ - --disable-java \ - --disable-native-java \ - --without-emacs \ - --with-libiconv-prefix=${SDK_PATH}/usr" +# prepare_package "${GETTEXT_NAME}" +# build_package "${GETTEXT_NAME}" \ +# "${ARCH_HOSTSETTING} \ +# --prefix="${FW_DIR}" \ +# --with-pic \ +# --disable-shared \ +# --enable-static \ +# --disable-java \ +# --disable-native-java \ +# --without-emacs \ +# --with-libiconv-prefix=${SDK_PATH}/usr" prepare_package "${LIBOGG_NAME}" build_package "${LIBOGG_NAME}" \ @@ -388,13 +388,14 @@ build_extractor() CFLAGS="${CFLAGS}" \ CXXFLAGS="${CXXFLAGS}" \ LDFLAGS="${LDFLAGS}" \ - gt_cv_func_gnugettext1_libintl=yes \ + xxgt_cv_func_gnugettext1_libintl=yes \ ac_cv_func_memcmp_working=yes \ ac_cv_func_mmap_fixed_mapped=yes \ ac_cv_func_stat_empty_string_bug=no \ ./configure "${ARCH_HOSTSETTING}" \ --prefix="${FW_DIR}" \ --enable-shared \ + --enable-framework \ --disable-gsf \ --disable-gnome \ --enable-ffmpeg \ @@ -559,6 +560,52 @@ install_file_to_framework() done } +install_message_catalog_to_framework() +{ + local src_file="$1" + local lang_name=$( basename -s .po $src_file ) + local dst_file="${FINAL_FW_DIR}/Resources/${lang_name}.lproj/Localizable.strings" + if [ ! -e "$dst_file" ] + then + echo "MSGCAT $src_file $dst_file" + create_directory_for "$dst_file" + if ! ( msgcat -t UTF-8 --stringtable-output -o "$dst_file" "$src_file" ) + then + echo "error creating message catalog: $lang" + exit 1 + fi + if ! ( chmod 0755 "${dst_file}" ) + then + echo "error setting permissions" + exit 1 + fi + plutil -lint "$dst_file" + fi +} + +install_en_message_catalog_to_framework() +{ + local src_file="$1" + local lang_name="en" + local dst_file="${FINAL_FW_DIR}/Resources/${lang_name}.lproj/Localizable.strings" + if [ ! -e "$dst_file" ] + then + echo "MSGCAT $src_file $dst_file" + create_directory_for "$dst_file" + if ! ( msgcat -t UTF-8 "$src_file" | msgen --stringtable-output -o "$dst_file" - ) + then + echo "error creating English message catalog" + exit 1 + fi + if ! ( chmod 0755 "${dst_file}" ) + then + echo "error setting permissions" + exit 1 + fi + plutil -lint "$dst_file" + fi +} + copy_file_to_framework() { local src_file="$1" @@ -691,7 +738,12 @@ done cd "${ORIG_DIR}" copy_file_to_framework "./contrib/macosx/Info.plist" "Resources/Info.plist" fill_framework_revision "Resources/Info.plist" -copy_file_to_framework "./contrib/macosx/English.lproj/InfoPlist.strings" "Resources/English.lproj/InfoPlist.strings" +for tfn in ./po/*.po +do + install_message_catalog_to_framework "$tfn" +done +install_en_message_catalog_to_framework "./po/libextractor.pot" +#copy_file_to_framework "./contrib/macosx/English.lproj/InfoPlist.strings" "Resources/English.lproj/InfoPlist.strings" make_framework_link "lib/libextractor.dylib" "Extractor" make_framework_link "lib" "Libraries" make_framework_link "lib/libextractor" "PlugIns" diff --git a/src/Makefile.am b/src/Makefile.am @@ -1,3 +1,7 @@ +if WANT_FRAMEWORK + INTLEMU_SUBDIRS = intlemu +endif + INCLUDES = -I$(top_srcdir)/src/include -SUBDIRS = include main common plugins test . +SUBDIRS = include $(INTLEMU_SUBDIRS) main common plugins test . diff --git a/src/common/Makefile.am b/src/common/Makefile.am @@ -1,7 +1,7 @@ INCLUDES = -I$(top_srcdir)/src/include $(LTDLINCL) LIBS = \ - @LTLIBINTL@ @LIBS@ + @LE_LIBINTL@ @LIBS@ lib_LTLIBRARIES = \ libextractor_common.la diff --git a/src/include/platform.h b/src/include/platform.h @@ -29,8 +29,13 @@ #define PLATFORM_H #include "config.h" +#ifndef FRAMEWORK_BUILD #include "gettext.h" #define _(a) dgettext(PACKAGE, a) +#else +#include "libintlemu.h" +#define _(a) dgettext("org.gnunet.libextractor", a) +#endif #include "plibc.h" diff --git a/src/intlemu/Makefile.am b/src/intlemu/Makefile.am @@ -0,0 +1,8 @@ +noinst_LTLIBRARIES = \ + libintlemu.la + +libintlemu_la_SOURCES = \ + libintlemu.h \ + intlemu.c +libintlemu_la_LDFLAGS = \ + -framework CoreFoundation diff --git a/src/intlemu/intlemu.c b/src/intlemu/intlemu.c @@ -0,0 +1,136 @@ +#include <CoreFoundation/CoreFoundation.h> +#include <stdlib.h> +#include <pthread.h> + +static pthread_mutex_t intlemu_lock; +static CFMutableDictionaryRef intlemu_dict; + +static void intlemu_cstring_release(CFAllocatorRef allocator, const void *value) +{ + //printf("intlemu_cstring_release: %p\n", value); + free((void *)value); +} + +void __attribute__ ((constructor)) intlemu_init_() { + //printf("intlemu: init\n"); + CFDictionaryValueCallBacks cstring_value_callbacks = + { + 0, /* version */ + NULL, /* retain callback */ + &intlemu_cstring_release, /* release callback */ + NULL, /* copy description */ + NULL /* equal */ + }; + pthread_mutex_init(&intlemu_lock, NULL); + + intlemu_dict = CFDictionaryCreateMutable( + kCFAllocatorDefault, + 0, + &kCFCopyStringDictionaryKeyCallBacks, + &cstring_value_callbacks); + if (intlemu_dict == NULL) { + //printf("Error creating dictionary\n"); + return; + } +} + +void __attribute__ ((destructor)) intlemu_fini_() { + //printf("intlemu: fini\n"); + CFRelease(intlemu_dict); + + pthread_mutex_destroy(&intlemu_lock); +} + +char * intlemu_bgettext (CFBundleRef bundle, const char *msgid) +{ + CFStringRef key; + const char *value; + CFStringRef s; + CFRange r; + CFIndex len; + CFIndex clen; + char *buf; + + if (msgid == NULL) + return NULL; + + key = CFStringCreateWithBytes( + kCFAllocatorDefault, + (const UInt8 *)msgid, + (CFIndex)strlen(msgid), + kCFStringEncodingUTF8, + false); + + pthread_mutex_lock(&intlemu_lock); + value = (char *)CFDictionaryGetValue(intlemu_dict, key); + pthread_mutex_unlock(&intlemu_lock); + //printf("CFDictionaryGetValue: [%s]\n", value); + if (value != NULL) { + CFRelease(key); + return (char *)value; + } + + /* no cached translaation, so, find one from the bundle */ + s = CFBundleCopyLocalizedString( + bundle, + key, + NULL, + NULL); + if (s == key) { + //printf("no translation found\n"); + CFRelease(key); + return (char *)msgid; + } + /* get the length in bytes */ + r.location = 0; + r.length = CFStringGetLength(s); + len = 0; + clen = CFStringGetBytes( + s, + r, + kCFStringEncodingUTF8, + 0, + false, + NULL, + 0, + &len); + buf = NULL; + if (clen == r.length) { + //printf("allocate dictionary value: %d\n", len+1); + buf = malloc(len + 1); + } + + if (buf == NULL) { + CFRelease(s); + CFRelease(key); + return (char *)msgid; + } + + clen = CFStringGetBytes( + s, + r, + kCFStringEncodingUTF8, + 0, + false, + (UInt8 *)buf, + len, + &len); + buf[len] = '\0'; + if (clen == r.length) { + pthread_mutex_lock(&intlemu_lock); + CFDictionaryAddValue(intlemu_dict, key, buf); + pthread_mutex_unlock(&intlemu_lock); + value = buf; + } + else { + free(buf); + value = msgid; + } + + CFRelease(s); + + CFRelease(key); + + return (char *)value; +} + diff --git a/src/intlemu/libintlemu.h b/src/intlemu/libintlemu.h @@ -0,0 +1,18 @@ +/* Mac OS X CoreFoundation libintl emulator */ + +#ifndef LIBINTLEMU_H +#define LIBINTLEMU_H + +#include <CoreFoundation/CoreFoundation.h> + +#define gettext(msgid) \ + intlemu_bgettext(CFBundleGetMainBundle(), msgid) + +#define dgettext(domainname, msgid) \ + intlemu_bgettext(CFBundleGetBundleWithIdentifier(CFSTR(domainname)), msgid) + +#define gettext_noop(s) s + +extern char * intlemu_bgettext (CFBundleRef bundle, const char *msgid); + +#endif diff --git a/src/main/Makefile.am b/src/main/Makefile.am @@ -6,7 +6,7 @@ INCLUDES = -I$(top_srcdir)/src/include $(LTDLINCL) plugindir = $(libdir)/@RPLUGINDIR@ LIBS = \ - @LTLIBINTL@ @LIBS@ + @LE_LIBINTL@ @LIBS@ lib_LTLIBRARIES = \ libextractor.la diff --git a/src/plugins/Makefile-plugins.am b/src/plugins/Makefile-plugins.am @@ -4,7 +4,7 @@ INCLUDES = -I$(top_srcdir)/src/include -I$(top_srcdir)/src/common plugindir = $(libdir)/@RPLUGINDIR@ LIBS = \ - @LTLIBINTL@ @LIBS@ + @LE_LIBINTL@ @LIBS@ if HAVE_GNU_LD makesymbolic=-Wl,-Bsymbolic