[dia] mingw: relocation derived from PREFIX



commit b73263c2155ad9b1353d40f3e5dcdcc63a1b8f50
Author: Fridrich Å trba <fridrich strba bluewin ch>
Date:   Thu Sep 2 20:05:09 2010 +0200

    mingw: relocation derived from PREFIX
    
    [PATCH 6/6] Make the relocations of windows autotools build
    depend on configure-time variables. For build not using
    configure, fall back to the previous behaviour
    
    Signed-off-by: Hans Breuer <hans breuer org>

 app/app_procs.c |    4 +-
 lib/Makefile.am |    4 ++-
 lib/dia_dirs.c  |   75 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 lib/dia_dirs.h  |    1 +
 lib/libdia.def  |    1 +
 5 files changed, 79 insertions(+), 6 deletions(-)
---
diff --git a/app/app_procs.c b/app/app_procs.c
index afa19c8..129e072 100644
--- a/app/app_procs.c
+++ b/app/app_procs.c
@@ -649,8 +649,8 @@ _setup_textdomains (void)
 #ifdef G_OS_WIN32
   /* calculate runtime directory */
   {
-    gchar* localedir = dia_get_lib_directory ("locale");
-    
+    gchar* localedir = dia_get_locale_directory ();
+
     bindtextdomain(GETTEXT_PACKAGE, localedir);
     g_free (localedir);
   }
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 16f63bb..57126f4 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -194,7 +194,9 @@ AM_CPPFLAGS = \
 	$(LIBART_CFLAGS) \
 	-DLIBDIA_COMPILATION \
 	-DLIBDIR=\"$(libdir)\" \
-	-DDATADIR=\"$(pkgdatadir)\"
+	-DDATADIR=\"$(pkgdatadir)\" \
+	-DLOCALEDIR=\"$(localedir)\" \
+	-DPREFIX=\"$(prefix)\"
 
 sheetdir = $(pkgdatadir)/sheets
 
diff --git a/lib/dia_dirs.c b/lib/dia_dirs.c
index 98f7e56..514ddc8 100644
--- a/lib/dia_dirs.c
+++ b/lib/dia_dirs.c
@@ -32,6 +32,22 @@
 #endif
 #include <glib/gstdio.h>
 
+#if defined(G_OS_WIN32) && defined(PREFIX)
+static gchar *
+replace_prefix (const gchar *runtime_prefix,
+                const gchar *configure_time_path)
+{
+        if (runtime_prefix &&
+            strncmp (configure_time_path, PREFIX "/",
+                     strlen (PREFIX) + 1) == 0) {
+                return g_strconcat (runtime_prefix,
+                                    configure_time_path + strlen (PREFIX) + 1,
+                                    NULL);
+        } else
+                return g_strdup (configure_time_path);
+}
+#endif
+
 /** Get the name of a subdirectory of our data directory.
  *  This function does not create the subdirectory, just make the correct name.
  * @param subdir The name of the directory desired.
@@ -42,6 +58,8 @@ gchar *
 dia_get_data_directory(const gchar* subdir)
 {
 #ifdef G_OS_WIN32
+  gchar *tmpPath = NULL;
+  gchar *returnPath = NULL;
   /*
    * Calculate from executable path
    */
@@ -57,10 +75,20 @@ dia_get_data_directory(const gchar* subdir)
       if (strrchr(sLoc, G_DIR_SEPARATOR))
         strrchr(sLoc, G_DIR_SEPARATOR)[1] = 0;
     }
-  return g_strconcat (sLoc , subdir, NULL); 
+#if defined(PREFIX) && defined(DATADIR)
+  tmpPath = replace_prefix(sLoc, DATADIR);
+  if (strlen (subdir) == 0)
+    returnPath = g_strdup(tmpPath);
+  else
+    returnPath = g_build_path(G_DIR_SEPARATOR_S, tmpPath, subdir, NULL);
+  g_free(tmpPath);
+  return returnPath;
+#else
+  return g_strconcat (sLoc , subdir, NULL);
+#endif
 
 #else
-  if (strlen (subdir) == 0)		
+  if (strlen (subdir) == 0)
     return g_strconcat (DATADIR, NULL);
   else
     return g_strconcat (DATADIR, G_DIR_SEPARATOR_S, subdir, NULL);
@@ -77,6 +105,8 @@ gchar*
 dia_get_lib_directory(const gchar* subdir)
 {
 #ifdef G_OS_WIN32
+  gchar *tmpPath = NULL;
+  gchar *returnPath = NULL;
   /*
    * Calulate from executable path
    */
@@ -92,7 +122,46 @@ dia_get_lib_directory(const gchar* subdir)
       if (strrchr(sLoc, G_DIR_SEPARATOR))
         strrchr(sLoc, G_DIR_SEPARATOR)[1] = 0;
     }
-  return g_strconcat (sLoc , subdir, NULL); 
+#if defined(PREFIX) && defined(LIBDIR)
+  tmpPath = replace_prefix(sLoc, LIBDIR);
+  returnPath = g_build_path(G_DIR_SEPARATOR_S, tmpPath, subdir, NULL);
+  g_free(tmpPath);
+  return returnPath;
+#else
+  return g_strconcat (sLoc , subdir, NULL);
+#endif
+
+
+#else
+  return g_strconcat (LIBDIR, G_DIR_SEPARATOR_S, subdir, NULL);
+#endif
+}
+
+gchar*
+dia_get_locale_directory(void)
+{
+#ifdef G_OS_WIN32
+#if defined(PREFIX) && defined(LOCALEDIR)
+  /*
+   * Calulate from executable path
+   */
+  gchar sLoc [MAX_PATH+1];
+  HINSTANCE hInst = GetModuleHandle(NULL);
+
+  if (0 != GetModuleFileName(hInst, sLoc, MAX_PATH))
+    {
+	/* strip the name */
+      if (strrchr(sLoc, G_DIR_SEPARATOR))
+        strrchr(sLoc, G_DIR_SEPARATOR)[0] = 0;
+      /* and one dir (bin) */
+      if (strrchr(sLoc, G_DIR_SEPARATOR))
+        strrchr(sLoc, G_DIR_SEPARATOR)[1] = 0;
+    }
+  return replace_prefix(sLoc, LOCALEDIR);
+#else
+  return dia_get_lib_directory ("locale");
+#endif
+
 
 #else
   return g_strconcat (LIBDIR, G_DIR_SEPARATOR_S, subdir, NULL);
diff --git a/lib/dia_dirs.h b/lib/dia_dirs.h
index e1d3cd2..c0cbff0 100644
--- a/lib/dia_dirs.h
+++ b/lib/dia_dirs.h
@@ -29,6 +29,7 @@
 
 gchar *dia_get_data_directory (const gchar* subdir);
 gchar *dia_get_lib_directory  (const gchar* subdir);
+gchar *dia_get_locale_directory (void);
 gchar *dia_config_filename    (const gchar* file);
 gboolean dia_config_ensure_dir  (const gchar* filename);
 gchar *dia_get_absolute_filename (const gchar *filename);
diff --git a/lib/libdia.def b/lib/libdia.def
index 1fb5a9d..2f49d61 100644
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -254,6 +254,7 @@ EXPORTS
 
  dia_get_data_directory
  dia_get_lib_directory
+ dia_get_locale_directory
  dia_get_absolute_filename
  dia_relativize_filename
  dia_absolutize_filename



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]