[glib: 1/2] m4macros: Allow information from pkg-config to be overridden



commit 4bb16f4845ab938e10ab0d5a60ac1747ee2d2f4d
Author: Simon McVittie <smcv collabora com>
Date:   Thu Oct 4 20:13:32 2018 +0100

    m4macros: Allow information from pkg-config to be overridden
    
    By using PKG_CHECK_VAR, we declare $GLIB_COMPILE_SCHEMAS,
    $GLIB_GENMARSHAL, $GOBJECT_QUERY, $GLIB_MKENUMS and
    $GLIB_COMPILE_RESOURCES as Autoconf "precious variables" with AC_ARG_VAR,
    similar to $PKG_CONFIG and $CC, so that they can be put on a configure
    command line:
    
        ./configure GLIB_COMPILE_RESOURCES=my-glib-compile-resources
    
    If they are set to a non-empty value, PKG_CHECK_VAR will use that
    instead of auto-detecting from pkg-config, so that builders can
    override them, for example when cross-compiling.
    
    Similarly, use the standard PKG_CHECK_MODULES macro to get GLib's CFLAGS
    and LIBS.
    
    It's possible that most of the rest of each macro can also disappear,
    but for the moment I've given them the benefit of the doubt.
    
    This does result in printing "checking for GLIB" twice (once for
    PKG_CHECK_MODULES and once for GLib's custom checks), but if you're
    using Autotools, you probably don't have a strong objection to overly
    verbose output.
    
    Signed-off-by: Simon McVittie <smcv collabora com>

 m4macros/glib-2.0.m4  | 33 +++++++++++++++++----------------
 m4macros/gsettings.m4 | 14 ++++++++------
 2 files changed, 25 insertions(+), 22 deletions(-)
---
diff --git a/m4macros/glib-2.0.m4 b/m4macros/glib-2.0.m4
index 4b1901947..92dbc7d85 100644
--- a/m4macros/glib-2.0.m4
+++ b/m4macros/glib-2.0.m4
@@ -2,7 +2,7 @@
 # Owen Taylor     1997-2001
 
 # Increment this whenever this file is changed.
-#serial 1
+#serial 2
 
 dnl AM_PATH_GLIB_2_0([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, MODULES]]]])
 dnl Test for GLIB, and define GLIB_CFLAGS and GLIB_LIBS, if gmodule, gobject,
@@ -12,10 +12,16 @@ AC_DEFUN([AM_PATH_GLIB_2_0],
 [dnl 
 dnl Get the cflags and libraries from pkg-config
 dnl
+
+dnl We can't use PKG_PREREQ because that needs 0.29.
+m4_ifndef([PKG_PROG_PKG_CONFIG],
+          [pkg.m4 version 0.28 or later is required])
+
 AC_ARG_ENABLE(glibtest, [  --disable-glibtest      do not try to compile and run a test GLIB program],
                    , enable_glibtest=yes)
 
-  pkg_config_args=glib-2.0
+  min_glib_version=ifelse([$1], [], [2.0.0], [$1])
+  pkg_config_args="glib-2.0 >= $min_glib_version"
   for module in . $4
   do
       case "$module" in
@@ -46,7 +52,15 @@ AC_ARG_ENABLE(glibtest, [  --disable-glibtest      do not try to compile and run
     PKG_CONFIG=no
   fi
 
-  min_glib_version=ifelse([$1], ,2.0.0,$1)
+  dnl For GLIB_CFLAGS and GLIB_LIBS
+  PKG_CHECK_MODULES([GLIB], [$pkg_config_args >= $min_glib_version], [:], [:])
+
+  dnl For the tools
+  PKG_CHECK_VAR([GLIB_GENMARSHAL], [glib-2.0], [glib_genmarshal])
+  PKG_CHECK_VAR([GOBJECT_QUERY], [glib-2.0], [gobject_query])
+  PKG_CHECK_VAR([GLIB_MKENUMS], [glib-2.0], [glib_mkenums])
+  PKG_CHECK_VAR([GLIB_COMPILE_RESOURCES], [gio-2.0], [glib_compile_resources])
+
   AC_MSG_CHECKING(for GLIB - version >= $min_glib_version)
 
   if test x$PKG_CONFIG != xno ; then
@@ -64,13 +78,6 @@ AC_ARG_ENABLE(glibtest, [  --disable-glibtest      do not try to compile and run
   fi
 
   if test x"$no_glib" = x ; then
-    GLIB_GENMARSHAL=`$PKG_CONFIG --variable=glib_genmarshal glib-2.0`
-    GOBJECT_QUERY=`$PKG_CONFIG --variable=gobject_query glib-2.0`
-    GLIB_MKENUMS=`$PKG_CONFIG --variable=glib_mkenums glib-2.0`
-    GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable=glib_compile_resources gio-2.0`
-
-    GLIB_CFLAGS=`$PKG_CONFIG --cflags $pkg_config_args`
-    GLIB_LIBS=`$PKG_CONFIG --libs $pkg_config_args`
     glib_config_major_version=`$PKG_CONFIG --modversion glib-2.0 | \
            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
     glib_config_minor_version=`$PKG_CONFIG --modversion glib-2.0 | \
@@ -204,11 +211,5 @@ main (void)
      GLIB_COMPILE_RESOURCES=""
      ifelse([$3], , :, [$3])
   fi
-  AC_SUBST(GLIB_CFLAGS)
-  AC_SUBST(GLIB_LIBS)
-  AC_SUBST(GLIB_GENMARSHAL)
-  AC_SUBST(GOBJECT_QUERY)
-  AC_SUBST(GLIB_MKENUMS)
-  AC_SUBST(GLIB_COMPILE_RESOURCES)
   rm -f conf.glibtest
 ])
diff --git a/m4macros/gsettings.m4 b/m4macros/gsettings.m4
index 03c16fb80..882e6a83e 100644
--- a/m4macros/gsettings.m4
+++ b/m4macros/gsettings.m4
@@ -1,5 +1,5 @@
 # Increment this whenever this file is changed.
-#serial 1
+#serial 2
 
 dnl GLIB_GSETTINGS
 dnl Defines GSETTINGS_SCHEMAS_INSTALL which controls whether
@@ -8,6 +8,10 @@ dnl
 
 AC_DEFUN([GLIB_GSETTINGS],
 [
+  dnl We can't use PKG_PREREQ because that needs 0.29.
+  m4_ifndef([PKG_PROG_PKG_CONFIG],
+            [pkg.m4 version 0.28 or later is required])
+
   m4_pattern_allow([AM_V_GEN])
   AC_ARG_ENABLE(schemas-compile,
                 AS_HELP_STRING([--disable-schemas-compile],
@@ -20,11 +24,9 @@ AC_DEFUN([GLIB_GSETTINGS],
   AC_SUBST([GSETTINGS_DISABLE_SCHEMAS_COMPILE])
   PKG_PROG_PKG_CONFIG([0.16])
   AC_SUBST(gsettingsschemadir, [${datadir}/glib-2.0/schemas])
-  if test x$cross_compiling != xyes; then
-    GLIB_COMPILE_SCHEMAS=`$PKG_CONFIG --variable glib_compile_schemas gio-2.0`
-  else
-    AC_PATH_PROG(GLIB_COMPILE_SCHEMAS, glib-compile-schemas)
-  fi
+  AS_IF([test x$cross_compiling != xyes],
+        [PKG_CHECK_VAR([GLIB_COMPILE_SCHEMAS], [gio-2.0], [glib_compile_schemas])],
+        [AC_PATH_PROG([GLIB_COMPILE_SCHEMAS], [glib-compile-schemas])])
   AC_SUBST(GLIB_COMPILE_SCHEMAS)
   if test "x$GLIB_COMPILE_SCHEMAS" = "x"; then
     ifelse([$2],,[AC_MSG_ERROR([glib-compile-schemas not found.])],[$2])


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