1*b58112e5SPatrick WilliamsFrom 6aa1338b916fe72c200b6f160b934be15b6ff590 Mon Sep 17 00:00:00 2001
25082cc7fSAndrew GeisslerFrom: Ross Burton <ross.burton@intel.com>
35082cc7fSAndrew GeisslerDate: Tue, 23 Jan 2018 00:54:13 +0000
45082cc7fSAndrew GeisslerSubject: [PATCH] gettext: beat library detection into shape
55082cc7fSAndrew Geissler
65082cc7fSAndrew GeisslerFor reasons which I just can't fathom gnulib doesn't use the expected tools to
75082cc7fSAndrew Geisslerfind libraries but badly reinvents the wheel.  This will trivially lead to host
85082cc7fSAndrew Geisslercontamination (explicit searches of /usr/lib) or incorrect RPATHs (bad
95082cc7fSAndrew Geisslercanonicalisation resulting in relative paths).
105082cc7fSAndrew Geissler
115082cc7fSAndrew GeisslerSimply delete all the crazy, and replace with a single call to pkg-config.
125082cc7fSAndrew Geissler
135082cc7fSAndrew GeisslerUpstream-Status: Inappropriate [upstream still refuse to consider pkg-config]
145082cc7fSAndrew GeisslerSigned-off-by: Ross Burton <ross.burton@intel.com>
155082cc7fSAndrew Geissler---
16*b58112e5SPatrick Williams gettext-tools/gnulib-m4/libxml.m4       | 105 ++---------------------
17*b58112e5SPatrick Williams libtextstyle/gnulib-local/m4/libglib.m4 | 106 +++---------------------
18*b58112e5SPatrick Williams libtextstyle/gnulib-m4/libglib.m4       | 106 +++---------------------
19*b58112e5SPatrick Williams 3 files changed, 31 insertions(+), 286 deletions(-)
205082cc7fSAndrew Geissler
215082cc7fSAndrew Geisslerdiff --git a/gettext-tools/gnulib-m4/libxml.m4 b/gettext-tools/gnulib-m4/libxml.m4
225082cc7fSAndrew Geisslerindex 0340490..0355388 100644
235082cc7fSAndrew Geissler--- a/gettext-tools/gnulib-m4/libxml.m4
245082cc7fSAndrew Geissler+++ b/gettext-tools/gnulib-m4/libxml.m4
255082cc7fSAndrew Geissler@@ -13,6 +13,7 @@ dnl gl_LIBXML(FORCE-INCLUDED)
265082cc7fSAndrew Geissler dnl   forces the use of the included or an external libxml.
275082cc7fSAndrew Geissler AC_DEFUN([gl_LIBXML],
285082cc7fSAndrew Geissler [
295082cc7fSAndrew Geissler+  AC_REQUIRE([PKG_PROG_PKG_CONFIG])
305082cc7fSAndrew Geissler   AC_REQUIRE([AM_ICONV_LINK])
315082cc7fSAndrew Geissler
325082cc7fSAndrew Geissler   ifelse([$1], , [
335082cc7fSAndrew Geissler@@ -30,106 +31,10 @@ AC_DEFUN([gl_LIBXML],
345082cc7fSAndrew Geissler   INCXML=
355082cc7fSAndrew Geissler   ifelse([$1], [yes], , [
365082cc7fSAndrew Geissler     if test "$gl_cv_libxml_use_included" != yes; then
375082cc7fSAndrew Geissler-      dnl Figure out whether we can use a preinstalled libxml2, or have to use
385082cc7fSAndrew Geissler-      dnl the included one.
395082cc7fSAndrew Geissler-      AC_CACHE_VAL([gl_cv_libxml], [
405082cc7fSAndrew Geissler-        gl_cv_libxml=no
415082cc7fSAndrew Geissler-        gl_cv_LIBXML=
425082cc7fSAndrew Geissler-        gl_cv_LTLIBXML=
435082cc7fSAndrew Geissler-        gl_cv_INCXML=
445082cc7fSAndrew Geissler-        gl_save_LIBS="$LIBS"
455082cc7fSAndrew Geissler-        LIBS="$LIBS $LIBICONV"
465082cc7fSAndrew Geissler-        dnl Search for libxml2 and define LIBXML2, LTLIBXML2 and INCXML2
475082cc7fSAndrew Geissler-        dnl accordingly.
485082cc7fSAndrew Geissler-        dnl Don't use xml2-config nor pkg-config, since it doesn't work when
495082cc7fSAndrew Geissler-        dnl cross-compiling or when the C compiler in use is different from the
505082cc7fSAndrew Geissler-        dnl one that built the library.
515082cc7fSAndrew Geissler-        dnl Use a test program that tries to invoke xmlFree. On Cygwin 1.7.x,
525082cc7fSAndrew Geissler-        dnl libxml2 is built in such a way that uses of xmlFree work fine with
535082cc7fSAndrew Geissler-        dnl -Wl,--enable-auto-import but lead to a link error with
545082cc7fSAndrew Geissler-        dnl -Wl,--disable-auto-import.
555082cc7fSAndrew Geissler-        AC_LIB_LINKFLAGS_BODY([xml2])
565082cc7fSAndrew Geissler-        LIBS="$gl_save_LIBS $LIBXML2 $LIBICONV"
575082cc7fSAndrew Geissler-        AC_LINK_IFELSE(
585082cc7fSAndrew Geissler-          [AC_LANG_PROGRAM(
595082cc7fSAndrew Geissler-             [[#include <libxml/xmlversion.h>
605082cc7fSAndrew Geissler-               #include <libxml/xmlmemory.h>
615082cc7fSAndrew Geissler-               #include <libxml/xpath.h>
625082cc7fSAndrew Geissler-             ]],
635082cc7fSAndrew Geissler-             [[xmlCheckVersion (0);
645082cc7fSAndrew Geissler-               xmlFree ((void *) 0);
655082cc7fSAndrew Geissler-               xmlXPathSetContextNode ((void *)0, (void *)0);
665082cc7fSAndrew Geissler-             ]])],
675082cc7fSAndrew Geissler-          [gl_cv_libxml=yes
685082cc7fSAndrew Geissler-           gl_cv_LIBXML="$LIBXML2 $LIBICONV"
695082cc7fSAndrew Geissler-           gl_cv_LTLIBXML="$LTLIBXML2 $LTLIBICONV"
705082cc7fSAndrew Geissler-          ])
715082cc7fSAndrew Geissler-        if test "$gl_cv_libxml" != yes; then
725082cc7fSAndrew Geissler-          gl_save_CPPFLAGS="$CPPFLAGS"
735082cc7fSAndrew Geissler-          CPPFLAGS="$CPPFLAGS $INCXML2"
745082cc7fSAndrew Geissler-          AC_LINK_IFELSE(
755082cc7fSAndrew Geissler-            [AC_LANG_PROGRAM(
765082cc7fSAndrew Geissler-               [[#include <libxml/xmlversion.h>
775082cc7fSAndrew Geissler-                 #include <libxml/xmlmemory.h>
785082cc7fSAndrew Geissler-                 #include <libxml/xpath.h>
795082cc7fSAndrew Geissler-               ]],
805082cc7fSAndrew Geissler-               [[xmlCheckVersion (0);
815082cc7fSAndrew Geissler-                 xmlFree ((void *) 0);
825082cc7fSAndrew Geissler-                 xmlXPathSetContextNode ((void *)0, (void *)0);
835082cc7fSAndrew Geissler-               ]])],
845082cc7fSAndrew Geissler-            [gl_cv_libxml=yes
855082cc7fSAndrew Geissler-             gl_cv_LIBXML="$LIBXML2 $LIBICONV"
865082cc7fSAndrew Geissler-             gl_cv_LTLIBXML="$LTLIBXML2 $LTLIBICONV"
875082cc7fSAndrew Geissler-             gl_cv_INCXML="$INCXML2"
885082cc7fSAndrew Geissler-            ])
895082cc7fSAndrew Geissler-          if test "$gl_cv_libxml" != yes; then
905082cc7fSAndrew Geissler-            dnl Often the include files are installed in /usr/include/libxml2.
915082cc7fSAndrew Geissler-            dnl In libxml2-2.5, <libxml/xmlversion.h> is self-contained.
925082cc7fSAndrew Geissler-            dnl In libxml2-2.6, it includes <libxml/xmlexports.h> which is
935082cc7fSAndrew Geissler-            dnl self-contained.
945082cc7fSAndrew Geissler-            libxml2_include_dir=
955082cc7fSAndrew Geissler-            AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <libxml2/libxml/xmlexports.h>]])],
965082cc7fSAndrew Geissler-              [gl_ABSOLUTE_HEADER([libxml2/libxml/xmlexports.h])
975082cc7fSAndrew Geissler-               libxml2_include_dir=`echo "$gl_cv_absolute_libxml2_libxml_xmlexports_h" | sed -e 's,.libxml.xmlexports\.h$,,'`
985082cc7fSAndrew Geissler-              ])
995082cc7fSAndrew Geissler-            if test -z "$libxml2_include_dir"; then
1005082cc7fSAndrew Geissler-              AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <libxml2/libxml/xmlversion.h>]])],
1015082cc7fSAndrew Geissler-                [gl_ABSOLUTE_HEADER([libxml2/libxml/xmlversion.h])
1025082cc7fSAndrew Geissler-                 libxml2_include_dir=`echo "$gl_cv_absolute_libxml2_libxml_xmlversion_h" | sed -e 's,.libxml.xmlversion\.h$,,'`
1035082cc7fSAndrew Geissler-                ])
1045082cc7fSAndrew Geissler-            fi
1055082cc7fSAndrew Geissler-            if test -n "$libxml2_include_dir" && test -d "$libxml2_include_dir"; then
1065082cc7fSAndrew Geissler-              CPPFLAGS="$gl_save_CPPFLAGS -I$libxml2_include_dir"
1075082cc7fSAndrew Geissler-              AC_LINK_IFELSE(
1085082cc7fSAndrew Geissler-                [AC_LANG_PROGRAM(
1095082cc7fSAndrew Geissler-                   [[#include <libxml/xmlversion.h>
1105082cc7fSAndrew Geissler-                     #include <libxml/xmlmemory.h>
1115082cc7fSAndrew Geissler-                     #include <libxml/xpath.h>
1125082cc7fSAndrew Geissler-                   ]],
1135082cc7fSAndrew Geissler-                   [[xmlCheckVersion (0);
1145082cc7fSAndrew Geissler-                     xmlFree ((void *) 0);
1155082cc7fSAndrew Geissler-                     xmlXPathSetContextNode ((void *)0, (void *)0);
1165082cc7fSAndrew Geissler-                   ]])],
1175082cc7fSAndrew Geissler-                [gl_cv_libxml=yes
1185082cc7fSAndrew Geissler-                 gl_cv_LIBXML="$LIBXML2 $LIBICONV"
1195082cc7fSAndrew Geissler-                 gl_cv_LTLIBXML="$LTLIBXML2 $LTLIBICONV"
1205082cc7fSAndrew Geissler-                 gl_cv_INCXML="-I$libxml2_include_dir"
1215082cc7fSAndrew Geissler-                ])
1225082cc7fSAndrew Geissler-            fi
1235082cc7fSAndrew Geissler-          fi
1245082cc7fSAndrew Geissler-          CPPFLAGS="$gl_save_CPPFLAGS"
1255082cc7fSAndrew Geissler-        fi
1265082cc7fSAndrew Geissler-        LIBS="$gl_save_LIBS"
1275082cc7fSAndrew Geissler-      ])
1285082cc7fSAndrew Geissler-      AC_MSG_CHECKING([for libxml])
1295082cc7fSAndrew Geissler-      AC_MSG_RESULT([$gl_cv_libxml])
1305082cc7fSAndrew Geissler-      if test $gl_cv_libxml = yes; then
1315082cc7fSAndrew Geissler-        LIBXML="$gl_cv_LIBXML"
1325082cc7fSAndrew Geissler-        LTLIBXML="$gl_cv_LTLIBXML"
1335082cc7fSAndrew Geissler-        INCXML="$gl_cv_INCXML"
1345082cc7fSAndrew Geissler-      else
1355082cc7fSAndrew Geissler-        gl_cv_libxml_use_included=yes
1365082cc7fSAndrew Geissler-      fi
1375082cc7fSAndrew Geissler+      PKG_CHECK_MODULES([XML], [libxml-2.0])
1385082cc7fSAndrew Geissler+      LIBXML=$XML_LIBS
1395082cc7fSAndrew Geissler+      LTLIBXML=$XML_LIBS
1405082cc7fSAndrew Geissler+      INCXML=$XML_CFLAGS
1415082cc7fSAndrew Geissler     fi
1425082cc7fSAndrew Geissler   ])
1435082cc7fSAndrew Geissler   AC_SUBST([LIBXML])
1445082cc7fSAndrew Geisslerdiff --git a/libtextstyle/gnulib-local/m4/libglib.m4 b/libtextstyle/gnulib-local/m4/libglib.m4
145*b58112e5SPatrick Williamsindex dbc9eb8..136e512 100644
1465082cc7fSAndrew Geissler--- a/libtextstyle/gnulib-local/m4/libglib.m4
1475082cc7fSAndrew Geissler+++ b/libtextstyle/gnulib-local/m4/libglib.m4
1485082cc7fSAndrew Geissler@@ -6,106 +6,26 @@ dnl with or without modifications, as long as this notice is preserved.
1495082cc7fSAndrew Geissler
1505082cc7fSAndrew Geissler dnl From Bruno Haible.
1515082cc7fSAndrew Geissler
1525082cc7fSAndrew Geissler-dnl gl_LIBGLIB
1535082cc7fSAndrew Geissler-dnl   gives the user the option to decide whether to use the included or
1545082cc7fSAndrew Geissler-dnl   an external libglib.
1555082cc7fSAndrew Geissler-dnl gl_LIBGLIB(FORCE-INCLUDED)
1565082cc7fSAndrew Geissler-dnl   forces the use of the included or an external libglib.
1575082cc7fSAndrew Geissler AC_DEFUN([gl_LIBGLIB],
1585082cc7fSAndrew Geissler [
1595082cc7fSAndrew Geissler-  ifelse([$1], , [
1605082cc7fSAndrew Geissler-    AC_MSG_CHECKING([whether included glib is requested])
1615082cc7fSAndrew Geissler-    AC_ARG_WITH([included-glib],
1625082cc7fSAndrew Geissler-      [  --with-included-glib    use the glib2 included here],
1635082cc7fSAndrew Geissler-      [gl_cv_libglib_force_included=$withval],
1645082cc7fSAndrew Geissler-      [gl_cv_libglib_force_included=no])
1655082cc7fSAndrew Geissler-    AC_MSG_RESULT([$gl_cv_libglib_force_included])
1665082cc7fSAndrew Geissler-  ], [gl_cv_libglib_force_included=$1])
1675082cc7fSAndrew Geissler+  AC_REQUIRE([PKG_PROG_PKG_CONFIG])
1685082cc7fSAndrew Geissler+  AC_MSG_CHECKING([whether included glib is requested])
1695082cc7fSAndrew Geissler+  AC_ARG_WITH([included-glib],
1705082cc7fSAndrew Geissler+    [  --with-included-glib    use the glib2 included here],
1715082cc7fSAndrew Geissler+    [gl_cv_libglib_force_included=$withval],
1725082cc7fSAndrew Geissler+    [gl_cv_libglib_force_included=no])
1735082cc7fSAndrew Geissler+  AC_MSG_RESULT([$gl_cv_libglib_force_included])
1745082cc7fSAndrew Geissler
1755082cc7fSAndrew Geissler   gl_cv_libglib_use_included="$gl_cv_libglib_force_included"
1765082cc7fSAndrew Geissler   LIBGLIB=
1775082cc7fSAndrew Geissler   LTLIBGLIB=
1785082cc7fSAndrew Geissler   INCGLIB=
1795082cc7fSAndrew Geissler-  ifelse([$1], [yes], , [
1805082cc7fSAndrew Geissler-    if test "$gl_cv_libglib_use_included" != yes; then
1815082cc7fSAndrew Geissler-      dnl Figure out whether we can use a preinstalled libglib-2.0, or have to use
1825082cc7fSAndrew Geissler-      dnl the included one.
1835082cc7fSAndrew Geissler-      AC_CACHE_VAL([gl_cv_libglib], [
1845082cc7fSAndrew Geissler-        gl_cv_libglib=no
1855082cc7fSAndrew Geissler-        gl_cv_LIBGLIB=
1865082cc7fSAndrew Geissler-        gl_cv_LTLIBGLIB=
1875082cc7fSAndrew Geissler-        gl_cv_INCGLIB=
1885082cc7fSAndrew Geissler-        gl_save_LIBS="$LIBS"
1895082cc7fSAndrew Geissler-        dnl Search for libglib2 and define LIBGLIB_2_0, LTLIBGLIB_2_0 and
1905082cc7fSAndrew Geissler-        dnl INCGLIB_2_0 accordingly.
1915082cc7fSAndrew Geissler-        dnl Don't use glib-config nor pkg-config, since it doesn't work when
1925082cc7fSAndrew Geissler-        dnl cross-compiling or when the C compiler in use is different from the
1935082cc7fSAndrew Geissler-        dnl one that built the library.
1945082cc7fSAndrew Geissler-        AC_LIB_LINKFLAGS_BODY([glib-2.0])
1955082cc7fSAndrew Geissler-        LIBS="$gl_save_LIBS $LIBGLIB_2_0"
1965082cc7fSAndrew Geissler-        AC_LINK_IFELSE(
1975082cc7fSAndrew Geissler-          [AC_LANG_PROGRAM(
1985082cc7fSAndrew Geissler-             [[#include <glib.h>
1995082cc7fSAndrew Geissler-               #ifndef G_BEGIN_DECLS
2005082cc7fSAndrew Geissler-               error this glib.h includes a glibconfig.h from a glib version 1.x
2015082cc7fSAndrew Geissler-               #endif
2025082cc7fSAndrew Geissler-             ]],
2035082cc7fSAndrew Geissler-             [[g_string_new ("foo");]])],
2045082cc7fSAndrew Geissler-          [gl_cv_libglib=yes
2055082cc7fSAndrew Geissler-           gl_cv_LIBGLIB="$LIBGLIB_2_0"
2065082cc7fSAndrew Geissler-           gl_cv_LTLIBGLIB="$LTLIBGLIB_2_0"
2075082cc7fSAndrew Geissler-          ])
2085082cc7fSAndrew Geissler-        if test "$gl_cv_libglib" != yes; then
2095082cc7fSAndrew Geissler-          gl_save_CPPFLAGS="$CPPFLAGS"
2105082cc7fSAndrew Geissler-          CPPFLAGS="$CPPFLAGS $INCGLIB_2_0"
2115082cc7fSAndrew Geissler-          AC_LINK_IFELSE(
2125082cc7fSAndrew Geissler-            [AC_LANG_PROGRAM(
2135082cc7fSAndrew Geissler-               [[#include <glib.h>
2145082cc7fSAndrew Geissler-                 #ifndef G_BEGIN_DECLS
2155082cc7fSAndrew Geissler-                 error this glib.h includes a glibconfig.h from a glib version 1.x
2165082cc7fSAndrew Geissler-                 #endif
2175082cc7fSAndrew Geissler-               ]],
2185082cc7fSAndrew Geissler-               [[g_string_new ("foo");]])],
2195082cc7fSAndrew Geissler-            [gl_cv_libglib=yes
2205082cc7fSAndrew Geissler-             gl_cv_LIBGLIB="$LIBGLIB_2_0"
2215082cc7fSAndrew Geissler-             gl_cv_LTLIBGLIB="$LTLIBGLIB_2_0"
2225082cc7fSAndrew Geissler-             gl_cv_INCGLIB="$INCGLIB_2_0"
2235082cc7fSAndrew Geissler-            ])
2245082cc7fSAndrew Geissler-          if test "$gl_cv_libglib" != yes; then
2255082cc7fSAndrew Geissler-            dnl Often the include files are installed in /usr/include/glib-2.0
2265082cc7fSAndrew Geissler-            dnl and /usr/lib/glib-2.0/include.
2275082cc7fSAndrew Geissler-            if test -n "$LIBGLIB_2_0_PREFIX"; then
2285082cc7fSAndrew Geissler-              CPPFLAGS="$gl_save_CPPFLAGS -I$LIBGLIB_2_0_PREFIX/include/glib-2.0 -I$LIBGLIB_2_0_PREFIX/$acl_libdirstem/glib-2.0/include"
2295082cc7fSAndrew Geissler-              AC_LINK_IFELSE(
2305082cc7fSAndrew Geissler-                [AC_LANG_PROGRAM(
2315082cc7fSAndrew Geissler-                   [[#include <glib.h>
2325082cc7fSAndrew Geissler-                     #ifndef G_BEGIN_DECLS
2335082cc7fSAndrew Geissler-                     error this glib.h includes a glibconfig.h from a glib version 1.x
2345082cc7fSAndrew Geissler-                     #endif
2355082cc7fSAndrew Geissler-                   ]],
2365082cc7fSAndrew Geissler-                   [[g_string_new ("foo");]])],
2375082cc7fSAndrew Geissler-                [gl_cv_libglib=yes
2385082cc7fSAndrew Geissler-                 gl_cv_LIBGLIB="$LIBGLIB_2_0"
2395082cc7fSAndrew Geissler-                 gl_cv_LTLIBGLIB="$LTLIBGLIB_2_0"
2405082cc7fSAndrew Geissler-                 gl_cv_INCGLIB="-I$LIBGLIB_2_0_PREFIX/include/glib-2.0 -I$LIBGLIB_2_0_PREFIX/$acl_libdirstem/glib-2.0/include"
2415082cc7fSAndrew Geissler-                ])
2425082cc7fSAndrew Geissler-            fi
2435082cc7fSAndrew Geissler-          fi
2445082cc7fSAndrew Geissler-          CPPFLAGS="$gl_save_CPPFLAGS"
2455082cc7fSAndrew Geissler-        fi
2465082cc7fSAndrew Geissler-        LIBS="$gl_save_LIBS"
2475082cc7fSAndrew Geissler-      ])
2485082cc7fSAndrew Geissler-      AC_MSG_CHECKING([for glib])
2495082cc7fSAndrew Geissler-      AC_MSG_RESULT([$gl_cv_libglib])
2505082cc7fSAndrew Geissler-      if test $gl_cv_libglib = yes; then
2515082cc7fSAndrew Geissler-        LIBGLIB="$gl_cv_LIBGLIB"
2525082cc7fSAndrew Geissler-        LTLIBGLIB="$gl_cv_LTLIBGLIB"
2535082cc7fSAndrew Geissler-        INCGLIB="$gl_cv_INCGLIB"
2545082cc7fSAndrew Geissler-      else
2555082cc7fSAndrew Geissler-        gl_cv_libglib_use_included=yes
2565082cc7fSAndrew Geissler-      fi
2575082cc7fSAndrew Geissler-    fi
2585082cc7fSAndrew Geissler-  ])
2595082cc7fSAndrew Geissler+  if test "$gl_cv_libglib_use_included" != yes; then
2605082cc7fSAndrew Geissler+    PKG_CHECK_MODULES([GLIB], [glib-2.0])
2615082cc7fSAndrew Geissler+    LIBGLIB="$GLIB_LIBS"
2625082cc7fSAndrew Geissler+    LTLIBGLIB="$GLIB_LIBS"
2635082cc7fSAndrew Geissler+    INCGLIB="$GLIB_CFLAGS"
2645082cc7fSAndrew Geissler+  fi
2655082cc7fSAndrew Geissler   AC_SUBST([LIBGLIB])
2665082cc7fSAndrew Geissler   AC_SUBST([LTLIBGLIB])
2675082cc7fSAndrew Geissler   AC_SUBST([INCGLIB])
2685082cc7fSAndrew Geisslerdiff --git a/libtextstyle/gnulib-m4/libglib.m4 b/libtextstyle/gnulib-m4/libglib.m4
269*b58112e5SPatrick Williamsindex dbc9eb8..136e512 100644
2705082cc7fSAndrew Geissler--- a/libtextstyle/gnulib-m4/libglib.m4
2715082cc7fSAndrew Geissler+++ b/libtextstyle/gnulib-m4/libglib.m4
2725082cc7fSAndrew Geissler@@ -6,106 +6,26 @@ dnl with or without modifications, as long as this notice is preserved.
2735082cc7fSAndrew Geissler
2745082cc7fSAndrew Geissler dnl From Bruno Haible.
2755082cc7fSAndrew Geissler
2765082cc7fSAndrew Geissler-dnl gl_LIBGLIB
2775082cc7fSAndrew Geissler-dnl   gives the user the option to decide whether to use the included or
2785082cc7fSAndrew Geissler-dnl   an external libglib.
2795082cc7fSAndrew Geissler-dnl gl_LIBGLIB(FORCE-INCLUDED)
2805082cc7fSAndrew Geissler-dnl   forces the use of the included or an external libglib.
2815082cc7fSAndrew Geissler AC_DEFUN([gl_LIBGLIB],
2825082cc7fSAndrew Geissler [
2835082cc7fSAndrew Geissler-  ifelse([$1], , [
2845082cc7fSAndrew Geissler-    AC_MSG_CHECKING([whether included glib is requested])
2855082cc7fSAndrew Geissler-    AC_ARG_WITH([included-glib],
2865082cc7fSAndrew Geissler-      [  --with-included-glib    use the glib2 included here],
2875082cc7fSAndrew Geissler-      [gl_cv_libglib_force_included=$withval],
2885082cc7fSAndrew Geissler-      [gl_cv_libglib_force_included=no])
2895082cc7fSAndrew Geissler-    AC_MSG_RESULT([$gl_cv_libglib_force_included])
2905082cc7fSAndrew Geissler-  ], [gl_cv_libglib_force_included=$1])
2915082cc7fSAndrew Geissler+  AC_REQUIRE([PKG_PROG_PKG_CONFIG])
2925082cc7fSAndrew Geissler+  AC_MSG_CHECKING([whether included glib is requested])
2935082cc7fSAndrew Geissler+  AC_ARG_WITH([included-glib],
2945082cc7fSAndrew Geissler+    [  --with-included-glib    use the glib2 included here],
2955082cc7fSAndrew Geissler+    [gl_cv_libglib_force_included=$withval],
2965082cc7fSAndrew Geissler+    [gl_cv_libglib_force_included=no])
2975082cc7fSAndrew Geissler+  AC_MSG_RESULT([$gl_cv_libglib_force_included])
2985082cc7fSAndrew Geissler
2995082cc7fSAndrew Geissler   gl_cv_libglib_use_included="$gl_cv_libglib_force_included"
3005082cc7fSAndrew Geissler   LIBGLIB=
3015082cc7fSAndrew Geissler   LTLIBGLIB=
3025082cc7fSAndrew Geissler   INCGLIB=
3035082cc7fSAndrew Geissler-  ifelse([$1], [yes], , [
3045082cc7fSAndrew Geissler-    if test "$gl_cv_libglib_use_included" != yes; then
3055082cc7fSAndrew Geissler-      dnl Figure out whether we can use a preinstalled libglib-2.0, or have to use
3065082cc7fSAndrew Geissler-      dnl the included one.
3075082cc7fSAndrew Geissler-      AC_CACHE_VAL([gl_cv_libglib], [
3085082cc7fSAndrew Geissler-        gl_cv_libglib=no
3095082cc7fSAndrew Geissler-        gl_cv_LIBGLIB=
3105082cc7fSAndrew Geissler-        gl_cv_LTLIBGLIB=
3115082cc7fSAndrew Geissler-        gl_cv_INCGLIB=
3125082cc7fSAndrew Geissler-        gl_save_LIBS="$LIBS"
3135082cc7fSAndrew Geissler-        dnl Search for libglib2 and define LIBGLIB_2_0, LTLIBGLIB_2_0 and
3145082cc7fSAndrew Geissler-        dnl INCGLIB_2_0 accordingly.
3155082cc7fSAndrew Geissler-        dnl Don't use glib-config nor pkg-config, since it doesn't work when
3165082cc7fSAndrew Geissler-        dnl cross-compiling or when the C compiler in use is different from the
3175082cc7fSAndrew Geissler-        dnl one that built the library.
3185082cc7fSAndrew Geissler-        AC_LIB_LINKFLAGS_BODY([glib-2.0])
3195082cc7fSAndrew Geissler-        LIBS="$gl_save_LIBS $LIBGLIB_2_0"
3205082cc7fSAndrew Geissler-        AC_LINK_IFELSE(
3215082cc7fSAndrew Geissler-          [AC_LANG_PROGRAM(
3225082cc7fSAndrew Geissler-             [[#include <glib.h>
3235082cc7fSAndrew Geissler-               #ifndef G_BEGIN_DECLS
3245082cc7fSAndrew Geissler-               error this glib.h includes a glibconfig.h from a glib version 1.x
3255082cc7fSAndrew Geissler-               #endif
3265082cc7fSAndrew Geissler-             ]],
3275082cc7fSAndrew Geissler-             [[g_string_new ("foo");]])],
3285082cc7fSAndrew Geissler-          [gl_cv_libglib=yes
3295082cc7fSAndrew Geissler-           gl_cv_LIBGLIB="$LIBGLIB_2_0"
3305082cc7fSAndrew Geissler-           gl_cv_LTLIBGLIB="$LTLIBGLIB_2_0"
3315082cc7fSAndrew Geissler-          ])
3325082cc7fSAndrew Geissler-        if test "$gl_cv_libglib" != yes; then
3335082cc7fSAndrew Geissler-          gl_save_CPPFLAGS="$CPPFLAGS"
3345082cc7fSAndrew Geissler-          CPPFLAGS="$CPPFLAGS $INCGLIB_2_0"
3355082cc7fSAndrew Geissler-          AC_LINK_IFELSE(
3365082cc7fSAndrew Geissler-            [AC_LANG_PROGRAM(
3375082cc7fSAndrew Geissler-               [[#include <glib.h>
3385082cc7fSAndrew Geissler-                 #ifndef G_BEGIN_DECLS
3395082cc7fSAndrew Geissler-                 error this glib.h includes a glibconfig.h from a glib version 1.x
3405082cc7fSAndrew Geissler-                 #endif
3415082cc7fSAndrew Geissler-               ]],
3425082cc7fSAndrew Geissler-               [[g_string_new ("foo");]])],
3435082cc7fSAndrew Geissler-            [gl_cv_libglib=yes
3445082cc7fSAndrew Geissler-             gl_cv_LIBGLIB="$LIBGLIB_2_0"
3455082cc7fSAndrew Geissler-             gl_cv_LTLIBGLIB="$LTLIBGLIB_2_0"
3465082cc7fSAndrew Geissler-             gl_cv_INCGLIB="$INCGLIB_2_0"
3475082cc7fSAndrew Geissler-            ])
3485082cc7fSAndrew Geissler-          if test "$gl_cv_libglib" != yes; then
3495082cc7fSAndrew Geissler-            dnl Often the include files are installed in /usr/include/glib-2.0
3505082cc7fSAndrew Geissler-            dnl and /usr/lib/glib-2.0/include.
3515082cc7fSAndrew Geissler-            if test -n "$LIBGLIB_2_0_PREFIX"; then
3525082cc7fSAndrew Geissler-              CPPFLAGS="$gl_save_CPPFLAGS -I$LIBGLIB_2_0_PREFIX/include/glib-2.0 -I$LIBGLIB_2_0_PREFIX/$acl_libdirstem/glib-2.0/include"
3535082cc7fSAndrew Geissler-              AC_LINK_IFELSE(
3545082cc7fSAndrew Geissler-                [AC_LANG_PROGRAM(
3555082cc7fSAndrew Geissler-                   [[#include <glib.h>
3565082cc7fSAndrew Geissler-                     #ifndef G_BEGIN_DECLS
3575082cc7fSAndrew Geissler-                     error this glib.h includes a glibconfig.h from a glib version 1.x
3585082cc7fSAndrew Geissler-                     #endif
3595082cc7fSAndrew Geissler-                   ]],
3605082cc7fSAndrew Geissler-                   [[g_string_new ("foo");]])],
3615082cc7fSAndrew Geissler-                [gl_cv_libglib=yes
3625082cc7fSAndrew Geissler-                 gl_cv_LIBGLIB="$LIBGLIB_2_0"
3635082cc7fSAndrew Geissler-                 gl_cv_LTLIBGLIB="$LTLIBGLIB_2_0"
3645082cc7fSAndrew Geissler-                 gl_cv_INCGLIB="-I$LIBGLIB_2_0_PREFIX/include/glib-2.0 -I$LIBGLIB_2_0_PREFIX/$acl_libdirstem/glib-2.0/include"
3655082cc7fSAndrew Geissler-                ])
3665082cc7fSAndrew Geissler-            fi
3675082cc7fSAndrew Geissler-          fi
3685082cc7fSAndrew Geissler-          CPPFLAGS="$gl_save_CPPFLAGS"
3695082cc7fSAndrew Geissler-        fi
3705082cc7fSAndrew Geissler-        LIBS="$gl_save_LIBS"
3715082cc7fSAndrew Geissler-      ])
3725082cc7fSAndrew Geissler-      AC_MSG_CHECKING([for glib])
3735082cc7fSAndrew Geissler-      AC_MSG_RESULT([$gl_cv_libglib])
3745082cc7fSAndrew Geissler-      if test $gl_cv_libglib = yes; then
3755082cc7fSAndrew Geissler-        LIBGLIB="$gl_cv_LIBGLIB"
3765082cc7fSAndrew Geissler-        LTLIBGLIB="$gl_cv_LTLIBGLIB"
3775082cc7fSAndrew Geissler-        INCGLIB="$gl_cv_INCGLIB"
3785082cc7fSAndrew Geissler-      else
3795082cc7fSAndrew Geissler-        gl_cv_libglib_use_included=yes
3805082cc7fSAndrew Geissler-      fi
3815082cc7fSAndrew Geissler-    fi
3825082cc7fSAndrew Geissler-  ])
3835082cc7fSAndrew Geissler+  if test "$gl_cv_libglib_use_included" != yes; then
3845082cc7fSAndrew Geissler+    PKG_CHECK_MODULES([GLIB], [glib-2.0])
3855082cc7fSAndrew Geissler+    LIBGLIB="$GLIB_LIBS"
3865082cc7fSAndrew Geissler+    LTLIBGLIB="$GLIB_LIBS"
3875082cc7fSAndrew Geissler+    INCGLIB="$GLIB_CFLAGS"
3885082cc7fSAndrew Geissler+  fi
3895082cc7fSAndrew Geissler   AC_SUBST([LIBGLIB])
3905082cc7fSAndrew Geissler   AC_SUBST([LTLIBGLIB])
3915082cc7fSAndrew Geissler   AC_SUBST([INCGLIB])
392