From fd3d64301598af490d54df88fb485853521e283f Mon Sep 17 00:00:00 2001
From: John Darrington <john@darrington.wattle.id.au>
Date: Tue, 20 May 2008 14:01:09 +0000
Subject: [PATCH] Applied patch #6515 : Allow dlls to be built on w32 platforms

---
 configure.ac                |  1 +
 src/ui/gui/ChangeLog        | 10 ++++++++++
 src/ui/gui/automake.mk      | 40 ++++++++++++++++++++++++++-----------
 src/ui/gui/psppire-keypad.c |  2 +-
 4 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/configure.ac b/configure.ac
index fafa7ccd50..8f3c96c4dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,6 +11,7 @@ AC_GNU_SOURCE
 AC_PROG_CC
 gl_EARLY
 AM_PROG_CC_C_O
+AC_LIBTOOL_WIN32_DLL
 AC_LIBTOOL_DLOPEN
 AC_PROG_LIBTOOL
 PKG_PROG_PKG_CONFIG
diff --git a/src/ui/gui/ChangeLog b/src/ui/gui/ChangeLog
index 3cc945cc53..88a42f1ffa 100644
--- a/src/ui/gui/ChangeLog
+++ b/src/ui/gui/ChangeLog
@@ -1,3 +1,13 @@
+2008-05-20  John Darrington <john@darrington.wattle.id.au>
+
+	* automake.mk: Added the -no-undefined flag so that dlls can be built
+	on w32 platforms.  Abstracted the dependencies of glade-register.c
+	into a new shared library libpsppwidgets.so, which can be either
+	linked directly by psppire or by libpsppire.so
+
+	* psppire-keypad.c: Changed snprintf to g_snprintf so as not to use
+	gnulib.
+
 2008-05-15  Ben Pfaff  <blp@gnu.org>
 
 	* automake.mk: Rename install-data-hook to yelp-check and mark it
diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk
index a405e87a61..651f5905ee 100644
--- a/src/ui/gui/automake.mk
+++ b/src/ui/gui/automake.mk
@@ -1,7 +1,5 @@
 ## Process this file with automake to produce Makefile.in  -*- makefile -*-
 
-
-
 bin_PROGRAMS += src/ui/gui/psppire 
 
 src_ui_gui_psppire_CFLAGS = $(GTK_CFLAGS) $(GLADE_CFLAGS) -Wall \
@@ -9,8 +7,8 @@ src_ui_gui_psppire_CFLAGS = $(GTK_CFLAGS) $(GLADE_CFLAGS) -Wall \
 
 
 src_ui_gui_psppire_LDFLAGS = \
-	$(PG_LDFLAGS) \
-	-export-dynamic
+	$(PG_LDFLAGS)
+
 
 
 if RELOCATABLE_VIA_LD
@@ -20,15 +18,40 @@ src_ui_gui_psppire_LDFLAGS += -rpath $(pkglibdir)
 endif
 
 
-pkglib_LTLIBRARIES = src/ui/gui/libpsppire.la
+# The library libpsppire contains a single function to register our custom widgets with libglade.
+# This library is dynamically loaded by libglade.   On w32 platforms, dynamic libraries simply 
+# can't be created unless all of the symbols can be resolved at link time.  Thus, all the custom 
+# widgets have to be available.  
+# But they can't appear in the library AND the binary, otherwise glib complains about them already
+# existing (and its a waste of space).  So we have a seperate shared library (statically loaded) 
+# libpsppwidgets which contains our custom widgets.
+
+pkglib_LTLIBRARIES = src/ui/gui/libpsppwidgets.la src/ui/gui/libpsppire.la 
+
+src_ui_gui_libpsppwidgets_la_CFLAGS = $(GTK_CFLAGS)
+src_ui_gui_libpsppwidgets_la_LDFLAGS = -no-undefined
+src_ui_gui_libpsppwidgets_la_LIBADD = $(GTK_LIBS)
+
+src_ui_gui_libpsppwidgets_la_SOURCES = \
+	src/ui/gui/psppire-dialog.c \
+	src/ui/gui/psppire-keypad.c \
+	src/ui/gui/psppire-selector.c \
+	src/ui/gui/psppire-buttonbox.c \
+	src/ui/gui/psppire-hbuttonbox.c \
+	src/ui/gui/psppire-vbuttonbox.c \
+	src/ui/gui/psppire-acr.c 
+
 
 src_ui_gui_libpsppire_la_CFLAGS = $(GLADE_CFLAGS) 
+src_ui_gui_libpsppire_la_LDFLAGS = -no-undefined
+src_ui_gui_libpsppire_la_LIBADD = $(GLADE_LIBS) src/ui/gui/libpsppwidgets.la
 
 src_ui_gui_libpsppire_la_SOURCES = \
 	src/ui/gui/glade-register.c
 
 src_ui_gui_psppire_LDADD = \
 	-dlopen src/ui/gui/libpsppire.la \
+	src/ui/gui/libpsppwidgets.la \
 	lib/gtksheet/libgtksheet.a \
 	src/language/liblanguage.a \
 	src/ui/libuicommon.a \
@@ -124,13 +147,9 @@ src_ui_gui_psppire_SOURCES = \
         src/ui/gui/oneway-anova-dialog.h \
 	src/ui/gui/output-viewer.c \
 	src/ui/gui/output-viewer.h \
-	src/ui/gui/psppire-acr.c \
 	src/ui/gui/psppire-acr.h \
-	src/ui/gui/psppire-buttonbox.c \
 	src/ui/gui/psppire-buttonbox.h \
-	src/ui/gui/psppire-hbuttonbox.c \
 	src/ui/gui/psppire-hbuttonbox.h \
-	src/ui/gui/psppire-vbuttonbox.c \
 	src/ui/gui/psppire-vbuttonbox.h \
 	src/ui/gui/psppire-case-file.c \
 	src/ui/gui/psppire-case-file.h \
@@ -138,13 +157,10 @@ src_ui_gui_psppire_SOURCES = \
 	src/ui/gui/psppire-data-editor.h \
 	src/ui/gui/psppire-data-store.c \
 	src/ui/gui/psppire-data-store.h \
-	src/ui/gui/psppire-dialog.c \
 	src/ui/gui/psppire-dialog.h \
 	src/ui/gui/psppire-dict.c \
 	src/ui/gui/psppire-dict.h \
-	src/ui/gui/psppire-keypad.c \
 	src/ui/gui/psppire-keypad.h \
-	src/ui/gui/psppire-selector.c \
 	src/ui/gui/psppire-selector.h \
 	src/ui/gui/psppire-var-ptr.c \
 	src/ui/gui/psppire-var-ptr.h \
diff --git a/src/ui/gui/psppire-keypad.c b/src/ui/gui/psppire-keypad.c
index 19b8cabf4e..23ddccb550 100644
--- a/src/ui/gui/psppire-keypad.c
+++ b/src/ui/gui/psppire-keypad.c
@@ -339,7 +339,7 @@ psppire_keypad_init (PsppireKeypad *kp)
     {
       int j = i - 1;
       char buf[5];
-      snprintf (buf, 5, "%d", i);
+      g_snprintf (buf, 5, "%d", i);
       kp->digit[i] = gtk_button_new_with_label (buf);
 
       if ( i == 0 )
-- 
2.30.2