From 19e0f9880f3a4d0edc366f582c1a5d4767b1f36d Mon Sep 17 00:00:00 2001
From: Slava Zanko <slavazanko@gmail.com>
Date: Tue, 5 Jul 2011 13:04:09 +0300
Subject: [PATCH 2/2] Changes for build with static glib

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
---
 lib/Makefile.am       |   16 ++++-----
 lib/tty/Makefile.am   |    8 +----
 m4.include/ac-glib.m4 |   83 +++++++++++++++++++++++++++---------------------
 src/Makefile.am       |    2 +
 4 files changed, 57 insertions(+), 52 deletions(-)

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 70eab30..2d741aa 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -67,13 +67,11 @@ libmc_la_LIBADD = \
 	vfs/libmcvfs.la \
 	widget/libmcwidget.la
 
-libmc_la_LIBADD += $(MCLIBS) $(SLANGLIB)
-
-if HAVE_GMODULE
-    libmc_la_LIBADD += $(GMODULE_LIBS)
-else
-    libmc_la_LIBADD += $(GLIB_LIBS)
-endif
-
-libmc_la_LIBADD += $(PCRE_LIBS) $(LIBICONV) $(INTLLIBS)
+libmc_la_LIBADD += \
+	$(MCLIBS) \
+	$(SLANGLIB) \
+	$(GLIB_LIBS) \
+	$(PCRE_LIBS) \
+	$(LIBICONV) \
+	$(INTLLIBS)
 
diff --git a/lib/tty/Makefile.am b/lib/tty/Makefile.am
index 9cade4b..8090800 100644
--- a/lib/tty/Makefile.am
+++ b/lib/tty/Makefile.am
@@ -22,13 +22,7 @@ TTY_SRC = \
 
 libmctty_la_SOURCES = $(TTY_SRC) $(TTY_SCREEN_SRC)
 
-libmctty_la_CFLAGS = -I$(top_srcdir)
+libmctty_la_CFLAGS = -I$(top_srcdir) $(GLIB_CFLAGS)
 
-if HAVE_GMODULE
-libmctty_la_CFLAGS += $(GMODULE_CFLAGS)
-else
-libmctty_la_CFLAGS += $(GLIB_CFLAGS)
-
-endif
 libmctty_la_CFLAGS += -DDATADIR=\""$(pkgdatadir)/"\" -DLOCALEDIR=\""$(localedir)"\"
 
diff --git a/m4.include/ac-glib.m4 b/m4.include/ac-glib.m4
index bdd0999..a454760 100644
--- a/m4.include/ac-glib.m4
+++ b/m4.include/ac-glib.m4
@@ -3,6 +3,47 @@ dnl Check whether the g_module_* family of functions works
 dnl on this system.  We need to know that at the compile time to
 dnl decide whether to link with X11.
 dnl
+
+AC_DEFUN([AC_CHECK_STATIC_GLIB], [
+    dnl
+    dnl Try to find static libraries for glib and gmodule.
+    dnl
+    AC_ARG_WITH([glib_static],
+        AC_HELP_STRING([--with-glib-static],[Link glib statically [[no]]]))
+
+    if test x$with_glib_static = xyes; then
+        GLIB_LIBDIR=`pkg-config --variable=libdir glib-2.0`
+        new_GLIB_LIBS=
+        for i in $GLIB_LIBS; do
+            case x$i in
+            x-lglib*)
+                lib=glib ;;
+            x-lgmodule*)
+                lib=gmodule ;;
+            *)
+                lib=
+                add="$i" ;;
+            esac
+
+            if test -n "$lib"; then
+                lib1=`echo $i | sed 's/^-l//'`
+                if test -f "$GLIB_LIBDIR/lib${lib1}.a"; then
+                    add="$GLIB_LIBDIR/lib${lib1}.a"
+                else
+                    if test -f "$GLIB_LIBDIR/lib${lib}.a"; then
+                        add="$GLIB_LIBDIR/lib${lib}.a"
+                    else
+                        AC_MSG_ERROR([Cannot find static $lib])
+                    fi
+                fi
+            fi
+            new_GLIB_LIBS="$new_GLIB_LIBS $add"
+            glib_found=yes
+        done
+        GLIB_LIBS="$new_GLIB_LIBS"
+    fi
+])
+
 AC_DEFUN([AC_G_MODULE_SUPPORTED], [
 
     g_module_supported=""
@@ -43,40 +84,10 @@ AC_DEFUN([AC_G_MODULE_SUPPORTED], [
 
     AM_CONDITIONAL([HAVE_GMODULE], [test x"$g_module_supported" != x])
 
-    dnl
-    dnl Try to find static libraries for glib and gmodule.
-    dnl
-    if test x$with_glib_static = xyes; then
-        GLIB_LIBDIR=`pkg-config --variable=libdir glib-2.0`
-        new_GLIB_LIBS=
-        for i in $GLIB_LIBS; do
-            case x$i in
-            x-lglib*)
-                lib=glib ;;
-            x-lgmodule*)
-                lib=gmodule ;;
-            *)
-                lib=
-                add="$i" ;;
-            esac
-
-            if test -n "$lib"; then
-                lib1=`echo $i | sed 's/^-l//'`
-                if test -f "$GLIB_LIBDIR/lib${lib1}.a"; then
-                    add="$GLIB_LIBDIR/lib${lib1}.a"
-                else
-                    if test -f "$GLIB_LIBDIR/lib${lib}.a"; then
-                        add="$GLIB_LIBDIR/lib${lib}.a"
-                    else
-                        AC_MSG_ERROR([Cannot find static $lib])
-                    fi
-                fi
-            fi
-            new_GLIB_LIBS="$new_GLIB_LIBS $add"
-        done
-        GLIB_LIBS="$new_GLIB_LIBS"
+    if test x"$g_module_supported" != x; then
+        GLIB_LIBS="$GMODULE_LIBS"
+        GLIB_CFLAGS="$GMODULE_CFLAGS"
     fi
-
 ])
 
 AC_DEFUN([AC_CHECK_GLIB], [
@@ -86,11 +97,11 @@ AC_DEFUN([AC_CHECK_GLIB], [
     dnl without any glib won't have their time wasted by other checks.
     dnl
 
-    AC_ARG_WITH([glib_static],
-        AC_HELP_STRING([--with-glib-static],[Link glib statically [[no]]]))
-
     glib_found=no
+
     PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.8], [glib_found=yes], [:])
+    AC_CHECK_STATIC_GLIB
+
     if test x"$glib_found" = xno; then
         AC_MSG_ERROR([glib-2.0 not found or version too old (must be >= 2.8)])
     fi
diff --git a/src/Makefile.am b/src/Makefile.am
index d5ec6b0..c402624 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,6 +17,7 @@ endif
 
 AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) $(PCRE_CFLAGS)
 
+
 localedir = $(datadir)/locale
 pkglibexecdir = $(libexecdir)/@PACKAGE@
 
@@ -31,6 +32,7 @@ DIFFLIB = diffviewer/libdiffviewer.la
 endif
 
 mc_LDADD = \
+	$(GLIB_LIBS) \
 	vfs/libmc-vfs.la \
 	viewer/libmcviewer.la \
 	filemanager/libmcfilemanager.la \
-- 
1.7.5.2

