Commit 1964935f authored by Yves Combe's avatar Yves Combe

Set Gtk to run from bundle.

svn path=/trunk/; revision=2540
parent 639237ce
2007-03-23 Yves Combe <yves@ycombe.net>
Set GTK to run from bundle. TODO: fix segfault.
* Makefile.am:
* configure.in:
* macosx/pangorc:
* src/gcompris/Makefile.am:
* src/gcompris/gcompris-nsbundle.m:
2007-03-22 Yves Combe <yves@ycombe.net>
fix and continue osx bundle creation
......
......@@ -105,8 +105,10 @@ if WITH_NSBUNDLE
ETC_PANGO=etc/pango
ETC_GTK=etc/gtk-2.0
GTK_CONF_FILES=gtk.immodules gdk-pixbuf.loaders im-multipress.conf
PANGO_CONF_FILES=pango.modules
FONTCONFIG_PATH=etc/fonts
GTK_MODULES_PATH=lib/gtk-2.0
EXTERN_BIN= gnuchess gnucap
nsbundle:
$(INSTALL) -d $(BUNDLE_RESOURCES_DIR)
......@@ -117,24 +119,37 @@ nsbundle:
bindir=$(BUNDLE_EXEC_DIR) \
PYTHON_PLUGIN_DIR=$(BUNDLE_RESOURCES_DIR)/share/gcompris/python
mv $(BUNDLE_EXEC_DIR)/gcompris $(BUNDLE_EXEC_DIR)/$(BUNDLE_NAME)
if OS_MACOSX
$(INSTALL) -d $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/lib
if OS_MACOSX
for f in $$(otool -L $(BUNDLE_EXEC_DIR)/$(BUNDLE_NAME) | grep $(prefix) | sed -e 's,^.*$(prefix)/\(.*.dylib\).*$$,\1,' ); do \
ls -L $(prefix)/$$f; \
cp -Lv $(prefix)/$$f $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$$f ;\
install_name_tool -change $(prefix)/$$f @executable_path/$(NSBUNDLE_GTK_DIR)/$$f $(BUNDLE_EXEC_DIR)/$(BUNDLE_NAME) ; \
done;
else
for f in $$(ldd $(BUNDLE_EXEC_DIR)/$(BUNDLE_NAME)| grep $(prefix) | sed -e 's,^.*$(prefix)/\(.*\) (.*$$,\1,' ); do \
ls -L $(prefix)/$$f; \
cp -Lv $(prefix)/$$f $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$$f ;\
done
endif
$(INSTALL) -d $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$(ETC_PANGO)
$(INSTALL) -d $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$(ETC_GTK)
#sed -e 's,$(prefix),@{prefix},g' $(prefix)/$(ETC_PANGO)/pangorc > $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$(ETC_PANGO)/pangord
for f in $(GTK_CONF_FILES); do\
sed -e 's,$(prefix),@{prefix},g' $(prefix)/$(ETC_GTK)/$$f > $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$(ETC_GTK)/$$f ;\
done
$(INSTALL) -d $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$(ETC_PANGO)
for f in $(PANGO_CONF_FILES); do\
sed -e 's,$(prefix),@{prefix},g' $(prefix)/$(ETC_PANGO)/$$f > $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$(ETC_PANGO)/$$f ;\
done
$(INSTALL) $(top_srcdir)/macosx/pangorc $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$(ETC_PANGO)/pangorc
$(INSTALL) -d $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$(FONTCONFIG_PATH)
(cd $(prefix)/$(FONTCONFIG_PATH) ; tar cf - * )| ( cd $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$(FONTCONFIG_PATH); tar xf -)
$(INSTALL) -d $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$(GTK_MODULES_PATH)
(cd $(prefix)/$(GTK_MODULES_PATH) ; tar cf - --exclude include * )| ( cd $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/$(GTK_MODULES_PATH); tar xf -)
$(INSTALL) -d $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/bin
for f in $(EXTERN_BIN); do \
cp -v $(prefix)/bin/$$f $(BUNDLE_EXEC_DIR)/$(NSBUNDLE_GTK_DIR)/bin/$$f; \
done
endif
......
......@@ -86,12 +86,13 @@ if test "x$nsbundle" = "xyes"; then
AC_MSG_ERROR([You need GNUstep dev to use nsbundle. Make sure GNUSTEP_SYSTEM_ROOT is set." ])
fi
CPPFLAGS="$saved_CPPFLAGS"
NSBUNDLE_CPPFLAGS=" -I$GNUSTEP_SYSTEM_ROOT/Library/Headers "
OBJCFLAGS=" -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -fconstant-string-class=NSConstantString -I$GNUSTEP_SYSTEM_ROOT/Library/Headers "
NSBUNDLE_GTK_DIR="GTK"
NSBUNDLE_LDFLAGS="-rdynamic -fgnu-runtime -L$GNUSTEP_SYSTEM_ROOT/Library/Libraries -lgnustep-base -Wl,-rpath=\\\$\$ORIGIN/$NSBUNDLE_GTK_DIR "
NSBUNDLE_LDFLAGS="-rdynamic -fgnu-runtime -L$GNUSTEP_SYSTEM_ROOT/Library/Libraries -lgnustep-base -Wl,-rpath=\\\$\$ORIGIN/$NSBUNDLE_GTK_DIR/lib "
AC_LANG_POP([Objective C])
fi
AC_DEFINE_UNQUOTED(NSBUNDLE, 1, [ Define to 1 to use NSBundle for relocation (OSX/GNUstep) ])
AC_DEFINE_UNQUOTED(NSBUNDLE_GTK_DIR, "$NSBUNDLE_GTK_DIR", [ Define to 1 to use NSBundle for relocation (OSX/GNUstep) ])
else
OBJC=$CC
AC_SUBST(OBJC)
......
#
# pangorc file for uninstalled operation. If pango-viewer is run with
# this file in the current directory it will set it as PANGO_RC_FILE
#
[Pango]
ModuleFiles = ./pango.modules
[PangoX]
AliasFiles = ./pangox.aliases
\ No newline at end of file
......@@ -133,3 +133,6 @@ gcompris_LDADD = \
EXTRA_DIST = \
Makefile.mingw gcomprisrc.rc
gcompris_nsbundle_CPPFLAGS = -fconstant-string-class=NSConstantString
\ No newline at end of file
#include <Foundation/Foundation.h>
#include "gcompris.h"
#include "config.h"
@interface NSMutableString (Perso)
- (id) stringCleanPath;
@end
void gcompris_fix_gtk_etc (void);
void set_prefix( NSString *source_dir,
NSString *filename,
NSString *tmp_dir,
NSString *prefix,
const char *var);
gchar *gcompris_nsbundle_resource(void)
{
#ifdef NSBUNDLE
NSAutoreleasePool *pool;
gchar *resourcePath = NULL;
NSAutoreleasePool *pool;
pool = [NSAutoreleasePool new];
resourcePath = g_strdup_printf("%s",[[[NSBundle mainBundle] resourcePath] UTF8String]);
printf("NSBundle resourcePath %s\n", resourcePath);
gcompris_fix_gtk_etc ();
[pool release];
return resourcePath;
#else
return NULL;
#endif
}
void gcompris_fix_gtk_etc (void)
{
NSMutableString *gtk_path = [[[[NSBundle mainBundle] executablePath] mutableCopy] autorelease] ;
NSString *base_dir = @"/../";
NSString *gtk_dir = @NSBUNDLE_GTK_DIR ;
NSString *gtk_conf_dir = @"/etc/gtk-2.0";
NSString *pango_conf_dir = @"/etc/pango";
NSString *gtk_immodules = @"/gtk.immodules";
NSString *gdk_pixbuf_loaders = @"/gdk-pixbuf.loaders";
NSString *pango_modules = @"/pango.modules";
NSString *pangorc = @"/pangorc";
printf("NSBundle executablePath %s\n", [gtk_path UTF8String]);
// first is to suppress last component (executable name)
[gtk_path appendString: base_dir];
[gtk_path appendString: gtk_dir];
[gtk_path stringCleanPath];
printf("NSBundle Gtk Dir Path %s\n", [gtk_path UTF8String]);
// Get the temporary filenames
NSString *tmp_dir = [NSTemporaryDirectory() autorelease];
printf("Temporary directory %s\n", [tmp_dir UTF8String]);
set_prefix( gtk_conf_dir,
gtk_immodules,
tmp_dir,
gtk_path,
"GTK_IM_MODULE_FILE");
set_prefix( gtk_conf_dir,
gdk_pixbuf_loaders,
tmp_dir,
gtk_path,
"GDK_PIXBUF_MODULE_FILE");
set_prefix( pango_conf_dir,
pango_modules,
tmp_dir,
gtk_path,
NULL);
// just copy the pangorc file
NSMutableString *pango_rc = [[gtk_path mutableCopy] autorelease];
[pango_rc appendString: pango_conf_dir];
[pango_rc appendString: pangorc];
NSMutableString *tmp_pango_rc = [[tmp_dir mutableCopy] autorelease];
[tmp_pango_rc appendString: pangorc];
[[NSFileManager defaultManager] copyPath: pango_rc toPath: tmp_pango_rc handler: nil];
printf("Copy %s file to %s\n", [pango_rc UTF8String], [tmp_pango_rc UTF8String]);
// PANGO_RC_FILE gives path to pango.modules
setenv ("PANGO_RC_FILE", g_strdup([tmp_pango_rc UTF8String]), TRUE);
//Now we just need to adjust some environnement variables
setenv ("GTK_EXE_PREFIX", g_strdup([gtk_path UTF8String]), TRUE);
setenv ("GTK_DATA_PREFIX", g_strdup([gtk_path UTF8String]), TRUE);
printf ("GTK environnemnt set to %s\n", getenv("GTK_EXE_PREFIX"));
// Unused ?
NSMutableString *gtk_rc = [[gtk_path mutableCopy] autorelease];
[gtk_rc appendString: gtk_conf_dir];
[gtk_rc appendString: @"/gtkrc"];
setenv ("GTK2_RC_FILES", g_strdup([gtk_rc UTF8String]), TRUE);
printf ("GTK environnemnt set to %s\n", getenv("GTK2_RC_FILES"));
// is that usefull for GCompris ?
NSMutableString *fontconfig_path = [[gtk_path mutableCopy] autorelease];
[fontconfig_path appendString: @"/etc/fonts"];
setenv ("FONTCONFIG_PATH", g_strdup([fontconfig_path UTF8String]), TRUE);
printf ("FC environnemnt set to %s\n", getenv("FONTCONFIG_PATH"));
printf ("GTK environnemnt set to %s\n", getenv("GTK_EXE_PREFIX"));
}
void set_prefix( NSString *source_dir,
NSString *filename,
NSString *tmp_dir,
NSString *prefix,
const char *var)
{
NSMutableString *source_file = [[prefix mutableCopy] autorelease];
[source_file appendString: source_dir];
[source_file appendString: filename];
NSMutableString *tmp_file = [[tmp_dir mutableCopy] autorelease];
[tmp_file appendString: filename];
NSMutableString *file_content = [[[NSString stringWithContentsOfFile: source_file] mutableCopy] autorelease];
[file_content replaceOccurrencesOfString: @"@{prefix}"
withString: prefix
options: NSLiteralSearch
range: NSMakeRange(0, [file_content length])];
[file_content writeToFile: tmp_file atomically: NO ];
printf("Write %s file to %s\n", [source_file UTF8String], [tmp_file UTF8String]);
if (var)
setenv(var, g_strdup([tmp_file UTF8String]), 1);
}
@implementation NSMutableString (Perso)
// suppress '..' and component just before.
- (id) stringCleanPath
{
NSMutableArray *tmpPath;
uint index =1;
tmpPath = [[[self pathComponents] mutableCopy] autorelease];
while (index < [tmpPath count]) {
if ([[tmpPath objectAtIndex: index] isEqualToString: @".."]) {
if ( index == 0)
return self;
else {
index--;
[tmpPath removeObjectAtIndex: index];
[tmpPath removeObjectAtIndex: index];
}
}
else
index++;
}
// this is to make +[NSString pathWithComponents:] construct
// an absolute path if necessary
if ([super isAbsolutePath] == YES)
{
[tmpPath replaceObjectAtIndex: 0 withObject: @""];
}
[self setString:[[NSString pathWithComponents: tmpPath] autorelease]] ;
return self;
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment