glib-2.0.m4 8.06 KB
Newer Older
Owen Taylor's avatar
Owen Taylor committed
1
# Configure paths for GLIB
2
# Owen Taylor     1997-2001
Owen Taylor's avatar
Owen Taylor committed
3

4
dnl AM_PATH_GLIB_2_0([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, MODULES]]]])
5 6
dnl Test for GLIB, and define GLIB_CFLAGS and GLIB_LIBS, if gmodule, gobject,
dnl gthread, or gio is specified in MODULES, pass to pkg-config
Owen Taylor's avatar
Owen Taylor committed
7
dnl
8
AC_DEFUN([AM_PATH_GLIB_2_0],
Owen Taylor's avatar
Owen Taylor committed
9
[dnl 
10
dnl Get the cflags and libraries from pkg-config
Owen Taylor's avatar
Owen Taylor committed
11
dnl
12
AC_ARG_ENABLE(glibtest, [  --disable-glibtest      do not try to compile and run a test GLIB program],
Owen Taylor's avatar
Owen Taylor committed
13 14
		    , enable_glibtest=yes)

15
  pkg_config_args=glib-2.0
16 17
  for module in . $4
  do
18 19
      case "$module" in
         gmodule) 
20
             pkg_config_args="$pkg_config_args gmodule-2.0"
21
         ;;
22 23 24
         gmodule-no-export) 
             pkg_config_args="$pkg_config_args gmodule-no-export-2.0"
         ;;
Tim Janik's avatar
Tim Janik committed
25
         gobject) 
26
             pkg_config_args="$pkg_config_args gobject-2.0"
Tim Janik's avatar
Tim Janik committed
27
         ;;
28
         gthread) 
29
             pkg_config_args="$pkg_config_args gthread-2.0"
30
         ;;
31 32 33
         gio*) 
             pkg_config_args="$pkg_config_args $module-2.0"
         ;;
34 35
      esac
  done
36

37
  PKG_PROG_PKG_CONFIG([0.16])
38

Owen Taylor's avatar
Owen Taylor committed
39
  no_glib=""
40

41
  if test "x$PKG_CONFIG" = x ; then
42
    no_glib=yes
43
    PKG_CONFIG=no
44 45
  fi

46
  min_glib_version=ifelse([$1], ,2.0.0,$1)
47 48
  AC_MSG_CHECKING(for GLIB - version >= $min_glib_version)

49 50 51 52 53 54 55 56 57 58 59 60
  if test x$PKG_CONFIG != xno ; then
    ## don't try to run the test against uninstalled libtool libs
    if $PKG_CONFIG --uninstalled $pkg_config_args; then
	  echo "Will use uninstalled version of GLib found in PKG_CONFIG_PATH"
	  enable_glibtest=no
    fi

    if $PKG_CONFIG --atleast-version $min_glib_version $pkg_config_args; then
	  :
    else
	  no_glib=yes
    fi
61 62
  fi

63
  if test x"$no_glib" = x ; then
64 65 66
    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`
67
    GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable=glib_compile_resources gio-2.0`
68

69 70 71
    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 | \
Owen Taylor's avatar
Owen Taylor committed
72
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
73
    glib_config_minor_version=`$PKG_CONFIG --modversion glib-2.0 | \
Owen Taylor's avatar
Owen Taylor committed
74
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
75
    glib_config_micro_version=`$PKG_CONFIG --modversion glib-2.0 | \
Owen Taylor's avatar
Owen Taylor committed
76 77 78 79 80
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
    if test "x$enable_glibtest" = "xyes" ; then
      ac_save_CFLAGS="$CFLAGS"
      ac_save_LIBS="$LIBS"
      CFLAGS="$CFLAGS $GLIB_CFLAGS"
81
      LIBS="$GLIB_LIBS $LIBS"
Owen Taylor's avatar
Owen Taylor committed
82 83
dnl
dnl Now check if the installed GLIB is sufficiently new. (Also sanity
84
dnl checks the results of pkg-config to some extent)
Owen Taylor's avatar
Owen Taylor committed
85 86 87 88 89 90 91 92 93 94
dnl
      rm -f conf.glibtest
      AC_TRY_RUN([
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>

int 
main ()
{
95
  unsigned int major, minor, micro;
Owen Taylor's avatar
Owen Taylor committed
96

97
  fclose (fopen ("conf.glibtest", "w"));
Owen Taylor's avatar
Owen Taylor committed
98

99
  if (sscanf("$min_glib_version", "%u.%u.%u", &major, &minor, &micro) != 3) {
Owen Taylor's avatar
Owen Taylor committed
100 101 102 103 104 105 106 107
     printf("%s, bad version string\n", "$min_glib_version");
     exit(1);
   }

  if ((glib_major_version != $glib_config_major_version) ||
      (glib_minor_version != $glib_config_minor_version) ||
      (glib_micro_version != $glib_config_micro_version))
    {
108
      printf("\n*** 'pkg-config --modversion glib-2.0' returned %d.%d.%d, but GLIB (%d.%d.%d)\n", 
Owen Taylor's avatar
Owen Taylor committed
109 110
             $glib_config_major_version, $glib_config_minor_version, $glib_config_micro_version,
             glib_major_version, glib_minor_version, glib_micro_version);
111 112
      printf ("*** was found! If pkg-config was correct, then it is best\n");
      printf ("*** to remove the old version of GLib. You may also be able to fix the error\n");
Owen Taylor's avatar
Owen Taylor committed
113 114 115
      printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
      printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
      printf("*** required on your system.\n");
116 117
      printf("*** If pkg-config was wrong, set the environment variable PKG_CONFIG_PATH\n");
      printf("*** to point to the correct configuration files\n");
Owen Taylor's avatar
Owen Taylor committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
    } 
  else if ((glib_major_version != GLIB_MAJOR_VERSION) ||
	   (glib_minor_version != GLIB_MINOR_VERSION) ||
           (glib_micro_version != GLIB_MICRO_VERSION))
    {
      printf("*** GLIB header files (version %d.%d.%d) do not match\n",
	     GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
      printf("*** library (version %d.%d.%d)\n",
	     glib_major_version, glib_minor_version, glib_micro_version);
    }
  else
    {
      if ((glib_major_version > major) ||
        ((glib_major_version == major) && (glib_minor_version > minor)) ||
        ((glib_major_version == major) && (glib_minor_version == minor) && (glib_micro_version >= micro)))
      {
        return 0;
       }
     else
      {
138
        printf("\n*** An old version of GLIB (%u.%u.%u) was found.\n",
Owen Taylor's avatar
Owen Taylor committed
139
               glib_major_version, glib_minor_version, glib_micro_version);
140
        printf("*** You need a version of GLIB newer than %u.%u.%u. The latest version of\n",
Owen Taylor's avatar
Owen Taylor committed
141
	       major, minor, micro);
142
        printf("*** GLIB is always available from ftp://ftp.gtk.org.\n");
Owen Taylor's avatar
Owen Taylor committed
143 144
        printf("***\n");
        printf("*** If you have already installed a sufficiently new version, this error\n");
145
        printf("*** probably means that the wrong copy of the pkg-config shell script is\n");
Owen Taylor's avatar
Owen Taylor committed
146
        printf("*** being found. The easiest way to fix this is to remove the old version\n");
147 148
        printf("*** of GLIB, but you can also set the PKG_CONFIG environment to point to the\n");
        printf("*** correct copy of pkg-config. (In this case, you will have to\n");
Owen Taylor's avatar
Owen Taylor committed
149 150 151 152 153 154 155 156 157 158 159 160
        printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
        printf("*** so that the correct libraries are found at run-time))\n");
      }
    }
  return 1;
}
],, no_glib=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
       CFLAGS="$ac_save_CFLAGS"
       LIBS="$ac_save_LIBS"
     fi
  fi
  if test "x$no_glib" = x ; then
161
     AC_MSG_RESULT(yes (version $glib_config_major_version.$glib_config_minor_version.$glib_config_micro_version))
Owen Taylor's avatar
Owen Taylor committed
162 163 164
     ifelse([$2], , :, [$2])     
  else
     AC_MSG_RESULT(no)
165 166
     if test "$PKG_CONFIG" = "no" ; then
       echo "*** A new enough version of pkg-config was not found."
167
       echo "*** See http://www.freedesktop.org/software/pkgconfig/"
Owen Taylor's avatar
Owen Taylor committed
168 169 170 171 172
     else
       if test -f conf.glibtest ; then
        :
       else
          echo "*** Could not run GLIB test program, checking why..."
Owen Taylor's avatar
Owen Taylor committed
173 174
          ac_save_CFLAGS="$CFLAGS"
          ac_save_LIBS="$LIBS"
Owen Taylor's avatar
Owen Taylor committed
175 176 177
          CFLAGS="$CFLAGS $GLIB_CFLAGS"
          LIBS="$LIBS $GLIB_LIBS"
          AC_TRY_LINK([
178
#include <glib.h>
Owen Taylor's avatar
Owen Taylor committed
179 180 181 182 183 184 185 186 187 188
#include <stdio.h>
],      [ return ((glib_major_version) || (glib_minor_version) || (glib_micro_version)); ],
        [ echo "*** The test program compiled, but did not run. This usually means"
          echo "*** that the run-time linker is not finding GLIB or finding the wrong"
          echo "*** version of GLIB. If it is not finding GLIB, you'll need to set your"
          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
          echo "*** is required on your system"
	  echo "***"
          echo "*** If you have an old version installed, it is best to remove it, although"
189
          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" ],
Owen Taylor's avatar
Owen Taylor committed
190
        [ echo "*** The test program failed to compile or link. See the file config.log for the"
Owen Taylor's avatar
Owen Taylor committed
191
          echo "*** exact error that occured. This usually means GLIB is incorrectly installed."])
Owen Taylor's avatar
Owen Taylor committed
192 193 194 195 196 197
          CFLAGS="$ac_save_CFLAGS"
          LIBS="$ac_save_LIBS"
       fi
     fi
     GLIB_CFLAGS=""
     GLIB_LIBS=""
198 199 200
     GLIB_GENMARSHAL=""
     GOBJECT_QUERY=""
     GLIB_MKENUMS=""
201
     GLIB_COMPILE_RESOURCES=""
Owen Taylor's avatar
Owen Taylor committed
202 203 204 205
     ifelse([$3], , :, [$3])
  fi
  AC_SUBST(GLIB_CFLAGS)
  AC_SUBST(GLIB_LIBS)
206 207 208
  AC_SUBST(GLIB_GENMARSHAL)
  AC_SUBST(GOBJECT_QUERY)
  AC_SUBST(GLIB_MKENUMS)
209
  AC_SUBST(GLIB_COMPILE_RESOURCES)
Owen Taylor's avatar
Owen Taylor committed
210 211
  rm -f conf.glibtest
])