1# libglib.m4 serial 5 2dnl Copyright (C) 2006-2007, 2019 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7dnl From Bruno Haible. 8 9dnl gl_LIBGLIB 10dnl gives the user the option to decide whether to use the included or 11dnl an external libglib. 12dnl gl_LIBGLIB(FORCE-INCLUDED) 13dnl forces the use of the included or an external libglib. 14AC_DEFUN([gl_LIBGLIB], 15[ 16 ifelse([$1], , [ 17 AC_MSG_CHECKING([whether included glib is requested]) 18 AC_ARG_WITH([included-glib], 19 [ --with-included-glib use the glib2 included here], 20 [gl_cv_libglib_force_included=$withval], 21 [gl_cv_libglib_force_included=no]) 22 AC_MSG_RESULT([$gl_cv_libglib_force_included]) 23 ], [gl_cv_libglib_force_included=$1]) 24 25 gl_cv_libglib_use_included="$gl_cv_libglib_force_included" 26 LIBGLIB= 27 LTLIBGLIB= 28 INCGLIB= 29 ifelse([$1], [yes], , [ 30 if test "$gl_cv_libglib_use_included" != yes; then 31 dnl Figure out whether we can use a preinstalled libglib-2.0, or have to use 32 dnl the included one. 33 AC_CACHE_VAL([gl_cv_libglib], [ 34 gl_cv_libglib=no 35 gl_cv_LIBGLIB= 36 gl_cv_LTLIBGLIB= 37 gl_cv_INCGLIB= 38 gl_save_LIBS="$LIBS" 39 dnl Search for libglib2 and define LIBGLIB_2_0, LTLIBGLIB_2_0 and 40 dnl INCGLIB_2_0 accordingly. 41 dnl Don't use glib-config nor pkg-config, since it doesn't work when 42 dnl cross-compiling or when the C compiler in use is different from the 43 dnl one that built the library. 44 AC_LIB_LINKFLAGS_BODY([glib-2.0]) 45 LIBS="$gl_save_LIBS $LIBGLIB_2_0" 46 AC_TRY_LINK([#include <glib.h> 47#ifndef G_BEGIN_DECLS 48error this glib.h includes a glibconfig.h from a glib version 1.x 49#endif 50], 51 [g_string_new ("foo");], 52 [gl_cv_libglib=yes 53 gl_cv_LIBGLIB="$LIBGLIB_2_0" 54 gl_cv_LTLIBGLIB="$LTLIBGLIB_2_0" 55 ]) 56 if test "$gl_cv_libglib" != yes; then 57 gl_save_CPPFLAGS="$CPPFLAGS" 58 CPPFLAGS="$CPPFLAGS $INCGLIB_2_0" 59 AC_TRY_LINK([#include <glib.h> 60#ifndef G_BEGIN_DECLS 61error this glib.h includes a glibconfig.h from a glib version 1.x 62#endif 63], 64 [g_string_new ("foo");], 65 [gl_cv_libglib=yes 66 gl_cv_LIBGLIB="$LIBGLIB_2_0" 67 gl_cv_LTLIBGLIB="$LTLIBGLIB_2_0" 68 gl_cv_INCGLIB="$INCGLIB_2_0" 69 ]) 70 if test "$gl_cv_libglib" != yes; then 71 dnl Often the include files are installed in /usr/include/glib-2.0 72 dnl and /usr/lib/glib-2.0/include. 73 if test -n "$LIBGLIB_2_0_PREFIX"; then 74 CPPFLAGS="$gl_save_CPPFLAGS -I$LIBGLIB_2_0_PREFIX/include/glib-2.0 -I$LIBGLIB_2_0_PREFIX/$acl_libdirstem/glib-2.0/include" 75 AC_TRY_LINK([#include <glib.h> 76#ifndef G_BEGIN_DECLS 77error this glib.h includes a glibconfig.h from a glib version 1.x 78#endif 79], 80 [g_string_new ("foo");], 81 [gl_cv_libglib=yes 82 gl_cv_LIBGLIB="$LIBGLIB_2_0" 83 gl_cv_LTLIBGLIB="$LTLIBGLIB_2_0" 84 gl_cv_INCGLIB="-I$LIBGLIB_2_0_PREFIX/include/glib-2.0 -I$LIBGLIB_2_0_PREFIX/$acl_libdirstem/glib-2.0/include" 85 ]) 86 fi 87 fi 88 CPPFLAGS="$gl_save_CPPFLAGS" 89 fi 90 LIBS="$gl_save_LIBS" 91 ]) 92 AC_MSG_CHECKING([for glib]) 93 AC_MSG_RESULT([$gl_cv_libglib]) 94 if test $gl_cv_libglib = yes; then 95 LIBGLIB="$gl_cv_LIBGLIB" 96 LTLIBGLIB="$gl_cv_LTLIBGLIB" 97 INCGLIB="$gl_cv_INCGLIB" 98 else 99 gl_cv_libglib_use_included=yes 100 fi 101 fi 102 ]) 103 AC_SUBST([LIBGLIB]) 104 AC_SUBST([LTLIBGLIB]) 105 AC_SUBST([INCGLIB]) 106 AC_MSG_CHECKING([whether to use the included glib]) 107 AC_MSG_RESULT([$gl_cv_libglib_use_included]) 108 109 if test "$gl_cv_libglib_use_included" = yes; then 110 LIBGLIB_H= 111 LIBGLIB_H="$LIBGLIB_H glib.h" 112 LIBGLIB_H="$LIBGLIB_H glibconfig.h" 113 LIBGLIB_H="$LIBGLIB_H glib/ghash.h" 114 LIBGLIB_H="$LIBGLIB_H glib/glist.h" 115 LIBGLIB_H="$LIBGLIB_H glib/gmacros.h" 116 LIBGLIB_H="$LIBGLIB_H glib/gprimes.h" 117 LIBGLIB_H="$LIBGLIB_H glib/gprintfint.h" 118 LIBGLIB_H="$LIBGLIB_H glib/gstrfuncs.h" 119 LIBGLIB_H="$LIBGLIB_H glib/gstring.h" 120 LIBGLIB_H="$LIBGLIB_H glib/gtypes.h" 121 AC_REQUIRE([AC_GNU_SOURCE]) 122 AC_CHECK_HEADERS([unistd.h]) 123 dnl Don't bother checking for pthread.h and other multithread facilities. 124 else 125 LIBGLIB_H= 126 fi 127 AC_SUBST([LIBGLIB_H]) 128 129 AM_CONDITIONAL([INCLUDED_LIBGLIB], 130 [test "$gl_cv_libglib_use_included" = yes]) 131]) 132